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]
platform = espressif8266@2.3.2
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_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
board_build.f_flash = 40000000L
board_build.flash_mode = dout

View File

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

View File

@ -1,6 +1,7 @@
//#include "webServer.h"
#include <Arduino.h>
#include "Arduino.h"
#include "ArduinoJson.h"
//#include "Update.h"
#include "lvgl.h"
#include "hasp_conf.h"
@ -241,7 +242,7 @@ void webHandleScreenshot()
if(!httpIsAuthenticated(F("screenshot"))) return;
if(webServer.hasArg(F("q"))) {
webServer.setContentLength(138 + 320 * 240 * 4);
webServer.setContentLength(122 + 320 * 240 * 2);
webServer.send(200, PSTR("image/bmp"), "");
guiTakeScreenshot(webServer);
@ -336,7 +337,7 @@ void webHandleInfo()
/* HASP Stats */
httpMessage += F("<b>HASP Version: </b>");
httpMessage += String(haspGetVersion());
httpMessage += F("<b>Build DateTime: </b>");
httpMessage += F("<br/><b>Build DateTime: </b>");
httpMessage += __DATE__;
httpMessage += F(" ");
httpMessage += __TIME__;
@ -385,7 +386,7 @@ void webHandleInfo()
// +String(mqttClient.returnCode());
}
httpMessage += F("<br/><b>MQTT ClientID: </b>");
// +String(mqttClientId);
httpMessage += nodename;
/* ESP Stats */
httpMessage += F("</p/><p><b>ESP Chip Id: </b>");
@ -504,6 +505,33 @@ bool handleFileRead(String path)
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()
{
if(webServer.uri() != "/edit") {

View File

@ -41,6 +41,13 @@ void mdnsStart()
MDNS.addService(F("http"), F("tcp"), 80);
MDNS.addService(F("telnet"), F("tcp"), 23);
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 {
errorPrintln(String(F("MDNS: %sResponder failed to start ")) + hasp2Node);
};

View File

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

View File

@ -10,6 +10,7 @@
#include "hasp_log.h"
#include "hasp_debug.h"
#include "hasp_config.h"
#include "hasp_dispatch.h"
#include "hasp_gui.h"
#include "hasp.h"
@ -37,6 +38,7 @@ char wifiPassword[32] = WIFI_PASSW;
#else
char wifiPassword[32] = "";
#endif
uint8_t wifiReconnectCounter = 0;
// const byte DNS_PORT = 53;
// DNSServer dnsServer;
@ -67,19 +69,24 @@ void wifiConnected(IPAddress ipaddress)
debugPrintln(buffer);
if(isConnected) {
mqttReconnect();
haspReconnect();
/* mqttReconnect();
haspReconnect();*/
httpReconnect();
mdnsStart();
// mdnsStart();
}
}
void wifiDisconnected(const char * ssid, uint8_t reason)
{
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);
debugPrintln(buffer);
WiFi.reconnect();
}
void wifiSsidConnected(const char * ssid)
@ -87,6 +94,7 @@ void wifiSsidConnected(const char * ssid)
char buffer[128];
snprintf_P(buffer, sizeof(buffer), PSTR("WIFI: Connected to SSID %s. Requesting IP..."), ssid);
debugPrintln(buffer);
wifiReconnectCounter = 0;
}
#if defined(ARDUINO_ARCH_ESP32)
@ -141,7 +149,7 @@ void wifiSetup(JsonObject settings)
WiFi.mode(WIFI_AP);
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 */
// dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
@ -152,7 +160,7 @@ void wifiSetup(JsonObject settings)
debugPrintln(buffer);
sprintf_P(buffer, PSTR("WIFI: AP IP address : %s"), IP.toString().c_str());
debugPrintln(buffer);
httpReconnect();
// httpReconnect();
} else {
WiFi.mode(WIFI_STA);
@ -177,34 +185,6 @@ void wifiSetup(JsonObject settings)
bool wifiLoop()
{
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)

View File

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

View File

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