Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

HTTP vs MQTT

Status
Not open for further replies.

Mosaic

Well-Known Member
Hi All :
I did an app and prototype based on the ESP12E IoT chips.
I am getting irregular comm issues....sometimes it's 100% sometimes down to 50%. No WiFi competition the router signal is 5 ' away.
The app was done in HTTP/TCP via the arduino IDE. I see that MQTT may be the better approach.
Can anyone advise?

EDIT: I also discovered the ESP8266 I2C protocol init string is flawed in the arduino IDE. I am forced to read the first I2C byte twice and discard the 1st read as it returns a NAK instead of an ACK when the logic analyzer looks at it.
 
I'm currently playing with ESP's writing to a MYSQL server on one of my websites, the ESP's wake up every ten minutes or so, read the temperature, humidity, and battery voltage, and upload it to a remote server via a PHP script - it also uploads the WiFi network it's connected to, and the signal strength.

So far they seem to be working flawlessly, here's a link to the graphs of the two currently running:



The top graph is an ESP01, actually connected to USB on the PC I'm using at the moment - and as it's an ESP01 the battery voltage is actually the internal supply in the chip. The lower graph, which I built today is a Wemos Mini, running off a Lithium AA cell, connected via a USB charger/protection board (and monitors the actual battery voltage) - the unit is currently sat under the eves of my house - the initial high temperature and low humidity was when it was at in the sun through my attic window. I haven't actually measured the current consumption, I'm just waiting to see how long the battery lasts.

My main problem at the moment is the graphing, I wish to have the X axis labelled in date and time, but I'm struggling getting PHPGRAPHLIB to do it - altering the x-axis interval removes the labels entirely.

I've also got a third ESP running, another Wemos Mini, with a battery charger shield fitted, and that's running from an 18650 battery - as the shield up-converts the battery to 5V, it's presumably taking more current than the bare Wemos version?. This one simply uploads to a CSV text file via PHP on the same server - it's been running since 23rd April, and the battery reading is currently 3.98V. The CSV files is now over 90Kb.
 
I've done quite a bit with the ESP's and MQTT. For the cost, and the level of community uptake and support for them, they're great.

I never use them with standard AT cmd firmware though.

MQTT is meant for distributed, low bandwidth, and potentially low reliability networks. Like a distributed network of sensor nodes located around the world, all connected to the internet. If you're simply talking over a local router, then there should be nothing wrong with raw TCP/UDP or even HTTP, they're solid. You can use MQTT for local use not utilising the internet, you just will need a local broker, but that's easily done with a RasberryPi or similar.
 
When u say a local broker....this is not a router?
No, but you can think of it like a router if you like, but specifically for MQTT messages.

Its a different piece of equipment/program connected to the network via the router, but specifically running as an MQTT broker. It will ferry (broker) all subscribe/publish messages to the relevant devices.
 
Last edited:
absolutely need a broker
What I did before; each node had its own web page, or each node used a network serial port, or could email out, or ....
So I was planning on using a Pi-0 on each node. But the MQTT looks tempting. I do have a Pi-3 in the middle of all this.

I am a hardware person and having complexity problems. lol Gave up on getting the Pi-3 to be a server. Decided to update and bricked the Pi last night. Had to start over from zero. Back up and running.

I am trying to replace my 25 year old home control computer but can't get a Pi server running and my python-ability is very low. And my head is slower than 25 years ago.
 
I'm currently playing with ESP's writing to a MYSQL server on one of my websites, the ESP's wake up every ten minutes or so, read the temperature, humidity, and battery voltage, and upload it to a remote server via a PHP script - it also uploads the WiFi network it's connected to, and the signal strength.

So far they seem to be working flawlessly, here's a link to the graphs of the two currently running:



The top graph is an ESP01, actually connected to USB on the PC I'm using at the moment - and as it's an ESP01 the battery voltage is actually the internal supply in the chip. The lower graph, which I built today is a Wemos Mini, running off a Lithium AA cell, connected via a USB charger/protection board (and monitors the actual battery voltage) - the unit is currently sat under the eves of my house - the initial high temperature and low humidity was when it was at in the sun through my attic window. I haven't actually measured the current consumption, I'm just waiting to see how long the battery lasts.

My main problem at the moment is the graphing, I wish to have the X axis labelled in date and time, but I'm struggling getting PHPGRAPHLIB to do it - altering the x-axis interval removes the labels entirely.

I've also got a third ESP running, another Wemos Mini, with a battery charger shield fitted, and that's running from an 18650 battery - as the shield up-converts the battery to 5V, it's presumably taking more current than the bare Wemos version?. This one simply uploads to a CSV text file via PHP on the same server - it's been running since 23rd April, and the battery reading is currently 3.98V. The CSV files is now over 90Kb.

Hi Nigel,

I'm using same solution like you. But I'm not sure it's safe or not.
Have you ever had any problem because of this script?


Code:
    $usid  = $_GET['id'];        $id   = strip_tags(addslashes($usid));
    $ustmp = $_GET['tmp'];        $tmp = strip_tags(addslashes($ustmp));
    $ushmi = $_GET['hmi'];        $hmi  = strip_tags(addslashes($ushmi));


    $usprs = $_GET['prs'];        $prs = strip_tags(addslashes($usprs));
    $usatt = $_GET['att'];        $att  = strip_tags(addslashes($usatt));
    $usslp = $_GET['slp'];        $slp = strip_tags(addslashes($usslp));
    $usrat = $_GET['rat'];        $rat  = strip_tags(addslashes($usrat));

   
   
    $refid = '7e7845cba796e256d61b2ef43f834e17';  // like password for filtering bot actions
   
    $date = date('Y-m-d');

    $clck = date('H:i:s');
   
   
   
    if($id==$refid) { //add database }
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top