Reputation: 84
I'm trying to use an ESP8266 and Arduino Uno to connect to wunderground and get the JSON file to get the current weather. With my code I am connecting to the server fine. What seems to be the issue is that it's not giving me the whole return file.
#include <SoftwareSerial.h>
#include <ArduinoJson.h>
SoftwareSerial esp8266(8, 9);
bool flag = true;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
esp8266.begin(9600);
}
void loop() {
if (flag) {
String cmd;
int length;
cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += "api.wunderground.com";
cmd += "\",80";
esp8266.println(cmd);
Serial.println(cmd);
delay(2000);
Serial.write(esp8266.read());
if (esp8266.find("CONNECT")) {
Serial.println("CONNECT found so your connected");
}
String action;
action = "GET http://api.wunderground.com/api/APIKEY/conditions/q/Canada/Regina.json HTTP/1.0\r\n\r\n";
length = action.length();
cmd = "AT+CIPSEND=";
cmd += length;
esp8266.println(cmd);
Serial.println(cmd);
delay(5000);
if (esp8266.find(">")) {
Serial.print(">");
} else {
esp8266.println("AT+CIPCLOSE");
Serial.println(F("connect timeout"));
}
esp8266.println(action);
Serial.println(action);
delay(700);
String test = "";
while (esp8266.available()) {
char c = esp8266.read();
test += c;
}
Serial.println(test);
flag = false;
Serial.println("Flag is false");
}
}
Running this code give me the following result:
AT+CIPSTART="TCP","api.wunderground.com",80 ACONNECT found so your connected AT+CIPSEND=97 GET http://api.wunderground.com/api/7287eb3ace065563/conditions/q/Canada/Regina.json HTTP/1.0
busy s...
Recv 97 bytes
SEND OK
+IPD,1460:HTTP/1.0:"0.1", "termsofService":"http://www.wunderground.com/weather/api/d/terms.html", " Flag is false
As you can see I only get a snippet of the JSON file. I'm not sure what the problem is.
Upvotes: 1
Views: 1449
Reputation: 6213
It's not sending JSON at all. It detected that your Arduino/ESP combo was not a human, and is scolding you, letting you know that you are in breach of the Terms of Service, as described in http://www.wunderground.com/weather/api/d/terms.html. You need to set some headers, to masquerade as a browser and thus pass as a human user.
Upvotes: 1