esp-12 and current weather @ openweathermap.org
Posted: Wed Jul 15, 2015 6:23 am
Hello everyone,
I'm working on a code to connect to the openweathermap.org api and display the weather information on a LCD via another arduino board (I wasn't able to make the I2C Bus work for the esp8266).
The code is kinda dirty right now and has a few old things in it, which should not be troubling though. So far it's kind of working. I can connect to the api and collect my data. Then I send it to the Arduino mega and it displays the data/numbers on my lcd. For some reason this is only working for the forecast. I can not make it work for the current weather information.
I hope someone can help me out here, cause I'm running out of ideas.
Working Code so far:
When connecting to http://api.openweathermap.org/data/2.5/ ... id=2947416 it tells me, that it connected but for some reason the whole respond is empty, like there is nothing to be read.
I'm working on a code to connect to the openweathermap.org api and display the weather information on a LCD via another arduino board (I wasn't able to make the I2C Bus work for the esp8266).
The code is kinda dirty right now and has a few old things in it, which should not be troubling though. So far it's kind of working. I can connect to the api and collect my data. Then I send it to the Arduino mega and it displays the data/numbers on my lcd. For some reason this is only working for the forecast. I can not make it work for the current weather information.
I hope someone can help me out here, cause I'm running out of ideas.
Working Code so far:
Code: Select all
//#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
//#define LOCATIONID "<LOCATION>" // location id
//#define API "http://api.openweathermap.org/data/2.5/forecast/city?id=2947416&APPID=..." //http://api.openweathermap.org/
const char* ssid = "SSIDNAME";//"mytest";
const char* password = "SSIDPASSWORD"; //"123456789";
int ledPin = 13; // GPIO13
//WiFiServer server(80);
WiFiClient client;
int wetter = 0;
float temp = 0.0;
float wind = 0.0;
//StaticJsonBuffer<200> jsonBuffer;
//JsonParser<32> parser;
char server[] = "openweathermap.org";
//char weather[544];
void setup() {
Serial.begin(9600);
delay(10);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
//server.begin();
//Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
/*WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
*/
/*WiFi.mode(WIFI_STA);
WiFi.softAP(ssid, password);
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.softAPIP());
Serial.println("/");*/
void loop() {
bool onlygiveone = false;
if (client.connect(server, 80))
{
//Serial.println("connected to server");
// Make a HTTP request:
client.println(F("GET /data/2.5/forecast?id=2947416 HTTP/1.1")); // <- works. http://api.openweathermap.org/data/2.5/weather?id=2947416 <- does not work.
client.println("Host: api.openweathermap.org");
//client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
}
onlygiveone = false;
while (client.available()) {
//char c = client.read();
if (onlygiveone == false)
{
client.find("temp");
temp = client.parseFloat() - 273.15;
client.find("weather");
wetter = client.parseInt();
client.find("speed");
wind = client.parseFloat();
client.stop();
onlygiveone=true;
}
}
Serial.println(String(temp));
Serial.println(String(wetter));
Serial.println(String(wind));
delay(60000);
/*// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();
// do nothing forevermore:
while(true)
{};
}*/
}
When connecting to http://api.openweathermap.org/data/2.5/ ... id=2947416 it tells me, that it connected but for some reason the whole respond is empty, like there is nothing to be read.