├── .gitattributes └── Live_Temperature_of_Ahmedabad └── Live_Temperature_of_Ahmedabad.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Live_Temperature_of_Ahmedabad/Live_Temperature_of_Ahmedabad.ino: -------------------------------------------------------------------------------- 1 | /** 2 | BasicHTTPClient.ino 3 | 4 | Created on: 24.05.2015 5 | 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #define USE_SERIAL Serial 16 | 17 | ESP8266WiFiMulti WiFiMulti; 18 | 19 | void setup() { 20 | 21 | USE_SERIAL.begin(115200); 22 | // USE_SERIAL.setDebugOutput(true); 23 | 24 | USE_SERIAL.println(); 25 | USE_SERIAL.println(); 26 | USE_SERIAL.println(); 27 | 28 | for (uint8_t t = 4; t > 0; t--) { 29 | USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); 30 | USE_SERIAL.flush(); 31 | delay(1000); 32 | } 33 | 34 | WiFi.mode(WIFI_STA); 35 | WiFiMulti.addAP("SSID_NAME", "PASSWORD"); 36 | 37 | } 38 | 39 | void loop() { 40 | // wait for WiFi connection 41 | if ((WiFiMulti.run() == WL_CONNECTED)) { 42 | 43 | HTTPClient http; 44 | 45 | USE_SERIAL.print("[HTTP] begin...\n"); 46 | // configure traged server and url 47 | //http.begin("https://192.168.1.12/test.html", "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS 48 | http.begin("http://api.thingspeak.com/apps/thinghttp/send_request?api_key=LS42ML70EW8J0ZC7"); //HTTP 49 | 50 | USE_SERIAL.print("[HTTP] GET...\n"); 51 | // start connection and send HTTP header 52 | int httpCode = http.GET(); 53 | 54 | // httpCode will be negative on error 55 | if (httpCode > 0) { 56 | // HTTP header has been send and Server response header has been handled 57 | USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode); 58 | 59 | // file found at server 60 | if (httpCode == HTTP_CODE_OK) { 61 | String payload = http.getString(); 62 | USE_SERIAL.println(payload); 63 | 64 | Serial.print("Temperature in Fahrenheit :- "); Serial.println(payload); 65 | 66 | 67 | 68 | int temp = payload.toInt(); 69 | temp = (temp - 32) * 5 / 9; 70 | 71 | Serial.print("Temperature in Celsius :- ");Serial.println(temp); 72 | 73 | 74 | } 75 | } else { 76 | USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 77 | } 78 | 79 | http.end(); 80 | } 81 | 82 | delay(10000); 83 | } 84 | --------------------------------------------------------------------------------