diff --git a/lib/ETHSPI/ETHSPI.cpp b/lib/ETHSPI/ETHSPI.cpp new file mode 100644 index 00000000..7bdbe7a5 --- /dev/null +++ b/lib/ETHSPI/ETHSPI.cpp @@ -0,0 +1,341 @@ +/* MIT License - Copyright (c) 2022 Ben Suffolk, ben@vanilla.net + For full license information read the LICENSE file in the project folder */ + +#include "ETHSPI.h" +#include "esp_netif.h" +#include "esp_eth.h" +#include "esp_event.h" +#include "esp_log.h" +#include "driver/gpio.h" +#include "sdkconfig.h" +#include "lwip/err.h" +#include "lwip/dns.h" + +extern void tcpipInit(); + + +ETHSPIClass::ETHSPIClass() + :initialized(false) + ,staticIP(false) + ,eth_handle(NULL) + ,eth_netif_spi(NULL) +{ +} + +ETHSPIClass::~ETHSPIClass() +{} + + +bool ETHSPIClass::begin(int mosi_io, int miso_io, int sclk_io, int cs_io, int int_io, spi_host_device_t spi_host) +{ + if(initialized) { + return true; + } + + tcpipInit(); + + // Create instance(s) of esp-netif for SPI Ethernet(s) + esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH(); + esp_netif_config.if_key = "ETH_SPI_0"; + esp_netif_config.if_desc = "eth0"; + esp_netif_config.route_prio = 30; + + esp_netif_config_t cfg_spi = { + .base = &esp_netif_config, + .stack = ESP_NETIF_NETSTACK_DEFAULT_ETH + }; + + eth_netif_spi = esp_netif_new(&cfg_spi); + + + // Init MAC and PHY configs to default + eth_mac_config_t mac_config_spi = ETH_MAC_DEFAULT_CONFIG(); + eth_phy_config_t phy_config_spi = ETH_PHY_DEFAULT_CONFIG(); + + // Install GPIO ISR handler to be able to service SPI Eth modlues interrupts + gpio_install_isr_service(0); + + // Init SPI bus + spi_device_handle_t spi_handle = NULL; + spi_bus_config_t buscfg = { + .mosi_io_num = mosi_io, + .miso_io_num = miso_io, + .sclk_io_num = sclk_io, + .quadwp_io_num = -1, + .quadhd_io_num = -1, + }; + + if(spi_bus_initialize(ETHSPI_HOST, &buscfg, SPI_DMA_CH_AUTO) != ESP_OK) { + return false; + } + + // Configure SPI interface and Ethernet driver for specific SPI module + esp_eth_mac_t *mac_spi; + esp_eth_phy_t *phy_spi; + + spi_device_interface_config_t devcfg = { + .command_bits = 16, // Actually it's the address phase in W5500 SPI frame + .address_bits = 8, // Actually it's the control phase in W5500 SPI frame + .mode = 0, + .clock_speed_hz = ETHSPI_CLOCK_MHZ * 1000 * 1000, + .queue_size = 20 + }; + + // Set SPI module Chip Select GPIO + devcfg.spics_io_num = cs_io; + + if(spi_bus_add_device(spi_host, &devcfg, &spi_handle) != ESP_OK) { + return false; + } + + // w5500 ethernet driver is based on spi driver + eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(spi_handle); + + // Set remaining GPIO numbers and configuration used by the SPI module + w5500_config.int_gpio_num = int_io; + phy_config_spi.phy_addr = 1; + phy_config_spi.reset_gpio_num = -1; + + mac_spi = esp_eth_mac_new_w5500(&w5500_config, &mac_config_spi); + phy_spi = esp_eth_phy_new_w5500(&phy_config_spi); + + esp_eth_config_t eth_config_spi = ETH_DEFAULT_CONFIG(mac_spi, phy_spi); + + if(esp_eth_driver_install(ð_config_spi, ð_handle) != ESP_OK) { + return false; + } + + // W5500 Does not have a mac address on the module. So get the ESP base address (WiFi) + uint8_t mac[6]; + esp_efuse_mac_get_default(mac); + if(esp_eth_ioctl(eth_handle, ETH_CMD_S_MAC_ADDR, mac) != ESP_OK) { + return false; + } + + // attach Ethernet driver to TCP/IP stack + if(esp_netif_attach(eth_netif_spi, esp_eth_new_netif_glue(eth_handle)) != ESP_OK) { + return false; + } + + if(esp_eth_start(eth_handle) != ESP_OK) { + return false; + } + + initialized = true; + + return initialized; +} + + +bool ETHSPIClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2) +{ + esp_netif_ip_info_t ip_info; + + if(local_ip != (uint32_t)0x00000000 && local_ip != INADDR_NONE) { + ip_info.ip.addr = static_cast(local_ip); + ip_info.gw.addr = static_cast(gateway); + ip_info.netmask.addr = static_cast(subnet); + } else { + ip_info.ip.addr = 0; + ip_info.gw.addr = 0; + ip_info.netmask.addr = 0; + } + + // Stop DHCP client + esp_netif_dhcp_status_t status; + if(esp_netif_dhcpc_get_status(eth_netif_spi, &status) != ESP_OK) { + log_e("could not get DHCP status"); + return false; + } + + if(status == ESP_NETIF_DHCP_STARTED && esp_netif_dhcpc_stop(eth_netif_spi) != ESP_OK) { + log_e("DHCP could not be stopped"); + return false; + } + + // Set IP Details + if(esp_netif_set_ip_info(eth_netif_spi, &ip_info) != ESP_OK) { + log_e("Unable to set IP address"); + return false; + } + + + // Start DHCP client is required + if(ip_info.ip.addr){ + staticIP = true; + } else { + + if(esp_netif_dhcpc_start(eth_netif_spi) != ESP_OK) { + log_e("DHCP could not be started"); + return false; + } + + staticIP = false; + } + + + // Set primary DNS + if(dns1 != (uint32_t)0x00000000 && dns1 != INADDR_NONE) { + + esp_netif_dns_info_t dns_info; + dns_info.ip.u_addr.ip4.addr = static_cast(dns1); + + if(esp_netif_set_dns_info(eth_netif_spi, ESP_NETIF_DNS_MAIN, &dns_info) != ESP_OK) { + log_e("Unable to set DNS"); + return false; + } + } + + // Set secondary DNS + if(dns2 != (uint32_t)0x00000000 && dns2 != INADDR_NONE) { + + esp_netif_dns_info_t dns_info; + dns_info.ip.u_addr.ip4.addr = static_cast(dns2); + + if(esp_netif_set_dns_info(eth_netif_spi, ESP_NETIF_DNS_FALLBACK, &dns_info) != ESP_OK) { + log_e("Unable to set DNS"); + return false; + } + } + + return true; +} + +IPAddress ETHSPIClass::localIP() +{ + esp_netif_ip_info_t ip_info; + + if(esp_netif_get_ip_info(eth_netif_spi, &ip_info) != ESP_OK) { + return IPAddress(); + } + + return IPAddress(ip_info.ip.addr); +} + +IPAddress ETHSPIClass::subnetMask() +{ + esp_netif_ip_info_t ip_info; + + if(esp_netif_get_ip_info(eth_netif_spi, &ip_info) != ESP_OK) { + return IPAddress(); + } + + return IPAddress(ip_info.netmask.addr); +} + +IPAddress ETHSPIClass::gatewayIP() +{ + esp_netif_ip_info_t ip_info; + + if(esp_netif_get_ip_info(eth_netif_spi, &ip_info) != ESP_OK) { + return IPAddress(); + } + + return IPAddress(ip_info.gw.addr); +} + +IPAddress ETHSPIClass::dnsIP(esp_netif_dns_type_t dns_type) +{ + esp_netif_dns_info_t dns_info; + + if(esp_netif_get_dns_info(eth_netif_spi, dns_type, &dns_info) != ESP_OK) { + return IPAddress(); + } + + return IPAddress(dns_info.ip.u_addr.ip4.addr); +} + +IPAddress ETHSPIClass::broadcastIP() +{ + esp_netif_ip_info_t ip_info; + + if(esp_netif_get_ip_info(eth_netif_spi, &ip_info) != ESP_OK) { + return IPAddress(); + } + + return WiFiGenericClass::calculateBroadcast(IPAddress(ip_info.gw.addr), IPAddress(ip_info.netmask.addr)); +} + +IPAddress ETHSPIClass::networkID() +{ + esp_netif_ip_info_t ip_info; + + if(esp_netif_get_ip_info(eth_netif_spi, &ip_info) != ESP_OK) { + return IPAddress(); + } + + return WiFiGenericClass::calculateNetworkID(IPAddress(ip_info.gw.addr), IPAddress(ip_info.netmask.addr)); +} + +uint8_t ETHSPIClass::subnetCIDR() +{ + esp_netif_ip_info_t ip_info; + + if(esp_netif_get_ip_info(eth_netif_spi, &ip_info) != ESP_OK) { + return IPAddress(); + } + + return WiFiGenericClass::calculateSubnetCIDR(IPAddress(ip_info.netmask.addr)); +} + +const char * ETHSPIClass::getHostname() +{ + const char *hostname; + + if(esp_netif_get_hostname(eth_netif_spi, &hostname) != ESP_OK) { + return NULL; + } + + return hostname; +} + +bool ETHSPIClass::setHostname(const char *hostname) +{ + return(esp_netif_set_hostname(eth_netif_spi, hostname) == ESP_OK); +} + +bool ETHSPIClass::fullDuplex() +{ + eth_duplex_t duplex; + + esp_eth_ioctl(eth_handle, ETH_CMD_G_DUPLEX_MODE, &duplex); + return (duplex == ETH_DUPLEX_FULL); +} + +bool ETHSPIClass::linkUp() +{ + return esp_netif_is_netif_up(eth_netif_spi); +} + + +uint8_t ETHSPIClass::linkSpeed() +{ + eth_speed_t link_speed; + esp_eth_ioctl(eth_handle, ETH_CMD_G_SPEED, &link_speed); + return (link_speed == ETH_SPEED_10M)?10:100; +} + + +uint8_t * ETHSPIClass::macAddress(uint8_t* mac) +{ + if(!mac) { + return NULL; + } + + esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac); + + return mac; +} + +String ETHSPIClass::macAddress(void) +{ + uint8_t mac[6]; + char macStr[18]; + + macAddress(mac); + + sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + return String(macStr); +} + +ETHSPIClass ETHSPI; diff --git a/lib/ETHSPI/ETHSPI.h b/lib/ETHSPI/ETHSPI.h new file mode 100644 index 00000000..d448b587 --- /dev/null +++ b/lib/ETHSPI/ETHSPI.h @@ -0,0 +1,80 @@ +/* MIT License - Copyright (c) 2022 Ben Suffolk, ben@vanilla.net + For full license information read the LICENSE file in the project folder */ + +#ifndef _ETHSPI_H_ +#define _ETHSPI_H_ + +#include "WiFi.h" +#include "esp_system.h" +#include "esp_eth.h" +#include "driver/spi_master.h" + +#ifndef ETHSPI_HOST +#define ETHSPI_HOST VSPI_HOST +#endif + +#ifndef ETHSPI_CLOCK_MHZ +#define ETHSPI_CLOCK_MHZ 12 +#endif + +#ifndef ETHSPI_INT_GPIO +#define ETHSPI_INT_GPIO 4 +#endif + +#ifndef ETHSPI_MOSI_GPIO +#define ETHSPI_MOSI_GPIO 13 +#endif + +#ifndef ETHSPI_MISO_GPIO +#define ETHSPI_MISO_GPIO 12 +#endif + +#ifndef ETHSPI_SCLK_GPIO +#define ETHSPI_SCLK_GPIO 14 +#endif + +#ifndef ETHSPI_CS_GPIO +#define ETHSPI_CS_GPIO 15 +#endif + +class ETHSPIClass { + private: + bool initialized; + bool staticIP; + esp_eth_handle_t eth_handle; + esp_netif_t *eth_netif_spi; + + public: + ETHSPIClass(); + ~ETHSPIClass(); + + bool begin(int mosi_io = ETHSPI_MOSI_GPIO, int miso_io = ETHSPI_MISO_GPIO, int sclk_io = ETHSPI_SCLK_GPIO, int cs_io = ETHSPI_CS_GPIO, int int_io = ETHSPI_INT_GPIO, spi_host_device_t spi_host = ETHSPI_HOST); + + bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000); + + const char * getHostname(); + bool setHostname(const char * hostname); + + bool fullDuplex(); + bool linkUp(); + uint8_t linkSpeed(); + + IPAddress localIP(); + IPAddress subnetMask(); + IPAddress gatewayIP(); + IPAddress dnsIP(esp_netif_dns_type_t dns_type = ESP_NETIF_DNS_MAIN); + + IPAddress broadcastIP(); + IPAddress networkID(); + uint8_t subnetCIDR(); + + uint8_t * macAddress(uint8_t* mac); + String macAddress(); + + friend class WiFiClient; + friend class WiFiServer; +}; + +extern ETHSPIClass ETHSPI; + +#endif /* _ETH_H_ */ diff --git a/src/hasp_oobe.cpp b/src/hasp_oobe.cpp index b7031983..86b2496b 100644 --- a/src/hasp_oobe.cpp +++ b/src/hasp_oobe.cpp @@ -303,9 +303,6 @@ void oobeSetAutoCalibrate(bool cal) bool oobeSetup() { -#if HASP_USE_ETHERNET > 0 - if(eth_connected) return false; -#endif #if HASP_USE_WIFI > 0 char ssid[32]; char pass[32]; @@ -357,4 +354,4 @@ void oobeFakeSetup(const char*, const char*, uint8_t source) } #endif } -#endif // HASP_USE_CONFIG \ No newline at end of file +#endif // HASP_USE_CONFIG diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp index 559a6b56..109947a7 100644 --- a/src/main_arduino.cpp +++ b/src/main_arduino.cpp @@ -120,7 +120,9 @@ void setup() delay(20); if(!oobe) { dispatch_exec(NULL, "L:/boot.cmd", TAG_HASP); +#if HASP_USE_WIFI > 0 wifi_run_scripts(); +#endif } mainLastLoopTime = -1000; // reset loop counter } @@ -129,8 +131,8 @@ IRAM_ATTR void loop() { guiLoop(); -#if HASP_USE_WIFI > 0 || HASP_USE_EHTERNET > 0 - networkLoop(); +#if HASP_USE_WIFI > 0 || HASP_USE_ETHERNET > 0 + networkLoop(); #endif #if HASP_USE_GPIO > 0 @@ -198,7 +200,7 @@ IRAM_ATTR void loop() break; case 4: -#if HASP_USE_WIFI > 0 || HASP_USE_EHTERNET > 0 +#if HASP_USE_WIFI > 0 || HASP_USE_ETHERNET > 0 isConnected = networkEvery5Seconds(); // Check connection #if HASP_USE_MQTT > 0 diff --git a/src/sys/net/hasp_ethernet_esp32.cpp b/src/sys/net/hasp_ethernet_esp32.cpp index 3b872d9d..f7f14a5f 100644 --- a/src/sys/net/hasp_ethernet_esp32.cpp +++ b/src/sys/net/hasp_ethernet_esp32.cpp @@ -8,7 +8,7 @@ #include "hal/hasp_hal.h" #include "dev/device.h" -#if HASP_USE_ETHERNET > 0 && defined(ARDUINO_ARCH_ESP32) +#if HASP_USE_ETHERNET > 0 && defined(ARDUINO_ARCH_ESP32) && HASP_USE_SPI_ETHERNET == 0 IPAddress ip; diff --git a/src/sys/net/hasp_ethernet_spi.cpp b/src/sys/net/hasp_ethernet_spi.cpp new file mode 100644 index 00000000..4d8fbd5f --- /dev/null +++ b/src/sys/net/hasp_ethernet_spi.cpp @@ -0,0 +1,108 @@ +/* MIT License - Copyright (c) 2022 Ben Suffolk, ben@vanilla.net + For full license information read the LICENSE file in the project folder */ + + +#include "hasp_conf.h" +#include "hasp_debug.h" +#include "hasp_network.h" + +#include "hal/hasp_hal.h" +#include "dev/device.h" + +#if HASP_USE_ETHERNET > 0 && defined(ARDUINO_ARCH_ESP32) && HASP_USE_SPI_ETHERNET > 0 + +static bool eth_connected = false; + +void EthernetEvent(WiFiEvent_t event) +{ + IPAddress ip; + switch(event) { + case ARDUINO_EVENT_ETH_START: + LOG_TRACE(TAG_ETH, F(D_SERVICE_STARTED)); + // set eth hostname here + ETHSPI.setHostname(haspDevice.get_hostname()); + break; + case ARDUINO_EVENT_ETH_CONNECTED: + LOG_TRACE(TAG_ETH, F(D_SERVICE_CONNECTED)); + eth_connected = true; + break; + case ARDUINO_EVENT_ETH_GOT_IP: + LOG_TRACE(TAG_ETH, F(D_INFO_MAC_ADDRESS " %s"), ETHSPI.macAddress().c_str()); + ip = ETHSPI.localIP(); + LOG_TRACE(TAG_ETH, F("IPv4: %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); + if(ETHSPI.fullDuplex()) { + LOG_TRACE(TAG_ETH, F(D_INFO_FULL_DUPLEX)); + } + LOG_TRACE(TAG_ETH, F(D_INFO_LINK_SPEED " %d Mbps"), ETHSPI.linkSpeed()); + eth_connected = true; + networkStart(); // Start network services + break; + case ARDUINO_EVENT_ETH_DISCONNECTED: + LOG_TRACE(TAG_ETH, F(D_SERVICE_DISCONNECTED)); + eth_connected = false; + networkStop(); // Stop network services + break; + case ARDUINO_EVENT_ETH_STOP: + LOG_WARNING(TAG_ETH, F(D_SERVICE_STOPPED)); + eth_connected = false; + break; + default: + break; + } +} + +void ethernetSetup() +{ + LOG_TRACE(TAG_ETH, F("ethernetSetup()")); + +#if HASP_USE_WIFI == 0 + // Need to make sure we get the Ethernet Events + WiFi.begin(); + WiFi.mode(WIFI_OFF); +#endif + + WiFi.onEvent(EthernetEvent); + bool started = ETHSPI.begin(); + + if(started) + LOG_TRACE(TAG_ETH, F("ETHSPI Started ")); +} + +IRAM_ATTR void ethernetLoop(void) +{} + +bool ethernetEvery5Seconds() +{ + return eth_connected; +} + +void ethernet_get_statusupdate(char* buffer, size_t len) +{ + snprintf_P(buffer, len, PSTR("\"eth\":\"%s\",\"link\":\"%d Mbps\",\"ip\":\"%s\",\"mac\":\"%s\","), + eth_connected ? F("on") : F("off"), ETHSPI.linkSpeed(), ETHSPI.localIP().toString().c_str(), + ETHSPI.macAddress().c_str()); +} + +void ethernet_get_info(JsonDocument& doc) +{ + char size_buf[32]; + String buffer((char*)0); + buffer.reserve(64); + + JsonObject info = doc.createNestedObject(F(D_INFO_ETHERNET)); + + buffer = ETHSPI.linkSpeed(); + buffer += F(" Mbps"); + if(ETHSPI.fullDuplex()) { + buffer += F(" " D_INFO_FULL_DUPLEX); + } + + info[F(D_INFO_LINK_SPEED)] = buffer; + info[F(D_INFO_IP_ADDRESS)] = ETHSPI.localIP().toString(); + info[F(D_INFO_GATEWAY)] = ETHSPI.gatewayIP().toString(); + info[F(D_INFO_DNS_SERVER)] = ETHSPI.dnsIP().toString(); + info[F(D_INFO_MAC_ADDRESS)] = ETHSPI.macAddress(); +} + +#endif + diff --git a/src/sys/net/hasp_ethernet_spi.h b/src/sys/net/hasp_ethernet_spi.h new file mode 100644 index 00000000..472def7d --- /dev/null +++ b/src/sys/net/hasp_ethernet_spi.h @@ -0,0 +1,18 @@ +/* MIT License - Copyright (c) 2022 Ben Suffolk, ben@vanilla.net + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_ETHERNET_SPI_H +#define HASP_ETHERNET_SPI_H + +#include "ArduinoJson.h" + +void ethernetSetup(); +IRAM_ATTR void ethernetLoop(void); + +bool ethernetEverySecond(); +bool ethernetEvery5Seconds(); +void ethernet_get_statusupdate(char* buffer, size_t len); + +void ethernet_get_info(JsonDocument& doc); + +#endif diff --git a/src/sys/net/hasp_network.cpp b/src/sys/net/hasp_network.cpp index e17670c2..56e5b286 100644 --- a/src/sys/net/hasp_network.cpp +++ b/src/sys/net/hasp_network.cpp @@ -8,6 +8,8 @@ #include "hasp_network.h" #include "sys/svc/hasp_mdns.h" +bool haspOnline = false; + #if HASP_USE_ETHERNET > 0 || HASP_USE_WIFI > 0 void networkStart(void) { @@ -24,6 +26,8 @@ void networkStart(void) #if HASP_USE_MDNS > 0 mdnsStart(); #endif // HASP_USE_MDNS + + dispatch_exec(NULL, "L:/online.cmd", TAG_WIFI); } void networkStop(void) @@ -39,10 +43,14 @@ void networkStop(void) #if HASP_USE_MDNS > 0 mdnsStop(); #endif + + dispatch_exec(NULL, "L:/offline.cmd", TAG_WIFI); } void networkSetup() { + dispatch_exec(NULL, "L:/offline.cmd", TAG_WIFI); + #if HASP_USE_ETHERNET > 0 ethernetSetup(); #endif @@ -90,11 +98,33 @@ IRAM_ATTR void networkLoop(void) bool networkEvery5Seconds(void) { #if HASP_USE_ETHERNET > 0 - return ethernetEvery5Seconds(); + if(ethernetEvery5Seconds() != haspOnline) { + haspOnline = !haspOnline; + LOG_WARNING(TAG_ETH, haspOnline ? F(D_NETWORK_ONLINE) : F(D_NETWORK_OFFLINE)); + + if(haspOnline) { + networkStart(); + } else { + networkStop(); + } + } + + return haspOnline; #endif #if HASP_USE_WIFI > 0 - return wifiEvery5Seconds(); + if(wifiEvery5Seconds() != haspOnline) { + haspOnline = !haspOnline; + LOG_WARNING(TAG_WIFI, haspOnline ? F(D_NETWORK_ONLINE) : F(D_NETWORK_OFFLINE)); + + if(haspOnline) { + networkStart(); + } else { + networkStop(); + } + } + + return haspOnline; #endif return false; @@ -133,7 +163,15 @@ void network_get_statusupdate(char* buffer, size_t len) void network_get_ipaddress(char* buffer, size_t len) { #if HASP_USE_ETHERNET > 0 +#if defined(ARDUINO_ARCH_ESP32) +#if HASP_USE_SPI_ETHERNET > 0 + IPAddress ip = WiFi.localIP(); +#else + IPAddress ip = ETH.localIP(); +#endif +#else IPAddress ip = Ethernet.localIP(); +#endif snprintf_P(buffer, len, PSTR("%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); return; #endif diff --git a/src/sys/net/hasp_wifi.cpp b/src/sys/net/hasp_wifi.cpp index 39a8ba2a..1c5ebacb 100644 --- a/src/sys/net/hasp_wifi.cpp +++ b/src/sys/net/hasp_wifi.cpp @@ -43,7 +43,6 @@ char wifiPassword[MAX_PASSWORD_LENGTH] = WIFI_PASSWORD; char wifiIpAddress[16] = ""; uint16_t wifiReconnectCounter = 0; bool wifiOnline = false; -bool haspOnline = false; bool wifiEnabled = true; // const byte DNS_PORT = 53; @@ -51,19 +50,6 @@ bool wifiEnabled = true; /* ============ Connection Event Handlers =============================================================== */ -void wifi_run_scripts() -{ - if(wifiOnline != haspOnline) { - if(wifiOnline) { - dispatch_exec(NULL, "L:/online.cmd", TAG_WIFI); - networkStart(); - } else { - dispatch_exec(NULL, "L:/offline.cmd", TAG_WIFI); - networkStop(); - } - haspOnline = wifiOnline; - } -} static void wifiConnected(IPAddress ipaddress) { @@ -528,8 +514,6 @@ bool wifiEvery5Seconds() } #endif - if(wifiOnline != haspOnline) wifi_run_scripts(); - if(WiFi.status() == WL_CONNECTED) { return true; } diff --git a/src/sys/net/hasp_wifi.h b/src/sys/net/hasp_wifi.h index abb0cc4d..e5d0269d 100644 --- a/src/sys/net/hasp_wifi.h +++ b/src/sys/net/hasp_wifi.h @@ -24,7 +24,6 @@ void wifi_get_statusupdate(char* buffer, size_t len); void wifi_get_info(JsonDocument& doc); const char* wifi_get_ssid(); const char* wifi_get_ip_address(); -void wifi_run_scripts(); #if HASP_USE_CONFIG > 0 bool wifiGetConfig(const JsonObject& settings); diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 0715447b..92c8c1f1 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -2117,7 +2117,11 @@ void httpStart() #if HASP_USE_ETHERNET > 0 IPAddress ip; #if defined(ARDUINO_ARCH_ESP32) +#if HASP_USE_SPI_ETHERNET > 0 + ip = ETHSPI.localIP(); +#else ip = ETH.localIP(); +#endif #else ip = Ethernet.localIP(); #endif @@ -2212,10 +2216,9 @@ void httpSetup() webHandleFirmwareUpload); #endif -#if HASP_USE_WIFI > 0 - // These two endpoints are needed in STA and AP mode webServer.on(F("/config"), webHandleConfig); +#if HASP_USE_WIFI > 0 #if !defined(STM32F4xx) #if HASP_USE_CONFIG > 0