///////////////////// // Domoticz Classe ///////////////////// #include #include #include "Domoticz.h" Domoticz domo("192.168.1.3", "81", "Livebox-37cc", "8A6060920A8A86896F770F2C47"); // Params * params; #include "Ecran.h" Ecran * ecran; double temp; class Meteo { public: double temp; double pressure; int humidity; String description; String icon; }; Meteo * meteo; const char* meteo_url = "http://api.openweathermap.org/data/2.5/weather?q=La%20gacilly,fr&APPID=feba3f4d926db3b358a25ec782bd1c8b&lang=FR&units=metric"; // Convert image to char array http://www.digole.com/tools/PicturetoC_Hex_converter.php // domoticz String macID = ""; void setup() { Serial.begin(115200); // // Conversion d'objet en pointeur Params p; params = &p; Meteo m; meteo = &m; // display Bitcoin Logo LCD_X // ecran->gotoXY(0,0); ecran->LcdString("Init :"); ecran->LcdString(domo._domoticz); domo.initWifi(); macID = domo.generateKey(); readMeteo(); delay(500); Ecran e; ecran = &e; ecran->initialise(); ecran->intro(); //#if 1 // show image for array // printf("show image for array\r\n"); // Paint_SelectImage(BlackImage); // Paint_Clear(WHITE); //// Paint_DrawBitMap(gImage_7in5_V2); // EPD_7IN5_V2_Display(BlackImage); // DEV_Delay_ms(2000); //#endif // //#if 1 // Drawing on the image // //1.Select Image // printf("SelectImage:BlackImage\r\n"); // Paint_SelectImage(BlackImage); ecran->clear(); // 2.Drawing on the image printf("Drawing:BlackImage\r\n"); // Paint_DrawPoint(10, 80, BLACK, DOT_PIXEL_1X1, DOT_STYLE_DFT); // Paint_DrawPoint(10, 90, BLACK, DOT_PIXEL_2X2, DOT_STYLE_DFT); // Paint_DrawPoint(10, 100, BLACK, DOT_PIXEL_3X3, DOT_STYLE_DFT); ecran->drawLine(20, 70, 70, 120, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID); ecran->drawLine(70, 70, 20, 120, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID); ecran->drawRect(3, 3, 797, 477, RED, DOT_PIXEL_3X3, DRAW_FILL_EMPTY); ecran->drawRect(80, 70, 130, 120, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL); ecran->drawCircle(45, 95, 20, LUT_RED_0, DOT_PIXEL_1X1, DRAW_FILL_EMPTY); ecran->drawCircle(105, 95, 20, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL); ecran->drawLine(85, 95, 125, 95, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED); ecran->drawLine(105, 75, 105, 115, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED); Paint_DrawString_EN(10, 0, String(meteo->description).c_str(), &Font16, BLACK, WHITE); Paint_DrawString_EN(10, 20, "hello world", &Font12, WHITE, BLACK); // Paint_DrawNum(10, 33, meteo->humidity, &Font12, BLACK, WHITE); Paint_DrawNum(10, 50, 987654321, &Font16, WHITE, BLACK); // Paint_DrawString_CN(130, 0, " 你好abc", &Font12CN, BLACK, WHITE); // Paint_DrawString_CN(130, 20, "微雪电子", &Font24CN, WHITE, BLACK); printf("EPD_Display\r\n"); EPD_7IN5_V2_Display(ecran->BlackImage); DEV_Delay_ms(2000); // printf("Clear...\r\n"); // EPD_7IN5_V2_Clear(); // // printf("Goto Sleep...\r\n"); // EPD_7IN5_V2_Sleep(); // free(BlackImage); // BlackImage = NULL; // ecran->LcdBitmap(LCD_X, LCD_Y, bitcoin); // ecran->LcdString(0, 0, domo._domoticz); // ecran->LcdChar(0, 10, "ID : "); // ecran->LcdString(40, 10, macID); // domo.getIdFromDomoticz(macID, params); //readTemp(); // printInfo(); // for (int i = 0; i <= 100; i+=10) { // ecran->LcdClear(); // ecran->drawRect(1, 1, LCD_X -1, LCD_Y -1); // ecran->drawJauge(10, 24, LCD_X -10, 34, i, "Jauge"); // delay(100); // } delay(2000); // Test Json ecran->sleep(); } void loop() { } void sleepWifi() { //Time to let the WiFi go to sleep! // printf("Sleeping..."); WiFi.disconnect(); WiFi.mode(WIFI_OFF); // WiFi.forceSleepBegin(params->sleepTime * 1000000L); //In uS. Must be same length as your delay delay(params->sleepTime * 1000); //Hang out at 15mA for 6 seconds WiFi.mode(WIFI_STA); // printf("Awake!"); } void readMeteo() { // if (WiFi.status()== WL_CONNECTED){ String sensorReadings = httpGETRequest(meteo_url); Serial.println(sensorReadings); JSONVar myObject = JSON.parse(sensorReadings); // JSON.typeof(jsonVar) can be used to get the type of the var if (JSON.typeof(myObject) == "undefined") { Serial.println("Parsing input failed!"); return; } Serial.print("JSON object = "); Serial.println(myObject); // myObject.keys() can be used to get an array of all the keys in the object JSONVar main = myObject["main"]; Serial.print("main ===>"); Serial.println(main); Serial.print("weather ===>"); JSONVar weathers = myObject["weather"]; String weather0 = weathers[0]; // JSONVar weather = JSON.parse(weather0); Serial.println(weathers[0].keys()); JSONVar keys = main.keys(); JSONVar t = main["temp"]; temp = double(t); JSONVar d = weathers[0]["description"]; // meteo->humidity = int(main['humidity']); meteo->description = String(d); // Serial.println(weathers[0]["description"]); for (int i = 0; i < keys.length(); i++) { JSONVar value = main[keys[i]]; Serial.print(keys[i]); Serial.print(" = "); Serial.println(value); // sensorReadingsArr[i] = double(value); } // } } String httpGETRequest(const char* serverName) { WiFiClient client; HTTPClient http; // Your Domain name with URL path or IP address with path http.begin(client, serverName); // If you need Node-RED/server authentication, insert user and password below //http.setAuthorization("REPLACE_WITH_SERVER_USERNAME", "REPLACE_WITH_SERVER_PASSWORD"); // Send HTTP POST request int httpResponseCode = http.GET(); String payload = "{}"; if (httpResponseCode>0) { Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); payload = http.getString(); } else { Serial.print("Error code: "); Serial.println(httpResponseCode); } // Free resources http.end(); return payload; }