-->
Page 1 of 1

HTTP Response with AT commands?

PostPosted: Tue Jan 26, 2016 3:15 am
by BlitzSSS
EDIT: solved my own issue, see my first reply.

Hi All

I've been using an ESP with an Arduino to post data to emoncms using the AT command set - (mostly) all good.

What I'm trying to achieve now is reading data back from emoncms. I can achieve this when directly programming the ESP with the Arduino ISP but can't figure out how (or if it's possible) to do this using the AT command set.

When programming with the Arduino IDE I basically need to post this to emoncms after establishing a TCP connection:

GET /feed/value.json?apikey=XXXXXXXXX&id=100486 HTTP/1.1
and on a new line:
Host:emoncms.org

and in the http response is the data I'm after i.e "3715113" (filtering the HTTP header was the next challenge).

I'm doing the following using the AT command set but only get a timeout from emoncms:

Code: Select allcmd3 = "GET /feed/value.json?apikey=";
  cmd3 += API_KEY;
  cmd3 += "&id=100486";
  cmd3 += " HTTP/1.1\r\n";

  //get string length
  Serial1.print(F("AT+CIPSEND="));
  Serial1.println(cmd3.length());

  delay(1000);

  if (Serial1.find(">")) {
    Serial1.println(cmd3);
  }


admittedly I'm not sending the "Host:emoncms.org" on a new line (which the site seems to need) mainly because I don't know how to construct it.

can anyone help me out? What's the best way to read the HTTP response and then filter out the header and assign the data I'm after to a variable using the AT command set?

Reading serial responses seems to be a challenge, wish there was better firmware out there for interfacing with an Arduino.

Thanks

Re: HTTP Response with AT commands?

PostPosted: Tue Jan 26, 2016 4:59 am
by BlitzSSS
OK figured it out, this is the code I'm using.

Code: Select all cmd3 = "GET /feed/value.json?apikey=";
  cmd3 += API_KEY;
  cmd3 += "&id=100486";
  cmd3 += " HTTP/1.1\n";
  cmd3 += "Host: emoncms.org\n\n";
 
  //get strings length
  Serial1.print(F("AT+CIPSEND="));
  Serial1.println(cmd3.length());

  delay(1000);

  if (Serial1.find(">")) {
    Serial1.println(cmd3);
  }

 long int time = millis();
  while ((time + 10000) > millis())
  {
    while (Serial1.available())
    {
      char c = Serial1.read();
      Serial.print(c);
    }
  }


now to figure out how-to filter the HTTP response:

+IPD,205:HTTP/1.1 200 OK
Date: Tue, 26 Jan 2016 09:57:45 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.3.10-1ubuntu3.16
Content-Length: 9
Connection: close
Content-Type: application/json

"3715251"CLOSED

all I want is the 3715251 bit and assign this to a variable. anyone able to help ?