From d90f6854e97645ec07f5c477a4c9baff4e83b3fd Mon Sep 17 00:00:00 2001 From: tablatronix Date: Wed, 13 Nov 2019 23:11:05 -0600 Subject: [PATCH] Update OnDemandConfigPortal.ino adds ota to dev example suite --- .../OnDemandConfigPortal.ino | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 7b5e3ec..2591356 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -6,6 +6,14 @@ #include // https://github.com/tzapu/WiFiManager #include +#define USEOTA +// enable OTA +#ifdef USEOTA +#include +#include +bool otastarted = false; +#endif + #define TRIGGER_PIN 0 const char* modes[] = { "NULL", "STA", "AP", "STA+AP" }; @@ -60,10 +68,13 @@ void print_oled(String str,uint8_t size){ } WiFiManager wm; -bool TEST_CP = false; // always start the configportal -bool TEST_NET = true; // do a network test, get ntp time -char ssid[] = "*************"; // your network SSID (name) -char pass[] = "********"; // your network password + +// OPTION FLAGS +bool TEST_CP = true; // always start the configportal, even if ap found +bool TEST_NET = true; // do a network test after connect, (gets ntp time) + +// char ssid[] = "*************"; // your network SSID (name) +// char pass[] = "********"; // your network password void saveWifiCallback(){ Serial.println("[CALLBACK] saveCallback fired"); @@ -100,8 +111,12 @@ void setup() { WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP // put your setup code here, to run once: Serial.begin(115200); + Serial1.begin(115200); + // Serial.setDebugOutput(true); - // delay(3000); + delay(1000); + Serial1.println("TXD1 Enabled"); + Serial.println("\n Starting"); // WiFi.setSleepMode(WIFI_NONE_SLEEP); // disable sleep, can improve ap stability @@ -173,7 +188,7 @@ void setup() { wm.setCountry("US"); // setting wifi country seems to improve OSX soft ap connectivity, may help others as well // set channel - wm.setWiFiAPChannel(13); + // wm.setWiFiAPChannel(13); // set AP hidden // wm.setAPHidden(true); @@ -205,9 +220,22 @@ void setup() { print_oled("Connected\nIP: " + WiFi.localIP().toString() + "\nSSID: " + WiFi.SSID(),1); } pinMode(TRIGGER_PIN, INPUT); + + #ifdef USEOTA + ArduinoOTA.begin(); + ArduinoOTA.onStart([]() { + otastarted = true; + Serial.println("\nOTA onStart"); + }); + #endif } void loop() { + + #ifdef USEOTA + ArduinoOTA.handle(); + if(otastarted)return; + #endif // is configuration portal requested? if ( digitalRead(TRIGGER_PIN) == LOW ) { delay(100);