mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 12:16:42 +00:00
Update networking
This commit is contained in:
parent
5cdf3ca380
commit
d4b7e3d246
@ -8,6 +8,7 @@
|
|||||||
#include "hasp_conf.h"
|
#include "hasp_conf.h"
|
||||||
#include "hasp_hal.h"
|
#include "hasp_hal.h"
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
|
#include "hasp_network.h"
|
||||||
|
|
||||||
#if HASP_USE_ETHERNET > 0
|
#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());
|
Log.notice(TAG_ETH, F("LINK_SPEED %d Mbps"), ETH.linkSpeed());
|
||||||
eth_connected = true;
|
eth_connected = true;
|
||||||
|
networkStart();// Start network services
|
||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
||||||
Log.notice(TAG_ETH, F("Disconnected"));
|
Log.notice(TAG_ETH, F("Disconnected"));
|
||||||
eth_connected = false;
|
eth_connected = false;
|
||||||
|
networkStop(); // Stop network services
|
||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_ETH_STOP:
|
case SYSTEM_EVENT_ETH_STOP:
|
||||||
Log.notice(TAG_ETH, F("Stopped"));
|
Log.notice(TAG_ETH, F("Stopped"));
|
||||||
|
79
src/hasp_network.cpp
Normal file
79
src/hasp_network.cpp
Normal 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
22
src/hasp_network.h
Normal 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
|
@ -64,13 +64,7 @@ static void wifiConnected(IPAddress ipaddress)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
Log.verbose(TAG_WIFI, F("Connected = %s"), WiFi.status() == WL_CONNECTED ? PSTR("yes") : PSTR("no"));
|
Log.verbose(TAG_WIFI, F("Connected = %s"), WiFi.status() == WL_CONNECTED ? PSTR("yes") : PSTR("no"));
|
||||||
haspProgressVal(255);
|
networkEvent(true);
|
||||||
|
|
||||||
haspReconnect();
|
|
||||||
debugStartSyslog();
|
|
||||||
//mqttStart();
|
|
||||||
httpStart();
|
|
||||||
mdnsStart();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wifiDisconnected(const char * ssid, uint8_t reason)
|
static void wifiDisconnected(const char * ssid, uint8_t reason)
|
||||||
@ -78,12 +72,7 @@ static void wifiDisconnected(const char * ssid, uint8_t reason)
|
|||||||
wifiReconnectCounter++;
|
wifiReconnectCounter++;
|
||||||
|
|
||||||
haspProgressVal(wifiReconnectCounter * 3);
|
haspProgressVal(wifiReconnectCounter * 3);
|
||||||
haspProgressMsg(F("Wifi Disconnected"));
|
networkEvent(false);
|
||||||
|
|
||||||
debugStopSyslog();
|
|
||||||
mqttStop();
|
|
||||||
httpStop();
|
|
||||||
mdnsStop();
|
|
||||||
|
|
||||||
if(wifiReconnectCounter > 33) {
|
if(wifiReconnectCounter > 33) {
|
||||||
Log.error(TAG_WIFI, F("Retries exceed %u: Rebooting..."), wifiReconnectCounter);
|
Log.error(TAG_WIFI, F("Retries exceed %u: Rebooting..."), wifiReconnectCounter);
|
||||||
|
25
src/main.cpp
25
src/main.cpp
@ -11,6 +11,7 @@
|
|||||||
#include "hasp_gui.h"
|
#include "hasp_gui.h"
|
||||||
#include "hasp_oobe.h"
|
#include "hasp_oobe.h"
|
||||||
#include "hasp_dispatch.h"
|
#include "hasp_dispatch.h"
|
||||||
|
#include "hasp_network.h"
|
||||||
#include "hasp.h"
|
#include "hasp.h"
|
||||||
|
|
||||||
bool isConnected;
|
bool isConnected;
|
||||||
@ -27,17 +28,17 @@ void setup()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
// #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
// filesystemSetup(); // Done in configSetup()
|
// filesystemSetup(); // FS mount is done in configSetup()
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
#if HASP_USE_SDCARD > 0
|
// #if HASP_USE_SDCARD > 0
|
||||||
sdcardSetup();
|
// sdcardSetup();
|
||||||
#endif
|
// #endif
|
||||||
|
|
||||||
/****************************
|
/****************************
|
||||||
* Read & Apply User Configuration
|
* Read & Apply User Configuration
|
||||||
***************************/
|
***************************/
|
||||||
configSetup();
|
configSetup(); // also runs debugPreSetup(), debugSetup() and debugStart()
|
||||||
|
|
||||||
dispatchSetup();
|
dispatchSetup();
|
||||||
|
|
||||||
@ -45,19 +46,15 @@ void setup()
|
|||||||
* Apply User Configuration
|
* Apply User Configuration
|
||||||
***************************/
|
***************************/
|
||||||
|
|
||||||
#if HASP_USE_ETHERNET > 0
|
|
||||||
ethernetSetup();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HASP_USE_MQTT > 0
|
#if HASP_USE_MQTT > 0
|
||||||
mqttSetup(); // Load Hostname before starting WiFi
|
mqttSetup(); // Load Hostname before starting WiFi
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HASP_USE_WIFI > 0
|
#if HASP_USE_WIFI > 0 || HASP_USE_ETHERNET > 0
|
||||||
wifiSetup();
|
networkSetup();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
debugSetup();
|
// debugSetup();
|
||||||
|
|
||||||
guiSetup();
|
guiSetup();
|
||||||
if(!oobeSetup()) {
|
if(!oobeSetup()) {
|
||||||
@ -155,11 +152,11 @@ void loop()
|
|||||||
/* Timer Loop */
|
/* Timer Loop */
|
||||||
if(millis() - mainLastLoopTime >= 1000) {
|
if(millis() - mainLastLoopTime >= 1000) {
|
||||||
/* Runs Every Second */
|
/* Runs Every Second */
|
||||||
|
guiEverySecond(); // sleep timer
|
||||||
|
debugEverySecond(); // statusupdate
|
||||||
#if HASP_USE_OTA > 0
|
#if HASP_USE_OTA > 0
|
||||||
otaEverySecond(); // progressbar
|
otaEverySecond(); // progressbar
|
||||||
#endif
|
#endif
|
||||||
guiEverySecond(); // sleep timer
|
|
||||||
debugEverySecond(); // statusupdate
|
|
||||||
|
|
||||||
/* Runs Every 5 Seconds */
|
/* Runs Every 5 Seconds */
|
||||||
if(mainLoopCounter == 0 || mainLoopCounter == 5) {
|
if(mainLoopCounter == 0 || mainLoopCounter == 5) {
|
||||||
|
@ -6,16 +6,16 @@
|
|||||||
; - xpt2606 touch controller ;
|
; - xpt2606 touch controller ;
|
||||||
;***************************************************;
|
;***************************************************;
|
||||||
|
|
||||||
[env:ttgo_esp32-lolintft24]
|
[env:ttgo_esp32_poe-lolintft24]
|
||||||
platform = espressif32@^2.0.0
|
platform = espressif32@^2.0.0
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
upload_protocol = espota ; Use ArduinoOTA after flashing over serial
|
;upload_protocol = espota ; Use ArduinoOTA after flashing over serial
|
||||||
upload_port = 10.4.70.37 ; 10.4.0.198 ; IP of the ESP
|
;upload_port = 10.4.70.37 ; 10.4.0.198 ; IP of the ESP
|
||||||
upload_flags =
|
;upload_flags =
|
||||||
--port=3232
|
; --port=3232
|
||||||
|
|
||||||
;upload_port = COM9 ; To change the port, use platform_override.ini
|
;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
|
monitor_filters = esp32_exception_decoder
|
||||||
board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv
|
board_build.partitions = user_setups/esp32_partition_app1300k_spiffs1216k.csv
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user