The use of the ESP8266 in the world of IoT

User avatar
By Dan Kiefer
#74708 I did some further research. Here my are my findings:

I finally was able to send data through the wifi network at my work, using my private tablet (Android). It works, when opening the Chrome browser (does not work with the standard internet browser though) and entering the path (storage/emulated/0/Documents/post.html) to my post.html file, which contains the following code:

Code: Select all<form action="https://api.thingspeak.com/update.json" method="post">
<p>
<label for="set temp">Desired Temperature: </label>
<input type="hidden" id="api_key" name="api_key" value="myAPIkey">
<input type="text" id="field1" name="field1"> <br>
<input type="submit" value="Send">
</p>
</form>


This opens a page that allows me to send data to my Thingspeak channel through the WLAN from my work place. It works fine.

However, the following code in the ESP8266, which works perfectly at home, doesn't work at my work place:

Code: Select allif (myClient.connect(server,80)){
    String postStr = apiKey;
    postStr += "&field1=";
    postStr += String(temperature);
    lastSentTemperature = temperature;
    postStr += "&field2=";
    postStr += String(humidity); 

    postStr += "\r\n\r\n";
    myClient.print("POST /update HTTP/1.1\n");
    myClient.print("Host: api.thingspeak.com\n");
    myClient.print("Connection: close\n");
    myClient.print("X-THINGSPEAKAPIKEY:" + apiKey +"\n");
    myClient.print("Content-Type: application/x-www-form-urlencoded\n");
    myClient.print("Content-Length: ");
    myClient.print(postStr.length());
    myClient.print("\n\n");
    myClient.print(postStr);
}


Any idea what could be wrong?

Thanks, Dan

@schufti: With that information, do you think that may still be a proxy problem? You may have pointed my into the right direction. I just don't know what to do with that proxy thing, and how to solve it.
User avatar
By torntrousers
#74710
Dan Kiefer wrote:...
However, the following code in the ESP8266, which works perfectly at home, doesn't work at my work place:

Code: Select allif (myClient.connect(server,80)){
    String postStr = apiKey;
    postStr += "&field1=";
    postStr += String(temperature);
    lastSentTemperature = temperature;
    postStr += "&field2=";
    postStr += String(humidity); 

    postStr += "\r\n\r\n";
    myClient.print("POST /update HTTP/1.1\n");
    myClient.print("Host: api.thingspeak.com\n");
    myClient.print("Connection: close\n");
    myClient.print("X-THINGSPEAKAPIKEY:" + apiKey +"\n");
    myClient.print("Content-Type: application/x-www-form-urlencoded\n");
    myClient.print("Content-Length: ");
    myClient.print(postStr.length());
    myClient.print("\n\n");
    myClient.print(postStr);
}


Any idea what could be wrong?


You don't show all the code - what happens next? Is something reading the response and what does it get?

...ant
User avatar
By Dan Kiefer
#74711 Well it's just that code that is done in a loop, every 60 seconds. So far there is no read of a response. I was not even aware that there was one... I will try to do that and post it here.

Thanks, Dan
User avatar
By torntrousers
#74712 If your esp client closes the connection before ThingSpeak has handled the request then the request can get canceled and the data lost, you need to wait till you get a response to make sure. It could be the difference in speed between your work and home networks causing the difference.

Its easier to use the ESP HTTPClient code, an example is here: https://github.com/HarringayMakerSpace/ ... #L103-L114