cleaning up setup

This commit is contained in:
Robert van den Breemen 2021-03-06 10:52:51 +01:00
parent fc32a1f590
commit 1a64053e55
3 changed files with 29 additions and 27 deletions

View File

@ -84,6 +84,16 @@ String getpicfwversion(){
_ret.trim();
return _ret;
}
//===================[ checkOTWGpicforupdate ]=====================
void checkOTWGpicforupdate(){
DebugTf("OTGW PIC firmware version = [%s]\r\n", CSTR(sPICfwversion));
String latest = checkforupdatepic("gateway.hex");
if (!bOTGWonline) {
sMessage = sPICfwversion;
} else if (latest != sPICfwversion) {
sMessage = "New PIC version " + latest + " available!";
}
}
//===================[ OTGW Command & Response ]===================
String executeCommand(const String sCmd){
//send command to OTGW

View File

@ -41,13 +41,11 @@ void setup() {
OTGWSerial.println(F("\r\n[OTGW firmware - Nodoshop version]\r\n"));
OTGWSerial.printf("Booting....[%s]\r\n\r\n", String(_FW_VERSION).c_str());
rebootCount = updateRebootCount();
//setup randomseed the right way
randomSeed(RANDOM_REG32); //This is 8266 HWRNG used to seed the Random PRNG: Read more: https://config9.com/arduino/getting-a-truly-random-number-in-arduino/
lastReset = ESP.getResetReason();
lastReset = ESP.getResetReason();
OTGWSerial.printf("Last reset reason: [%s]\r\n", CSTR(ESP.getResetReason()));
//setup the status LED
@ -61,12 +59,7 @@ void setup() {
OTGWSerial.println(F("Attempting to connect to WiFi network\r"));
setLed(LED1, ON);
startWiFi(_HOSTNAME, 240); // timeout 240 seconds
for (int i=0; i<=3;i++) {
blinkLEDnow(LED1);
delay(100);
blinkLEDnow(LED1);
delay(100);
}
blinkLED(LED1, 3, 100);
setLed(LED1, OFF);
startMDNS(CSTR(settingHostname));
@ -76,30 +69,19 @@ void setup() {
setupFSexplorer();
startWebserver();
OTGWSerial.println(F("Setup finished!\r\n"));
// After resetting the OTGW PIC never send anything to Serial for debug
// and switch to telnet port 23 for debug purposed.
// Setup the OTGW PIC
resetOTGW(); // reset the OTGW pic
startOTGWstream(); // start port 25238
DebugTf("OTGW PIC firmware version = [%s]\r\n", CSTR(sPICfwversion));
String latest = checkforupdatepic("gateway.hex");
if (!bOTGWonline) {
sMessage = sPICfwversion;
} else if (latest != sPICfwversion) {
sMessage = "New PIC version " + latest + " available!";
}
DebugTf("Reboot count = [%d]\r\n", rebootCount);
initWatchDog(); // setup the WatchDog
checkOTWGpicforupdate();
initWatchDog(); // setup the WatchDog
//Blink LED2 to signal setup done
setLed(LED1, OFF);
for (int i=0; i<=3;i++) {
blinkLEDnow(LED2);
delay(100);
blinkLEDnow(LED2);
delay(100);
}
blinkLED(LED2, 3, 100);
setLed(LED2, OFF);
}
@ -120,10 +102,19 @@ void blinkLEDms(uint32_t delay){
}
}
void blinkLEDnow(){
blinkLEDnow(LED1);
void blinkLED(uint8_t led, int nr, uint32_t waittime_ms, ){
for (int i = nr; i>0; i--){
blinkLEDnow(led);
delayms(waittime_ms);
blinkLEDnow(led);
delayms(waittime_ms);
}
}
// void blinkLEDnow(){
// blinkLEDnow(LED1);
// }
void blinkLEDnow(uint8_t led = LED1){
pinMode(led, OUTPUT);
digitalWrite(led, !digitalRead(led));

View File

@ -529,7 +529,8 @@ uint32_t updateRebootCount()
fh.println(_reboot);
}
fh.close();
}
}
DebugTf("Reboot count = [%d]\r\n", rebootCount);
return _reboot;
}