Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@ web.tar
.platformio
.local
.cache
.history

# macOS
.DS_Store
.DS_Store?
._*
.AppleDouble
.LSOverride
.Spotlight-V100
.Trashes
.fseventsd
.AppleDB
.AppleDesktop

Thumbs.db
.autotools
.built
Expand Down
14 changes: 8 additions & 6 deletions src/DebugConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,16 @@ extern "C" void logLegacy(const char *level, const char *fmt, ...);
// Default Bluetooth PIN
#define defaultBLEPin 123456

#if HAS_ETHERNET && !defined(USE_WS5500)
#include <RAK13800_W5100S.h>
#endif // HAS_ETHERNET

#if HAS_ETHERNET && defined(USE_WS5500)
#if HAS_ETHERNET
#if defined(USE_WS5500)
#include <ETHClass2.h>
#define ETH ETH2
#endif // HAS_ETHERNET
#elif defined(ESP32) && defined(ETH_PHY_TYPE)
#include <ETH.h>
#else
#include <RAK13800_W5100S.h>
#endif
#endif

#if HAS_WIFI
#include <WiFi.h>
Expand Down
4 changes: 2 additions & 2 deletions src/PowerFSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "sleep.h"
#include "target_specific.h"

#if HAS_WIFI && !defined(ARCH_PORTDUINO) || defined(MESHTASTIC_EXCLUDE_WIFI)
#if (HAS_WIFI || HAS_ETHERNET_ON_WIFI_STACK) && !defined(ARCH_PORTDUINO) || defined(MESHTASTIC_EXCLUDE_WIFI)
#include "mesh/wifi/WiFiAPClient.h"
#endif

Expand Down Expand Up @@ -376,7 +376,7 @@ void PowerFSM_setup()
// Don't add power saving transitions if we are a power saving tracker or sensor or have Wifi enabled. Sleep will be initiated
// through the modules

#if HAS_WIFI && !defined(MESHTASTIC_EXCLUDE_WIFI)
#if (HAS_WIFI || HAS_ETHERNET_ON_WIFI_STACK) && !defined(MESHTASTIC_EXCLUDE_WIFI)
bool isTrackerOrSensor = config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER ||
config.device.role == meshtastic_Config_DeviceConfig_Role_TAK_TRACKER ||
config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR;
Expand Down
7 changes: 7 additions & 0 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Allow code that needs internet to just check HAS_NETWORKING rather than HAS_WIFI || HAS_ETHERNET
#define HAS_NETWORKING (HAS_WIFI || HAS_ETHERNET)

// ESP32 uses Arduino Wi-Fi stack when using native/WS5500 Ethernet
#if (HAS_ETHERNET && (defined(ETH_PHY_TYPE) || defined(USE_WS5500)))
#define HAS_ETHERNET_ON_WIFI_STACK 1
#else
#define HAS_ETHERNET_ON_WIFI_STACK 0
#endif

// // Turn off Bluetooth
#ifdef MESHTASTIC_EXCLUDE_BLUETOOTH
#undef HAS_BLUETOOTH
Expand Down
6 changes: 4 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ NimbleBluetooth *nimbleBluetooth = nullptr;
NRF52Bluetooth *nrf52Bluetooth = nullptr;
#endif

#if HAS_WIFI || defined(USE_WS5500)
#if HAS_WIFI || HAS_ETHERNET_ON_WIFI_STACK
#include "mesh/api/WiFiServerAPI.h"
#include "mesh/wifi/WiFiAPClient.h"
#endif

#if HAS_ETHERNET && !defined(USE_WS5500)
#if HAS_ETHERNET
#include "mesh/api/ethServerAPI.h"
#if !defined(USE_WS5500) && !defined(ETH_PHY_TYPE)
#include "mesh/eth/ethClient.h"
#endif
#endif

#if !MESHTASTIC_EXCLUDE_MQTT
#include "mqtt/MQTT.h"
Expand Down
9 changes: 6 additions & 3 deletions src/mesh/InterfacesTemplates.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "configuration.h"
#include "LR11x0Interface.cpp"
#include "LR11x0Interface.h"
#include "SX126xInterface.cpp"
Expand Down Expand Up @@ -25,10 +26,12 @@ template class LR11x0Interface<LR1121>;
template class SX126xInterface<STM32WLx>;
#endif

#if HAS_ETHERNET && !defined(USE_WS5500)
#if HAS_ETHERNET
#include "api/ethServerAPI.h"
template class ServerAPI<EthernetClient>;
template class APIServerPort<ethServerAPI, EthernetServer>;
#if !(defined(ESP32) && HAS_WIFI)
template class ServerAPI<MeshEthernetClient>;
#endif
template class APIServerPort<ethServerAPI, MeshEthernetServer>;
#endif

#if HAS_WIFI
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/NodeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <vector>

#ifdef ARCH_ESP32
#if HAS_WIFI
#if HAS_WIFI || HAS_ETHERNET_ON_WIFI_STACK
#include "mesh/wifi/WiFiAPClient.h"
#endif
#include "SPILock.h"
Expand Down
12 changes: 6 additions & 6 deletions src/mesh/api/ethServerAPI.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#include "configuration.h"
#include <Arduino.h>

#if HAS_ETHERNET && !defined(USE_WS5500)

#include "ethServerAPI.h"

#include <Arduino.h>

#if HAS_ETHERNET
#if !HAS_WIFI
static ethServerPort *apiPort;

void initApiServer(int port)
{
// Start API server on port 4403
if (!apiPort) {
apiPort = new ethServerPort(port);
LOG_INFO("API server listening on TCP port %d", port);
apiPort->init();
}
}
#endif

ethServerAPI::ethServerAPI(EthernetClient &_client) : ServerAPI(_client)
ethServerAPI::ethServerAPI(MeshEthernetClient &_client) : ServerAPI(_client)
{
LOG_INFO("Incoming ethernet connection");
api_type = TYPE_ETH;
Expand Down
27 changes: 20 additions & 7 deletions src/mesh/api/ethServerAPI.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
#pragma once

#include "configuration.h"
#include "ServerAPI.h"
#ifndef USE_WS5500

#if HAS_ETHERNET
#if defined(ESP32) && HAS_ETHERNET_ON_WIFI_STACK
#if defined(ETH_PHY_TYPE)
#include <ETH.h>
#else
#include <ETHClass2.h>
#endif
typedef WiFiClient MeshEthernetClient;
typedef WiFiServer MeshEthernetServer;
#else
#include <RAK13800_W5100S.h>
typedef EthernetClient MeshEthernetClient;
typedef EthernetServer MeshEthernetServer;
#endif

/**
* Provides both debug printing and, if the client starts sending protobufs to us, switches to send/receive protobufs
* (and starts dropping debug printing - FIXME, eventually those prints should be encapsulated in protobufs).
*/
class ethServerAPI : public ServerAPI<EthernetClient>
class ethServerAPI : public ServerAPI<MeshEthernetClient>
{
public:
explicit ethServerAPI(EthernetClient &_client);
explicit ethServerAPI(MeshEthernetClient &_client);
};

/**
* Listens for incoming connections and does accepts and creates instances of EthernetServerAPI as needed
*/
class ethServerPort : public APIServerPort<ethServerAPI, EthernetServer>
class ethServerPort : public APIServerPort<ethServerAPI, MeshEthernetServer>
{
public:
explicit ethServerPort(int port);
};

void initApiServer(int port = SERVER_API_DEFAULT_PORT);
#endif
void initApiServer(int port);
#endif
4 changes: 2 additions & 2 deletions src/mesh/eth/ethClient.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "configuration.h"
#include "mesh/eth/ethClient.h"
#include "NodeDB.h"
#include "RTC.h"
#include "concurrency/Periodic.h"
#include "configuration.h"
#include "main.h"
#include "mesh/api/ethServerAPI.h"
#include "target_specific.h"
Expand Down Expand Up @@ -65,7 +65,7 @@ static int32_t reconnectETH()

#if !MESHTASTIC_EXCLUDE_SOCKETAPI
if (config.display.displaymode != meshtastic_Config_DisplayConfig_DisplayMode_COLOR) {
initApiServer();
initApiServer(SERVER_API_DEFAULT_PORT);
}
#endif
#if HAS_UDP_MULTICAST
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/http/ContentHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "main.h"
#include "mesh/http/ContentHelper.h"
#include "mesh/http/WebServer.h"
#if HAS_WIFI
#if HAS_WIFI || HAS_ETHERNET_ON_WIFI_STACK
#include "mesh/wifi/WiFiAPClient.h"
#endif
#include "SPILock.h"
Expand Down
48 changes: 31 additions & 17 deletions src/mesh/wifi/WiFiAPClient.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "configuration.h"
#if HAS_WIFI
#if HAS_WIFI || (HAS_ETHERNET && defined(ETH_PHY_TYPE))
#include "NodeDB.h"
#include "RTC.h"
#include "concurrency/Periodic.h"
Expand All @@ -13,7 +13,7 @@
#if HAS_ETHERNET && defined(USE_WS5500)
#include <ETHClass2.h>
#define ETH ETH2
#endif // HAS_ETHERNET
#endif

#include <WiFiUdp.h>
#ifdef ARCH_ESP32
Expand Down Expand Up @@ -50,7 +50,7 @@ char ourHost[16];
static unsigned long wifiReconnectStartMillis = 0;
static bool wifiReconnectPending = false;

bool APStartupComplete = 0;
bool APStartupComplete = false;

unsigned long lastrun_ntp = 0;

Expand All @@ -62,19 +62,31 @@ meshtastic::Syslog syslog(syslogClient);

Periodic *wifiReconnect;

#ifdef USE_WS5500
// Startup Ethernet
#if HAS_ETHERNET
// Startup Ethernet (Universal: Native or SPI)
bool initEthernet()
{
if ((config.network.eth_enabled) && (ETH.begin(ETH_PHY_W5500, 1, ETH_CS_PIN, ETH_INT_PIN, ETH_RST_PIN, SPI3_HOST,
ETH_SCLK_PIN, ETH_MISO_PIN, ETH_MOSI_PIN))) {
WiFi.onEvent(WiFiEvent);
bool ok = false;
#if defined(ESP32) && defined(ETH_PHY_TYPE)
// Native ESP32 Ethernet (LAN8720, etc.)
LOG_INFO("Starting Native Ethernet...");
WiFi.onEvent(WiFiEvent);
ok = ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE);
#elif defined(USE_WS5500)
// SPI Ethernet (W5500)
LOG_INFO("Starting W5500 Ethernet...");
WiFi.onEvent(WiFiEvent);
ok = ETH.begin(ETH_PHY_W5500, 1, ETH_CS_PIN, ETH_INT_PIN, ETH_RST_PIN, SPI3_HOST, ETH_SCLK_PIN, ETH_MISO_PIN, ETH_MOSI_PIN);
#endif

if (ok) {
#if !MESHTASTIC_EXCLUDE_WEBSERVER
createSSLCert(); // For WebServer
#endif
return true;
}

LOG_ERROR("Ethernet failed to start");
return false;
}
#endif
Expand Down Expand Up @@ -231,21 +243,20 @@ static int32_t reconnectWiFi()

bool isWifiAvailable()
{

if (config.network.wifi_enabled && (config.network.wifi_ssid[0])) {
return true;
#ifdef USE_WS5500
} else if (config.network.eth_enabled) {
}
#if HAS_ETHERNET
else if (config.network.eth_enabled) {
return true;
}
#endif
#ifndef ARCH_PORTDUINO
} else if (WiFi.status() == WL_CONNECTED) {
// it's likely we have wifi now, but user intends to turn it off in config!
else if (WiFi.status() == WL_CONNECTED) {
return true;
#endif
} else {
return false;
}
#endif
return false;
}

// Disable WiFi
Expand Down Expand Up @@ -494,7 +505,10 @@ static void WiFiEvent(WiFiEvent_t event)
LOG_INFO("Ethernet disconnected");
break;
case ARDUINO_EVENT_ETH_GOT_IP:
#ifdef USE_WS5500
#if defined(ETH_PHY_TYPE)
LOG_INFO("Ethernet Obtained IP address: %s", ETH.localIP().toString().c_str());
onNetworkConnected();
#elif defined(USE_WS5500)
LOG_INFO("Obtained IP address: %s, %u Mbps, %s", ETH.localIP().toString().c_str(), ETH.linkSpeed(),
ETH.fullDuplex() ? "FULL_DUPLEX" : "HALF_DUPLEX");
onNetworkConnected();
Expand Down
13 changes: 8 additions & 5 deletions src/mesh/wifi/WiFiAPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
#include <WiFi.h>
#endif

#if HAS_ETHERNET && defined(USE_WS5500)
#if HAS_ETHERNET
#if defined(ESP32) && defined(ETH_PHY_TYPE)
#include <ETH.h>
#elif defined(USE_WS5500)
#include <ETHClass2.h>
#define ETH ETH2
#endif // HAS_ETHERNET
#endif
#endif

extern bool needReconnect;
extern concurrency::Periodic *wifiReconnect;

/// @return true if wifi is now in use
/// @return true if Wi-Fi is now in use
bool initWifi();

void deinitWifi();
Expand All @@ -26,7 +30,6 @@ bool isWifiAvailable();

uint8_t getWifiDisconnectReason();

#ifdef USE_WS5500
// Startup Ethernet
#if HAS_ETHERNET_ON_WIFI_STACK
bool initEthernet();
#endif
Loading
Loading