| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #pragma once
- //////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////
- /////////////////
- //
- // Global Include Files
- //
- //
- //
- #if 0
- #include <WiFiUdp.h>
- #include <ArduinoOTA.h>
- #include <ESP8266WiFi.h>
- //////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////
- /////////////////
- //
- // Include Files from local modules
- //
- //
- #include "globalDefs.h"
- #include "DebugHdl.h"
- #include "views/cViewHdl.h"
- #include "DisplayHdl.h"
- //////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////
- /////////////////
- //
- // Class instanciation, external declarations and defines
- //
- //
- const char *ssid = "WLAN-LX"; // <- SSID here
- const char *password = "SP-RAXX749x7"; // <- Password here
- const char *server = "192.168.1.10"; // the IP address of your HA server here
- const char *hostName = "ESP8266-Touch"; // HostName for mDNS resolution
- uint16_t port = 8123; // the port of your HA server here
- // Place your Long Lived Access Token from HA here:
- const char *authtoken = " ";
- /** OTA progress */
- int otaStatus = 0;
- //////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////
- /////////////////
- //
- // Capture Button actions
- //
- //
- class cMeshHdl
- {
- public:
- cMeshHdl(){};
- ~cMeshHdl(){};
- bool init()
- {
- LOGMSG(INFO, "[INFO]: Connecting to WLAN-LX");
- WiFi.mode(WIFI_STA);
- LOGMSG(INFO, "[WIFI]: Board MAC-Address: ", WiFi.macAddress().c_str());
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.print('.');
- }
- Serial.println("");
- LOGMSG(INFO, "[WIFI]: Connected! IP address: ", WiFi.localIP().toString().c_str());
- // LOGMSG(INFO | SRC,WiFi.localIP().toString().c_str());
- // std::cout << WiFi.localIP().toString().c_str() << endl;
- // Port defaults to 8266
- // ArduinoOTA.setPort(8266);
- // Hostname defaults to esp8266-[ChipID]
- // ArduinoOTA.setHostname("myesp8266");
- // No authentication by default
- // ArduinoOTA.setPassword((const char *)"123");
- ArduinoOTA.setHostname(hostName);
- /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- *
- */
- ArduinoOTA.onStart([]()
- {
- Serial.println("Start");
- tft.fillScreen(TFT_NAVY);
- delay(10);
- tft.fillScreen(TFT_NAVY);
- tft.setTextDatum(TL_DATUM);
- tft.setTextColor(TFT_WHITE);
- tft.setFreeFont(&FreeSansBold12pt7b); // Choose a nicefont that fits box
- tft.drawString("OTA",10,30);
- tft.drawString("Progress:",10,60); });
- /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- *
- */
- ArduinoOTA.onEnd([]()
- {
- Serial.println("\nEnd");
- // Clear the screen and print OTA finished text
- tft.fillScreen(TFT_GREEN);
- delay(10);
- tft.fillScreen(TFT_GREEN);
- tft.setTextDatum(TL_DATUM);
- tft.setTextColor(TFT_BLACK);
- tft.setFreeFont(&FreeSansBold12pt7b); // Choose a nicefont that fits box
- tft.drawString("OTA",10,30);
- tft.drawString("FINISHED!",10,60);
- delay(1000); });
- /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- *
- */
- ArduinoOTA.onProgress([](unsigned int progress, unsigned int total)
- {
- Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
- // Calculate progress
- // unsigned int achieved = progress / (total / 100); // caused unsigned / signed warning message
- int achieved = progress / (total / 100);
- // Update progress every 1 %
- if (otaStatus == 0 || achieved == otaStatus + 1) {
- // Toggle the LED
- // digitalWrite(16, !digitalRead(16));
- otaStatus = achieved;
- // Print the progress
- // tft.setFreeFont(&FreeSansBold12pt7b); // Choose a nicefont that fits box
- tft.setTextDatum(TL_DATUM);
- // tft.setTextSize(1);
- tft.fillRect(120,100,80,30,TFT_NAVY);
- delay(10);
- String progVal = String(achieved) + "%";
- tft.drawString(progVal,125,100);
- } });
- /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- *
- */
- ArduinoOTA.onError([](ota_error_t error)
- {
- Serial.printf("Error[%u]: ", error);
- if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
- else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
- else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
- else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
- else if (error == OTA_END_ERROR) Serial.println("End Failed");
- // Clear the screen for error message
- tft.fillScreen(TFT_RED);
- tft.setTextDatum(TL_DATUM);
- tft.setTextColor(TFT_WHITE);
- // Print error message
- tft.setTextSize(1);
- tft.drawString("OTA",10,30);
- tft.drawString("ERROR:",10,60);
- // Get detailed error and print error reason
- if (error == OTA_AUTH_ERROR) {
- tft.drawString("Auth Failed",10,120);
- }
- else if (error == OTA_BEGIN_ERROR) {
- tft.drawString("Begin Failed",10,120);
- }
- else if (error == OTA_CONNECT_ERROR) {
- tft.drawString("Connect Failed",10,120);
- }
- else if (error == OTA_RECEIVE_ERROR) {
- tft.drawString("Receive Failed",10,120);
- }
- else if (error == OTA_END_ERROR) {
- tft.drawString("End Failed",10,120);
- }
- otaStatus = 0; });
- /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- *
- */
- ArduinoOTA.begin();
- return FNC_SUCCESS;
- }
- /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- *
- */
- void showConfiguration()
- {
- LOGMSG(INFO, "[MESH]: MESH initialized");
- }
- /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- *
- */
- void run()
- {
- ArduinoOTA.handle();
- }
- }; // end of class cMeshHdl
- #endif
|