Update networking

This commit is contained in:
fvanroie 2020-11-22 19:40:46 +01:00
parent 5cdf3ca380
commit d4b7e3d246
6 changed files with 123 additions and 33 deletions

View File

@ -8,6 +8,7 @@
#include "hasp_conf.h"
#include "hasp_hal.h"
#include "hasp_debug.h"
#include "hasp_network.h"
#if HASP_USE_ETHERNET > 0
@ -34,10 +35,12 @@ void EthernetEvent(WiFiEvent_t event)
}
Log.notice(TAG_ETH, F("LINK_SPEED %d Mbps"), ETH.linkSpeed());
eth_connected = true;
networkStart();// Start network services
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
Log.notice(TAG_ETH, F("Disconnected"));
eth_connected = false;
networkStop(); // Stop network services
break;
case SYSTEM_EVENT_ETH_STOP:
Log.notice(TAG_ETH, F("Stopped"));

79
src/hasp_network.cpp Normal file
View File

@ -0,0 +1,79 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#include <Arduino.h>
#include "ArduinoLog.h"
#include "hasp_conf.h"
#include "hasp_hal.h"
#include "hasp_debug.h"
#include "hasp.h"
#if HASP_USE_ETHERNET > 0 || HASP_USE_WIFI > 0
void networkStart(void)
{
haspProgressVal(255); // hide
haspReconnect();
debugStartSyslog();
// mqttStart();
httpStart();
mdnsStart();
}
void networkStop(void)
{
haspProgressMsg(F("Network Disconnected"));
debugStopSyslog();
mqttStop();
httpStop();
mdnsStop();
}
void networkSetup()
{
#if HASP_USE_ETHERNET > 0
ethernetSetup();
#endif
#if HASP_USE_WIFI > 0
wifiSetup();
#endif
}
void networkLoop(void)
{
#if HASP_USE_ETHERNET > 0
ethernetSetup();
#endif
#if HASP_USE_WIFI > 0
wifiSetup();
#endif
}
bool networkEvery5Seconds(void)
{
#if HASP_USE_ETHERNET > 0
ethernetEvery5Seconds();
#endif
#if HASP_USE_WIFI > 0
wifiEvery5Seconds();
#endif
}
bool networkEverySecond(void)
{
#if HASP_USE_ETHERNET > 0
// ethernetEverySecond();
#endif
#if HASP_USE_WIFI > 0
return wifiEverySecond();
#endif
}
#endif

22
src/hasp_network.h Normal file
View File

@ -0,0 +1,22 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_NETWORK_H
#define HASP_NETWORK_H
/* ===== Default Event Processors ===== */
void networkSetup();
void networkLoop(void);
void networkEvery5Seconds(void);
void networkEverySecond(void);
void networkStart(void);
void networkStop(void);
/* ===== Special Event Processors ===== */
/* ===== Getter and Setter Functions ===== */
/* ===== Read/Write Configuration ===== */
#endif

View File

@ -64,13 +64,7 @@ static void wifiConnected(IPAddress ipaddress)
#endif
Log.verbose(TAG_WIFI, F("Connected = %s"), WiFi.status() == WL_CONNECTED ? PSTR("yes") : PSTR("no"));
haspProgressVal(255);
haspReconnect();
debugStartSyslog();
//mqttStart();
httpStart();
mdnsStart();
networkEvent(true);
}
static void wifiDisconnected(const char * ssid, uint8_t reason)
@ -78,12 +72,7 @@ static void wifiDisconnected(const char * ssid, uint8_t reason)
wifiReconnectCounter++;
haspProgressVal(wifiReconnectCounter * 3);
haspProgressMsg(F("Wifi Disconnected"));
debugStopSyslog();
mqttStop();
httpStop();
mdnsStop();
networkEvent(false);
if(wifiReconnectCounter > 33) {
Log.error(TAG_WIFI, F("Retries exceed %u: Rebooting..."), wifiReconnectCounter);

View File

@ -11,6 +11,7 @@
#include "hasp_gui.h"
#include "hasp_oobe.h"
#include "hasp_dispatch.h"
#include "hasp_network.h"
#include "hasp.h"
bool isConnected;
@ -27,17 +28,17 @@ void setup()
#endif
// #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
// filesystemSetup(); // Done in configSetup()
// filesystemSetup(); // FS mount is done in configSetup()
// #endif
#if HASP_USE_SDCARD > 0
sdcardSetup();
#endif
// #if HASP_USE_SDCARD > 0
// sdcardSetup();
// #endif
/****************************
* Read & Apply User Configuration
***************************/
configSetup();
configSetup(); // also runs debugPreSetup(), debugSetup() and debugStart()
dispatchSetup();
@ -45,19 +46,15 @@ void setup()
* Apply User Configuration
***************************/
#if HASP_USE_ETHERNET > 0
ethernetSetup();
#endif
#if HASP_USE_MQTT > 0
mqttSetup(); // Load Hostname before starting WiFi
#endif
#if HASP_USE_WIFI > 0
wifiSetup();
#if HASP_USE_WIFI > 0 || HASP_USE_ETHERNET > 0
networkSetup();
#endif
debugSetup();
// debugSetup();
guiSetup();
if(!oobeSetup()) {
@ -155,11 +152,11 @@ void loop()
/* Timer Loop */
if(millis() - mainLastLoopTime >= 1000) {
/* Runs Every Second */
guiEverySecond(); // sleep timer
debugEverySecond(); // statusupdate
#if HASP_USE_OTA > 0
otaEverySecond(); // progressbar
#endif
guiEverySecond(); // sleep timer
debugEverySecond(); // statusupdate
/* Runs Every 5 Seconds */
if(mainLoopCounter == 0 || mainLoopCounter == 5) {

View File

@ -6,16 +6,16 @@
; - xpt2606 touch controller ;
;***************************************************;
[env:ttgo_esp32-lolintft24]
[env:ttgo_esp32_poe-lolintft24]
platform = espressif32@^2.0.0
board = esp32dev
upload_protocol = espota ; Use ArduinoOTA after flashing over serial
upload_port = 10.4.70.37 ; 10.4.0.198 ; IP of the ESP
upload_flags =
--port=3232
;upload_protocol = espota ; Use ArduinoOTA after flashing over serial
;upload_port = 10.4.70.37 ; 10.4.0.198 ; IP of the ESP
;upload_flags =
; --port=3232
;upload_port = COM9 ; To change the port, use platform_override.ini
monitor_port = COM9 ; To change the port, use platform_override.ini
;monitor_port = COM9 ; To change the port, use platform_override.ini
monitor_filters = esp32_exception_decoder
board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv