Chat freely about anything...

User avatar
By Barnabybear
#27535
martinayotte wrote:In your URL request, we see "Host: 192.168.0.230\n\r\n\r\n\r", it should be "Host: 192.168.0.230\r\n\r\n"
Also, about length, "\r\n" is count as 2 characters, and it can't be transmitted as is thru a serial monitor such putty, except if transmitted as Ctrl-M/Ctrl-J, otherwise it need to be sent from the arduino sketches, of python scripts.


Thanks Martin, that clears up the mystery & explains why when I check the length of a string I get an unexpected length & why it is has allways been an even number less.

Length check code:
Code: Select all// checks the length of a string (Arduino IDE 1.6.5)
void setup() {
  Serial.begin(115200);  // starts serial monitor
  delay(10); 
    String postStr = ("GET /datasources/20/addvalue?value=1 HTTP/1.0\r\nHost: 192.168.0.230\r\n\r\n"); //<-string to check length of
    Serial.println();
    Serial.print(postStr);
    Serial.print("String length = ");
    Serial.print(postStr.length());
}

void loop() {
  // No loop needed.


Serial responce to the above:
Code: Select allGET /datasources/20/addvalue?value=1 HTTP/1.0
Host: 192.168.0.230

String length = 70
User avatar
By kenn
#27559 Various and sundry thoughts:

- I found I had to add 2 to the length of the request string in the "AT+CIPSEND..." command

- I know nothing about "SwitchKing REST server". Have you tried hitting other servers - a local Apache or IIS, or hitting a public website?

- On Windows, I've found the Termite terminal program better than PuTTY for manually running AT commands because you can configure the terminator to be \r\n. I've also found it useful to write Python scripts to set up AT sessions on the ESP8266, or to run as a http client.

- some sites and servers reject requests from 'strange' clients with incomplete or unrecognized request headers. As above, a Python script can take care of creating and transmitting a benign header with the request (eg faking a Firefox header).
User avatar
By Ranemyr
#28497
martinayotte wrote:In your URL request, we see "Host: 192.168.0.230\n\r\n\r\n\r", it should be "Host: 192.168.0.230\r\n\r\n"
Also, about length, "\r\n" is count as 2 characters, and it can't be transmitted as is thru a serial monitor such putty, except if transmitted as Ctrl-M/Ctrl-J, otherwise it need to be sent from the arduino sketches, of python scripts.


Thanks martinayotte
The devils hides in the details :-)
Your tips guided me to a solution and now i can get my GET command to make wounders
I tried to send my GET string with

This didn't work
cmd = "My Get string with ending \r\n\r\n"
Serial.print(cmd);

But when i changed to
cmd = "My Get string with ending \r\n\r\n"
Serial.println(cmd);
This works like a charm :-)

And i am a happy man again

/Peter