Update to 0.0.11

This commit is contained in:
fvanroie 2020-03-21 14:56:54 +01:00
parent b72c5fbbca
commit e4da288990
8 changed files with 81 additions and 54 deletions

View File

@ -194,10 +194,10 @@ build_flags =
[env:d1mini-lolintft24] [env:d1mini-lolintft24]
platform = espressif8266@2.3.2 platform = espressif8266@2.3.2
board = d1_mini board = d1_mini
upload_port = COM4 ; Change to the correct port upload_port = COM13 ; Change to the correct port
;upload_protocol = espota ; Use ArduinoOTA after flashing over serial ;upload_protocol = espota ; Use ArduinoOTA after flashing over serial
;upload_port = 10.1.0.148 ; IP of the ESP ;upload_port = 10.1.0.148 ; IP of the ESP
monitor_port = COM4 ; Change to the correct port monitor_port = COM13 ; Change to the correct port
monitor_speed = 74880 monitor_speed = 74880
board_build.f_flash = 40000000L board_build.f_flash = 40000000L
board_build.flash_mode = dout board_build.flash_mode = dout

View File

@ -76,8 +76,8 @@ void dispatchAttribute(String & strTopic, const char * payload)
} // valid page } // valid page
} }
} else if(strTopic.startsWith(F("output"))) { } else if(strTopic.startsWith(F("output"))) {
uint8_t state = isON(payload) ? HIGH : LOW;
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
uint8_t state = isON(payload) ? HIGH : LOW;
digitalWrite(D1, state); digitalWrite(D1, state);
#endif #endif
@ -222,7 +222,7 @@ void dispatchJsonl(char * strPayload)
DynamicJsonDocument config(256); DynamicJsonDocument config(256);
String output((char *)0); String output((char *)0);
output.reserve(MQTT_MAX_PACKET_SIZE+ 256); output.reserve(MQTT_MAX_PACKET_SIZE + 256);
StringStream stream((String &)output); StringStream stream((String &)output);
stream.print(strPayload); stream.print(strPayload);

View File

@ -1,6 +1,7 @@
//#include "webServer.h" //#include "webServer.h"
#include <Arduino.h> #include "Arduino.h"
#include "ArduinoJson.h" #include "ArduinoJson.h"
//#include "Update.h"
#include "lvgl.h" #include "lvgl.h"
#include "hasp_conf.h" #include "hasp_conf.h"
@ -241,7 +242,7 @@ void webHandleScreenshot()
if(!httpIsAuthenticated(F("screenshot"))) return; if(!httpIsAuthenticated(F("screenshot"))) return;
if(webServer.hasArg(F("q"))) { if(webServer.hasArg(F("q"))) {
webServer.setContentLength(138 + 320 * 240 * 4); webServer.setContentLength(122 + 320 * 240 * 2);
webServer.send(200, PSTR("image/bmp"), ""); webServer.send(200, PSTR("image/bmp"), "");
guiTakeScreenshot(webServer); guiTakeScreenshot(webServer);
@ -336,7 +337,7 @@ void webHandleInfo()
/* HASP Stats */ /* HASP Stats */
httpMessage += F("<b>HASP Version: </b>"); httpMessage += F("<b>HASP Version: </b>");
httpMessage += String(haspGetVersion()); httpMessage += String(haspGetVersion());
httpMessage += F("<b>Build DateTime: </b>"); httpMessage += F("<br/><b>Build DateTime: </b>");
httpMessage += __DATE__; httpMessage += __DATE__;
httpMessage += F(" "); httpMessage += F(" ");
httpMessage += __TIME__; httpMessage += __TIME__;
@ -385,7 +386,7 @@ void webHandleInfo()
// +String(mqttClient.returnCode()); // +String(mqttClient.returnCode());
} }
httpMessage += F("<br/><b>MQTT ClientID: </b>"); httpMessage += F("<br/><b>MQTT ClientID: </b>");
// +String(mqttClientId); httpMessage += nodename;
/* ESP Stats */ /* ESP Stats */
httpMessage += F("</p/><p><b>ESP Chip Id: </b>"); httpMessage += F("</p/><p><b>ESP Chip Id: </b>");
@ -504,6 +505,33 @@ bool handleFileRead(String path)
return false; return false;
} }
/*
void handleFirmwareUpdate()
{
upload = &webServer.upload();
if(upload->status == UPLOAD_FILE_START) {
if(!httpIsAuthenticated(F("firmwareupdate"))) return false;
Serial.printf("Update: %s\n", upload->filename.c_str());
if(!Update.begin(UPDATE_SIZE_UNKNOWN)) { // start with max available size
Update.printError(Serial);
}
} else if(upload->status == UPLOAD_FILE_WRITE) {
// flashing firmware to /
if(Update.write(upload->buf, upload->currentSize) != upload->currentSize) {
Update.printError(Serial);
}
}
else if(upload->status == UPLOAD_FILE_END)
{
if(Update.end(true)) { // true to set the size to the current progress
Serial.printf("Update Success: %u\nRebooting...\n", upload->totalSize);
} else {
Update.printError(Serial);
}
}
}
*/
void handleFileUpload() void handleFileUpload()
{ {
if(webServer.uri() != "/edit") { if(webServer.uri() != "/edit") {

View File

@ -41,6 +41,13 @@ void mdnsStart()
MDNS.addService(F("http"), F("tcp"), 80); MDNS.addService(F("http"), F("tcp"), 80);
MDNS.addService(F("telnet"), F("tcp"), 23); MDNS.addService(F("telnet"), F("tcp"), 23);
MDNS.addServiceTxt(hasp2Node, F("tcp"), F("app_name"), F("HASP-lvgl")); MDNS.addServiceTxt(hasp2Node, F("tcp"), F("app_name"), F("HASP-lvgl"));
/*
addService("arduino", "tcp", port);
addServiceTxt("arduino", "tcp", "tcp_check", "no");
addServiceTxt("arduino", "tcp", "ssh_upload", "no");
addServiceTxt("arduino", "tcp", "board", ARDUINO_BOARD);
addServiceTxt("arduino", "tcp", "auth_upload", (auth) ? "yes" : "no");
*/
} else { } else {
errorPrintln(String(F("MDNS: %sResponder failed to start ")) + hasp2Node); errorPrintln(String(F("MDNS: %sResponder failed to start ")) + hasp2Node);
}; };

View File

@ -201,6 +201,13 @@ void mqttStatusUpdate()
mqttStatusPayload += F("\"espCore\":\""); mqttStatusPayload += F("\"espCore\":\"");
mqttStatusPayload += halGetCoreVersion(); mqttStatusPayload += halGetCoreVersion();
mqttStatusPayload += F("\""); mqttStatusPayload += F("\"");
#if defined(ARDUINO_ARCH_ESP8266)
mqttStatusPayload += F(",");
mqttStatusPayload += F("\"Vcc\":\"");
mqttStatusPayload += (float)ESP.getVcc() / 1000;
mqttStatusPayload += F("\"");
#endif
mqttStatusPayload += "}"; mqttStatusPayload += "}";
// mqttClient.publish(mqttSensorTopic, mqttStatusPayload); // mqttClient.publish(mqttSensorTopic, mqttStatusPayload);

View File

@ -10,6 +10,7 @@
#include "hasp_log.h" #include "hasp_log.h"
#include "hasp_debug.h" #include "hasp_debug.h"
#include "hasp_config.h" #include "hasp_config.h"
#include "hasp_dispatch.h"
#include "hasp_gui.h" #include "hasp_gui.h"
#include "hasp.h" #include "hasp.h"
@ -37,6 +38,7 @@ char wifiPassword[32] = WIFI_PASSW;
#else #else
char wifiPassword[32] = ""; char wifiPassword[32] = "";
#endif #endif
uint8_t wifiReconnectCounter = 0;
// const byte DNS_PORT = 53; // const byte DNS_PORT = 53;
// DNSServer dnsServer; // DNSServer dnsServer;
@ -67,19 +69,24 @@ void wifiConnected(IPAddress ipaddress)
debugPrintln(buffer); debugPrintln(buffer);
if(isConnected) { if(isConnected) {
mqttReconnect(); /* mqttReconnect();
haspReconnect(); haspReconnect();*/
httpReconnect(); httpReconnect();
mdnsStart(); // mdnsStart();
} }
} }
void wifiDisconnected(const char * ssid, uint8_t reason) void wifiDisconnected(const char * ssid, uint8_t reason)
{ {
char buffer[128]; char buffer[128];
wifiReconnectCounter++;
if(wifiReconnectCounter > 45) {
snprintf_P(buffer, sizeof(buffer), PSTR("WIFI: %%s Retries exceed %u: Rebooting..."), wifiReconnectCounter);
errorPrintln(buffer);
dispatchReboot(false);
}
snprintf_P(buffer, sizeof(buffer), PSTR("WIFI: Disconnected from %s (Reason: %d)"), ssid, reason); snprintf_P(buffer, sizeof(buffer), PSTR("WIFI: Disconnected from %s (Reason: %d)"), ssid, reason);
debugPrintln(buffer); debugPrintln(buffer);
WiFi.reconnect();
} }
void wifiSsidConnected(const char * ssid) void wifiSsidConnected(const char * ssid)
@ -87,6 +94,7 @@ void wifiSsidConnected(const char * ssid)
char buffer[128]; char buffer[128];
snprintf_P(buffer, sizeof(buffer), PSTR("WIFI: Connected to SSID %s. Requesting IP..."), ssid); snprintf_P(buffer, sizeof(buffer), PSTR("WIFI: Connected to SSID %s. Requesting IP..."), ssid);
debugPrintln(buffer); debugPrintln(buffer);
wifiReconnectCounter = 0;
} }
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
@ -141,7 +149,7 @@ void wifiSetup(JsonObject settings)
WiFi.mode(WIFI_AP); WiFi.mode(WIFI_AP);
WiFi.softAP(apSsdid.c_str(), buffer); WiFi.softAP(apSsdid.c_str(), buffer);
haspDisplayAP(apSsdid.c_str(), buffer); // haspDisplayAP(apSsdid.c_str(), buffer);
/* Setup the DNS server redirecting all the domains to the apIP */ /* Setup the DNS server redirecting all the domains to the apIP */
// dnsServer.setErrorReplyCode(DNSReplyCode::NoError); // dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
@ -152,7 +160,7 @@ void wifiSetup(JsonObject settings)
debugPrintln(buffer); debugPrintln(buffer);
sprintf_P(buffer, PSTR("WIFI: AP IP address : %s"), IP.toString().c_str()); sprintf_P(buffer, PSTR("WIFI: AP IP address : %s"), IP.toString().c_str());
debugPrintln(buffer); debugPrintln(buffer);
httpReconnect(); // httpReconnect();
} else { } else {
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
@ -177,34 +185,6 @@ void wifiSetup(JsonObject settings)
bool wifiLoop() bool wifiLoop()
{ {
return WiFi.status() == WL_CONNECTED; return WiFi.status() == WL_CONNECTED;
/*
if(WiFi.status() == WL_CONNECTED) {
if(wifiWasConnected) return true;
debugPrintln(F("WIFI: Reconnected"));
wifiWasConnected = true;
wifiReconnectAttempt = 1;
wifiPrevMillis = millis();
haspOnline();
return true;
} else if(millis() - wifiPrevMillis > 1000) {
if(wifiReconnectAttempt < 20) {
if(wifiReconnectAttempt == 1) { // <0 means we were never connected yet
// haspOffline();
warningPrintln(String(F("WIFI: %sConnection lost. Reconnecting... #")) +
String(wifiReconnectAttempt)); WiFi.reconnect(); } else { debugPrintln(F("WIFI: Waiting for connection..."));
}
} else {
// haspOffline();
debugPrintln(F("WIFI: Connection lost. Reconnecting..."));
WiFi.reconnect();
}
wifiReconnectAttempt++;
wifiPrevMillis = millis();
}
return false;*/
} }
bool wifiGetConfig(const JsonObject & settings) bool wifiGetConfig(const JsonObject & settings)

View File

@ -4,8 +4,8 @@
#include "ArduinoJson.h" #include "ArduinoJson.h"
void wifiSetup(JsonObject settings); void wifiSetup(JsonObject settings);
bool wifiLoop(); bool wifiLoop(void);
void wifiStop(); void wifiStop(void);
bool wifiGetConfig(const JsonObject & settings); bool wifiGetConfig(const JsonObject & settings);
bool wifiSetConfig(const JsonObject & settings); bool wifiSetConfig(const JsonObject & settings);

View File

@ -49,6 +49,7 @@
#endif #endif
bool isConnected; bool isConnected;
uint8_t mainLoopCounter = 0;
void setup() void setup()
{ {
@ -88,15 +89,15 @@ void setup()
wifiSetup(settings[F("wifi")]); wifiSetup(settings[F("wifi")]);
#if HASP_USE_MQTT #if HASP_USE_MQTT
// mqttSetup(settings[F("mqtt")]); mqttSetup(settings[F("mqtt")]);
#endif #endif
#if HASP_USE_TELNET #if HASP_USE_TELNET
// telnetSetup(settings[F("telnet")]); telnetSetup(settings[F("telnet")]);
#endif #endif
#if HASP_USE_MDNS #if HASP_USE_MDNS
// mdnsSetup(settings[F("mdns")]); mdnsSetup(settings[F("mdns")]);
#endif #endif
#if HASP_USE_HTTP #if HASP_USE_HTTP
@ -134,27 +135,26 @@ void loop()
/* Network Services Loops */ /* Network Services Loops */
#if HASP_USE_WIFI #if HASP_USE_WIFI
isConnected = wifiLoop(); isConnected = wifiLoop();
#if HASP_USE_MQTT #if HASP_USE_MQTT
mqttLoop(isConnected); mqttLoop(isConnected);
#endif #endif
if(isConnected) {
#if HASP_USE_HTTP #if HASP_USE_HTTP
httpLoop(); httpLoop();
#endif #endif
#if HASP_USE_TELNET #if HASP_USE_TELNET
telnetLoop(); telnetLoop();
#endif #endif
#if HASP_USE_MDNS #if HASP_USE_MDNS
mdnsLoop(); mdnsLoop();
#endif #endif
#if HASP_USE_BUTTON #if HASP_USE_BUTTON
buttonLoop(); buttonLoop();
#endif #endif
}
otaLoop(); otaLoop();
debugLoop(); debugLoop();
@ -162,10 +162,15 @@ void loop()
static unsigned long mainLastLoopTime = 0; static unsigned long mainLastLoopTime = 0;
// Every Secons Loop // Every Second Loop
if(millis() - mainLastLoopTime >= 1000) { if(millis() - mainLastLoopTime >= 1000) {
mainLastLoopTime += 1000; mainLastLoopTime += 1000;
httpEverySecond();
otaEverySecond(); otaEverySecond();
mainLoopCounter++;
if(mainLoopCounter >= 10) {
mainLoopCounter = 0;
}
} }
// delay(1); // delay(1);