#include #include //____________ //int rgb[3] = {255,255,255}; // RELLENAR COLOR FRIO //____ #define SSID "hangar_polivalent" // insert your SSID #define PASS "p0l1v4l3nc14s" // insert your password #define WeatherWS_IP "188.226.224.148" //api.openweathermap.org #define TimeWS_IP "208.113.226.171" //earthtools.org #define LOCATION_NAME "Barcelona,es" // location #define LOCATION_LL "41.3871/2.1685" // location latitude/longitude/ StaticJsonBuffer<200> jsonBuffer; void setup() { Serial1.begin(9600); Serial1.setTimeout(5000); Serial.begin(9600); // for debuging while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.println("Init"); do{ Serial1.println("AT+RST"); Serial.println("WiFi - Module is missing"); delay(100); } while(!Serial1.find("ready")); Serial.println("WiFi - Module is ready"); delay(1000); // try to connect to wifi boolean connected = false; for (int i = 0; i < 5; i++) { if (connectWiFi()) { connected = true; break; } } if (!connected) { while (1); } delay(5000); Serial1.println("AT+CIPMUX=0"); // set to single connection mode } void loop() { int h = getTime(); Serial.print("time = "); Serial.println(h); //for(int i=0;i<20;i++){Serial.print(i);delay(1000);} int t = getTemp(); Serial.print("temp = "); Serial.println(t); for(int i=0;i<20;i++){Serial.print(i);delay(1000);} } int getTime(){ String cmd = "AT+CIPSTART=\"TCP\",\""; cmd += TimeWS_IP; cmd += "\",80"; Serial1.println(cmd); Serial.println(cmd); if (Serial1.find("Error")) return -1; cmd = "GET /timezone/"; cmd += LOCATION_LL; cmd += " HTTP/1.0\r\nHost: www.earthtools.org\r\n\r\n"; Serial1.print("AT+CIPSEND="); Serial1.println(cmd.length()); if (Serial1.find(">")) { Serial.println(">"); } else { Serial1.println("AT+CIPCLOSE"); Serial.println("connection timeout"); delay(1000); return -1; } Serial1.print(cmd); unsigned int i = 0; //timeout counter //char json[100] = "{"; while (!Serial1.find("")) {} // find the part we are interested in. while (!Serial1.find("2015 ")) {} // find the part we are interested in. char h[2]; Serial1.readBytes(h, 2); int hour = atoi(h); //Serial.println(hour); // flush while(Serial1.available()){ char c = Serial1.read(); } return hour; } int getTemp(){ String cmd = "AT+CIPSTART=\"TCP\",\""; cmd += WeatherWS_IP; cmd += "\",80"; Serial1.println(cmd); Serial.println(cmd); if (Serial1.find("Error")){ Serial.println("error"); return -1; } cmd = "GET /data/2.5/weather?q="; cmd += LOCATION_NAME; cmd += "&mode=xml"; cmd += " HTTP/1.0\r\nHost: api.openweathermap.org\r\n\r\n"; Serial1.print("AT+CIPSEND="); Serial1.println(cmd.length()); if (Serial1.find(">")) { Serial.println(">"); } else { Serial1.println("AT+CIPCLOSE"); Serial.println("connection timeout"); //delay(1000); return -1; } Serial1.println(cmd); // unsigned int i = 0; //timeout counter // int n = 1; // char counter // char json[100] = "{"; // while (!Serial1.find("\"main\":{")) {} // find the part we are interested in. // while (i < 60000) { // if (Serial1.available()) { // char c = Serial1.read(); // json[n] = c; // if (c == '}') break; // n++; // i = 0; // } // i++; // } // Serial.println(json); // JsonObject& root = jsonBuffer.parseObject(json); // if (!root.success()) { // Serial.println("parseObject() failed"); // return -1; // } // // double temp = root["temp"]; // temp -= 273.15; int temperature = -111; while (!Serial1.find("