I will re-write my sketch. But also, with QOS in MQTT broker of "0" you can ensure that the information is received, isn't it ? Or am I wrong again ?
Another thing will be MQTT with QOS of 1 or 2.
What do you think ?
Regards
NOTE: Thanks a lot for WIFI.begin's stuff. In this sketch it is not necessary as I only want to check the difference between two protocols.
torntrousers wrote:A couple of comments on that sketch -
On the HTTP side it doesn't wait to receive the http response, it does the "client.print(String("GET ")..." and then client.stop(). I'm a bit surprised thats even working and the sent data is actually getting stored in ThingSpeak. If the connection is closed before ThingSpeak gets to sending the HTTP 200 OK response then the ThingSpeak sever may well just discard the request if it hasn't processed it yet.
Another thing, not related to this HTTP/MQTT comparison, its always doing WiFi.begin(ssid, password), I've heard (though not tested) that that is slower than just letting the ESP auto connect to the previously used SSID, which is why you often see code doing:
if (strcmp (WiFi.SSID().c_str(), ssid) != 0) {
WiFi.begin(ssid, password);
}
HTH.
EDIT: Hope thats not sounding negative, I think its interesting what you're doing, just pointing out its not timing the complete http request-response.