diff --git a/include/osw_hal.h b/include/osw_hal.h index 2af859537..6ee96009e 100644 --- a/include/osw_hal.h +++ b/include/osw_hal.h @@ -133,8 +133,6 @@ class OswHal { uint8_t getActivityMode(void); // Time - - void updateTimeViaNTP(long gmtOffset_sec, int daylightOffset_sec, uint32_t timeout_sec); void setUTCTime(long); uint32_t getUTCTime(void); void getUTCTime(uint32_t* hour, uint32_t* minute, uint32_t* second); @@ -145,9 +143,6 @@ class OswHal { void getDate(uint32_t* day, uint32_t* month, uint32_t* year); void getWeekdayString(int firstNChars, string* output); - // RF - MiniWifi* getWiFi(void); - // Destructor ~OswHal(){}; diff --git a/include/services/OswServiceTaskWiFi.h b/include/services/OswServiceTaskWiFi.h index 7d1b967e0..8c2e49631 100644 --- a/include/services/OswServiceTaskWiFi.h +++ b/include/services/OswServiceTaskWiFi.h @@ -23,6 +23,8 @@ class OswServiceTaskWiFi : public OswServiceTask { bool isConnected(); IPAddress getIP(); /// Either get ip of this ap client it connected and enabled or station if enabled void queueTimeUpdateViaNTP(); + int32_t getSignalStrength(); + uint8_t getSignalQuality(); //WiFi (client) bool isWiFiEnabled(); diff --git a/src/apps/_experiments/dnatilt.cpp b/src/apps/_experiments/dnatilt.cpp index b201e5946..ea87ba91f 100644 --- a/src/apps/_experiments/dnatilt.cpp +++ b/src/apps/_experiments/dnatilt.cpp @@ -7,16 +7,17 @@ #include #include +#include +#include + #define HTTP_GET_BUF_LEN 10 char httpGetBuffer[HTTP_GET_BUF_LEN]; -void OswAppDNATilt::setup(OswHal* hal) { // - hal->getWiFi()->setDebugStream(&Serial); +void OswAppDNATilt::setup(OswHal* hal) { + } void OswAppDNATilt::loop(OswHal* hal) { - hal->getWiFi()->checkWifi(); - static long lastDraw = 0; if (millis() - lastDraw > 250 /* 4fps redraw */) { @@ -31,7 +32,7 @@ void OswAppDNATilt::loop(OswHal* hal) { } else if (hal->getAccelerationX() < -250) { hal->getCanvas()->print("DNA Lamp --"); } else { - if (hal->getWiFi()->isConnected()) { + if (OswServiceAllTasks::wifi.isConnected()) { hal->getCanvas()->print("DNA Lamp"); } else { hal->getCanvas()->print("No WiFi"); @@ -41,9 +42,15 @@ void OswAppDNATilt::loop(OswHal* hal) { hal->requestFlush(); } +/* + THIS IS NOW MANAGED BY THE WIFI SERVICE. + The get() method is still a NON-STATIC method of MiniWiFi and therfore currently unusable. + Then you need this code working, please contact the author of the MiniWiFi lib or extend it youself. + if (hal->getAccelerationX() > 250) { hal->getWiFi()->get("http://192.168.1.54/api/ladder/hue/decr", httpGetBuffer, HTTP_GET_BUF_LEN); } else if (hal->getAccelerationX() < -250) { hal->getWiFi()->get("http://192.168.1.54/api/ladder/hue/incr", httpGetBuffer, HTTP_GET_BUF_LEN); } +*/ } diff --git a/src/apps/tools/time_config.cpp b/src/apps/tools/time_config.cpp index b05ca9ea0..12e8f6e78 100644 --- a/src/apps/tools/time_config.cpp +++ b/src/apps/tools/time_config.cpp @@ -1,4 +1,3 @@ - #include "./apps/tools/time_config.h" #include @@ -9,9 +8,11 @@ #include #include +#include +#include void OswAppTimeConfig::setup(OswHal* hal) { - hal->getWiFi()->setDebugStream(&Serial); + } void OswAppTimeConfig::enterManualMode(OswHal* hal) { @@ -148,7 +149,7 @@ void OswAppTimeConfig::loop(OswHal* hal) { hal->gfx()->setTextSize(2); OswUI::getInstance()->setTextCursor(BUTTON_3); - if (hal->getWiFi()->isConnected()) { + if (OswServiceAllTasks::wifi.isConnected()) { hal->gfx()->print(LANG_DISCONNECT); } else { hal->gfx()->print(LANG_CONNECT); @@ -157,19 +158,21 @@ void OswAppTimeConfig::loop(OswHal* hal) { } if (hal->btnHasGoneDown(BUTTON_3)) { - if (hal->getWiFi()->isConnected()) { - hal->getWiFi()->disableWiFi(); + if (OswServiceAllTasks::wifi.isConnected()) { + OswServiceAllTasks::wifi.disconnectWiFi(); + OswServiceAllTasks::wifi.disableWiFi(); } else { - hal->getWiFi()->joinWifi(); + OswServiceAllTasks::wifi.enableWiFi(); + OswServiceAllTasks::wifi.connectWiFi(); } } - if (hal->getWiFi()->isConnected()) { + if (OswServiceAllTasks::wifi.isConnected()) { OswUI::getInstance()->setTextCursor(BUTTON_2); hal->gfx()->print(LANG_TFW_UPDATE); if (hal->btnHasGoneDown(BUTTON_2)) { - if (hal->getWiFi()->isConnected()) { - hal->updateTimeViaNTP(OswConfigAllKeys::timeZone.get() * 3600, OswConfigAllKeys::daylightOffset.get() * 3600, 5 /*seconds*/); + if (OswServiceAllTasks::wifi.isConnected()) { + OswServiceAllTasks::wifi.queueTimeUpdateViaNTP(); } } } else { diff --git a/src/hal/time.cpp b/src/hal/time.cpp index 2364c842e..cd6cb1bf9 100644 --- a/src/hal/time.cpp +++ b/src/hal/time.cpp @@ -139,26 +139,4 @@ void OswHal::getWeekdayString(int firstNChars, string *output) { } *output = value.substr(0, firstNChars); -} - -void OswHal::updateTimeViaNTP(long gmtOffset_sec, int daylightOffset_sec, uint32_t timeout_sec) { - long start = millis(); - if (getWiFi()->isConnected()) { - // this configures the timezone and sets the esps time to UTC - configTime(gmtOffset_sec + 3600, daylightOffset_sec, "pool.ntp.org", "time.nist.gov"); - - Serial.println("Waiting for time"); - - while (!time(nullptr) && millis() - start < timeout_sec * 1000) { - Serial.print("."); - delay(1000); - } - - // sometimes time(nullptr) returns seconds since boot - // so check the request was resolved - if (time(nullptr) > 1600000000) { - Serial.println(time(nullptr)); - setUTCTime(time(nullptr)); - } - } -} +} \ No newline at end of file diff --git a/src/hal/wifi.cpp b/src/hal/wifi.cpp deleted file mode 100644 index 4f92e5dd5..000000000 --- a/src/hal/wifi.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -#include "osw_hal.h" - -String wifiSsid = OswConfigAllKeys::wifiSsid.get(); -String wifiPass = OswConfigAllKeys::wifiPass.get(); -MiniWifi wifi(DEVICE_NAME, wifiSsid.c_str(), wifiPass.c_str()); - -MiniWifi* OswHal::getWiFi(void) { return &wifi; } \ No newline at end of file diff --git a/src/overlays/overlays.cpp b/src/overlays/overlays.cpp index eccc0be04..9d61f854d 100644 --- a/src/overlays/overlays.cpp +++ b/src/overlays/overlays.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "./overlays/overlays.h" #include "osw_pins.h" @@ -28,8 +31,8 @@ void drawBattery(OswHal* hal, uint16_t x, uint16_t y) { } void drawWiFi(OswHal* hal, uint16_t x, uint16_t y) { - if (hal->getWiFi()->isEnabled()) { - for (uint8_t i = 0; i < hal->getWiFi()->getSignalQuality() / 20; i++) { + if (OswServiceAllTasks::wifi.isWiFiEnabled()) { + for (uint8_t i = 0; i < OswServiceAllTasks::wifi.getSignalQuality() / 20; i++) { hal->getCanvas()->getGraphics2D()->fillFrame(x + 3 * i, y + 12 - i * 2, 2, i * 2, OswUI::getInstance()->getForegroundColor()); // outer frame } @@ -39,7 +42,7 @@ void drawWiFi(OswHal* hal, uint16_t x, uint16_t y) { void drawOverlays(OswHal* hal) { if (hal->isCharging()) { drawUsbConnected(hal, 120 - 16, 6); // width is 31 - } else if (!hal->getWiFi()->isConnected()) { + } else if (!OswServiceAllTasks::wifi.isConnected()) { drawBattery(hal, 120 - 15, 6); } drawWiFi(hal, 138, 6); diff --git a/src/services/OswServiceTaskWiFi.cpp b/src/services/OswServiceTaskWiFi.cpp index 07c0b3fd0..fb013ebab 100644 --- a/src/services/OswServiceTaskWiFi.cpp +++ b/src/services/OswServiceTaskWiFi.cpp @@ -235,4 +235,18 @@ void OswServiceTaskWiFi::updateWiFiConfig() { Serial.println(String(__FILE__) + ": Off"); #endif } +} + +int32_t OswServiceTaskWiFi::getSignalStrength() { return WiFi.RSSI(); } +uint8_t OswServiceTaskWiFi::getSignalQuality() { + int32_t rssi = getSignalStrength(); + uint8_t quality = 0; + if (rssi < -100) { + quality = 0; + } else if (rssi > -50) { + quality = 100; + } else { + quality = 2 * (rssi + 100); + } + return quality; } \ No newline at end of file