Post topics, source code that relate to the Arduino Platform

User avatar
By pete_l
#12321 The "bad request" reply is coming from the ThingSpeak web server, not from the ESP8266.
Here is a sample of what I send to ThingSpeak:

Code: Select all  cmd = F("GET /update?key=----------------");
  cmd += F("&field1=");  cmd += temp;
  cmd += F("&field2=");  cmd += light;
  cmd += F("&field3=");  cmd += humid;
  cmd += F("&field4=");  cmd += sample_count++;
  cmd += F("&field5=");  cmd += resets;
  cmd += F("\r\n");
  Serial.print( "AT+CIPSEND=" );
  Serial.println( cmd.length() );
 
  if(read_serial_line(rep) > 0) {  // get response to CIPSEND=x
    if(str_contains(rep, ">")) {
      Serial.print(cmd);


and I am sending 88 character lines TERMINATED with \r\n
User avatar
By pete_l
#13024 If it's any consolation I was getting similar issues. I am sending 100+ characters to the server.

I have an example that is close to yours. I am sending 8 fields, one of which is a sequence number that increments with each GET string sent. I noticed that with ThingSpeak I was losing a significant number of entries - there were large gaps in the sequences.
I modified the arduino code to send the string to a local server and a PHP page that grabbed the data and wrote it to a log file. It still loses entries: somewhere between 10%-20% don't make it through.

I also have a scheme on my Arduino that writes replies from the 8266 to a memory buffer. I have connected the CH_PD pin so that when the 8266 is off the serial lines (i.e CH_PD is logic 0 - DON'T do this if you have tied CH_PD directly to +ve, which is bad practice anyway, it should go to a 10k pullup resistor) I can write out the contents of the memory buffer.
What I see is stuff like this going from the Arduino to the 8266:
AT+CIPSEND=112
GET 8266.php?key=from_8266&field1=24.1&field2=655&field3=34.0&field4=91&field5=0&field6=8&field7=33 HTTP/1.0


and this is what comes back from the 8266:
GET 8266.php?key=from_8266&field1=24.1&field2=655&field3=34.0&field4=91&fi&83
SE HX5pti3T3F<

OK
Unlink

Note: the HTTP/1.0\r\n is needed to talk to ordinary webservers - without this your PHP might not get the data passed to it.
User avatar
By swilson
#13275 Pete, very interesting. So what you are saying is even requests to your local php server is failing sometimes. That would mean possibly loss of data between the arduino and the esp. I have no clue. I ended up doing it a different way. I am just using a esp-12 by itself with nodemcu code. I setup a local email server (non-ssl) that allows only my the ip range of the esp to relay mail. It connects to the local mail server and sends the email to me. I was just trying to use thingspeak to keep track but that is not really needed. I am sure I will have to look into a setup like this in the future though.

Wonder if the Arduino IDE for the esp will behave differently? Might have to give that a shot just to see.
User avatar
By pete_l
#13393 Yes, it's even losing requests sent to a server on the same subnet.
One area I was looking into was the arduino code I was using to read replies back from the 8266. Briefly, I suspected that the code wasn't too great as it checked for a set of up to 4 replies after each character that the 8266 sent back. It's possible (likely, even?) that this string scanning was taking so long that characters were being dropped and I was not getting the correct handshaking before sending my web data.

However, I altered my code to work with char * arrays instead of String classes (less bloat) and to use the Arduino Serial.readBytes() routine straight into a buffer, with a 20mSec timeout - then just scan the returned string after each timeout (it turns out that 20mS is long enough to read all the 8266 responses, including a 300 byte reply from the webserver). I still lose a lot of packets. Since TCP is supposed to be a reliable protocol that handles handshaking and retransmits this is clearly far below what I expected to happen.