check pic version on boot

This commit is contained in:
Robert van den Breemen 2021-02-19 01:48:31 +01:00
parent 43576dacb0
commit 96088e2495
10 changed files with 69 additions and 40 deletions

View File

@ -25,6 +25,7 @@
"iosfwd": "cpp",
"xlocbuf": "cpp",
"random": "cpp",
"chrono": "cpp"
"chrono": "cpp",
"system_error": "cpp"
}
}

View File

@ -58,6 +58,31 @@ const char Helper[] = R"(
)";
const char Header[] = "HTTP/1.1 303 OK\r\nLocation:FSexplorer.html\r\nCache-Control: no-cache\r\n";
//=====================================================================================
void startWebserver(){
if (!LittleFS.exists("/index.html")) {
httpServer.serveStatic("/", LittleFS, "/FSexplorer.html");
httpServer.serveStatic("/index", LittleFS, "/FSexplorer.html");
httpServer.serveStatic("/index.html", LittleFS, "/FSexplorer.html");
} else{
httpServer.serveStatic("/", LittleFS, "/index.html");
httpServer.serveStatic("/index", LittleFS, "/index.html");
httpServer.serveStatic("/index.html", LittleFS, "/index.html");
}
httpServer.serveStatic("/FSexplorer.png", LittleFS, "/FSexplorer.png");
httpServer.serveStatic("/index.css", LittleFS, "/index.css");
httpServer.serveStatic("/index.js", LittleFS, "/index.js");
// all other api calls are catched in FSexplorer onNotFounD!
httpServer.on("/api", HTTP_ANY, processAPI); //was only HTTP_GET (20210110)
httpServer.begin();
// Set up first message as the IP address
OTGWSerial.println("\nHTTP Server started\r");
sprintf(cMsg, "%03d.%03d.%d.%d", WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3]);
OTGWSerial.printf("\nAssigned IP=%s\r\n", cMsg);
}
//=====================================================================================
void setupFSexplorer() // Funktionsaufruf "LittleFS();" muss im Setup eingebunden werden
{

View File

@ -221,6 +221,7 @@ String initWatchDog() {
// Code here is based on ESPEasy code, modified to work in the project.
// configure hardware pins according to eeprom settings.
DebugTln("Setup Watchdog");
DebugTln(F("INIT : I2C"));
Wire.begin(PIN_I2C_SDA, PIN_I2C_SCL); //configure the I2C bus
//=============================================
@ -1181,7 +1182,25 @@ void fwupgradestart(const char *hexfile) {
}
}
bool checkforupdatepic(String filename, String version){
WiFiClient client;
HTTPClient http;
String latest;
int code;
http.begin(client, "http://otgw.tclcode.com/download/" + filename);
http.collectHeaders(hexheaders, 2);
code = http.sendRequest("HEAD");
if (code == HTTP_CODE_OK) {
for (int i = 0; i< http.headers(); i++) {
DebugTf("%s: %s\n", hexheaders[i], http.header(i).c_str());
}
latest = http.header(1);
DebugTf("Update %s: %s -> %s\n", filename.c_str(), version.c_str(), latest.c_str());
http.end();
return (latest != version);
}
}
void refreshpic(String filename, String version) {
WiFiClient client;

View File

@ -53,10 +53,11 @@ WiFiClient wifiClient;
bool Verbose = false;
char cMsg[CMSG_SIZE];
char fChar[10];
String lastReset = "";
String lastReset = "";
uint64_t upTimeSeconds = 0;
uint32_t rebootCount = 0;
Timezone myTZ;
String sMessage = "";
const char *weekDayName[] { "Unknown", "Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Unknown" };
const char *flashMode[] { "QIO", "QOUT", "DIO", "DOUT", "Unknown" };
@ -66,8 +67,10 @@ String sPICfwversion = "";
bool bOTGWonline = true;
String errorupgrade = "";
//All things that are settings
String settingHostname = _HOSTNAME;
//MQTT settings
bool statusMQTTconnection = false;
bool settingMQTTenable = false;
@ -80,6 +83,7 @@ String settingMQTTtopTopic = "OTGW";
bool settingNTPenable = true;
String settingNTPtimezone = "CET"; //Default
//Now load network suff
#include "networkStuff.h"

View File

@ -72,48 +72,21 @@ void setup() {
startMDNS(CSTR(settingHostname));
startMQTT();
startNTP();
//start the debug port 23
startTelnet();
OTGWSerial.print("Use 'telnet ");
OTGWSerial.print(WiFi.localIP());
OTGWSerial.println("' for debugging");
//================ Start HTTP Server ================================
startTelnet(); //start the debug port 23
setupFSexplorer();
if (!LittleFS.exists("/index.html")) {
httpServer.serveStatic("/", LittleFS, "/FSexplorer.html");
httpServer.serveStatic("/index", LittleFS, "/FSexplorer.html");
httpServer.serveStatic("/index.html", LittleFS, "/FSexplorer.html");
} else{
httpServer.serveStatic("/", LittleFS, "/index.html");
httpServer.serveStatic("/index", LittleFS, "/index.html");
httpServer.serveStatic("/index.html", LittleFS, "/index.html");
}
httpServer.serveStatic("/FSexplorer.png", LittleFS, "/FSexplorer.png");
httpServer.serveStatic("/index.css", LittleFS, "/index.css");
httpServer.serveStatic("/index.js", LittleFS, "/index.js");
// all other api calls are catched in FSexplorer onNotFounD!
httpServer.on("/api", HTTP_ANY, processAPI); //was only HTTP_GET (20210110)
startWebserver();
httpServer.begin();
// Set up first message as the IP address
OTGWSerial.println("\nHTTP Server started\r");
sprintf(cMsg, "%03d.%03d.%d.%d", WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3]);
OTGWSerial.printf("\nAssigned IP=%s\r\n", cMsg);
DebugTln("Setup Watchdog");
initWatchDog(); // setup the WatchDog
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
DebugTln("Reset OTGW PIC");
resetOTGW(); // reset the OTGW pic
DebugTln("Start OTGW Stream");
startOTGWstream(); // start port 25238
DebugTf("OTGW PIC firmware version = [%s]\r\n", CSTR(sPICfwversion));
if (!checkforupdatepic("gateway.hex", OTGWSerial.firmwareVersion())) {
sMessage = "New PIC version available!";
}
DebugTf("Reboot count = [%d]\r\n", rebootCount);
setLed(LED1, OFF);
//Blink LED2 to signal setup done

View File

@ -70,7 +70,7 @@
<div class="bottom right-0">2021 &copy; Robert van den Breemen</div>
<!-- Pin to bottom left corner -->
<div id="message" class="bottom left-0">-</div>
<div id="message" class="bottom left-0"></div>
<script>
window.onload=initMainPage;

View File

@ -135,6 +135,7 @@
//console.log("Got new time ["+json.devtime[i].value+"]");
document.getElementById('theTime').innerHTML = json.devtime[i].value;
}
if (json.devtime[i].name == "message") document.getElementById('message').innerHTML = json.devtime[i].value;
}
})
.catch(function(error) {

View File

@ -119,9 +119,14 @@ void startWiFi(const char* hostname, int timeOut)
} // startWiFi()
//===========================================================================================
void startTelnet()
{
OTGWSerial.print("Use 'telnet ");
OTGWSerial.print(WiFi.localIP());
OTGWSerial.println("' for debugging");
TelnetStream.begin();
DebugTln(F("\nTelnet server started .."));
TelnetStream.flush();

View File

@ -333,6 +333,7 @@ void sendDeviceTime()
, hour(), minute(), second());
sendNestedJsonObj("dateTime", actTime);
sendNestedJsonObj("epoch", (int)now());
sendNestedJsonObj("message", sMessage);
sendEndJsonObj();

View File

@ -2,13 +2,13 @@
#define _VERSION_MAJOR 0
#define _VERSION_MINOR 7
#define _VERSION_PATCH 6
#define _VERSION_BUILD 649
#define _VERSION_BUILD 652
//#define _VERSION_PRERELEASE beta //uncomment to define prerelease labels: alpha - beta - rc
#define _VERSION_DATE "19-02-2021"
#define _VERSION_TIME "00:26:42"
#define _VERSION_TIME "01:41:25"
#define _SEMVER_CORE "0.7.6"
#define _SEMVER_BUILD "0.7.6+649"
#define _SEMVER_FULL "0.7.6+649"
#define _SEMVER_BUILD "0.7.6+652"
#define _SEMVER_FULL "0.7.6+652"
#define _SEMVER_NOBUILD "0.7.6 (19-02-2021)"
#define _VERSION "0.7.6+649 (19-02-2021)"
#define _VERSION "0.7.6+652 (19-02-2021)"
//The version information is created automatically, more information here: https://github.com/rvdbreemen/autoinc-semver