first murmurs of ethernet support

This commit is contained in:
Thomas Göttgens 2022-10-22 16:29:50 +02:00
parent 564feadc0d
commit f3fee5f4fb
11 changed files with 102 additions and 23 deletions

View File

@ -3,7 +3,7 @@
extends = arduino_base
platform = platformio/espressif32@^5.2.0
build_src_filter =
${arduino_base.build_src_filter} -<platform/nrf52/> -<platform/stm32wl> -<platform/rp2040>
${arduino_base.build_src_filter} -<platform/nrf52/> -<platform/stm32wl> -<platform/rp2040> -<mesh/eth/>
upload_speed = 921600
debug_init_break = tbreak setup
monitor_filters = esp32_exception_decoder

View File

@ -2,7 +2,7 @@
extends = arduino_base
platform = platformio/espressif32@^5.2.0
build_src_filter =
${arduino_base.build_src_filter} -<platform/nrf52/> -<platform/stm32wl> -<platform/rp2040>
${arduino_base.build_src_filter} -<platform/nrf52/> -<platform/stm32wl> -<platform/rp2040> -<mesh/eth/>
upload_speed = 961200
monitor_speed = 115200
debug_init_break = tbreak setup

View File

@ -47,8 +47,6 @@ size_t RedirectablePrint::vprintf(const char *format, va_list arg)
size_t len = vsnprintf(printBuf, sizeof(printBuf), format, copy);
va_end(copy);
if (len < 0) return 0;
// If the resulting string is longer than sizeof(printBuf)-1 characters, the remaining characters are still counted for the return value
if (len > sizeof(printBuf) - 1) {

View File

@ -142,6 +142,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef HAS_WIFI
#define HAS_WIFI 0
#endif
#ifndef HAS_ETHERNET
#define ETHERNET 0
#endif
#ifndef HAS_SCREEN
#define HAS_SCREEN 0
#endif

View File

@ -30,6 +30,7 @@
// #include <driver/rtc_io.h>
#include "mesh/http/WiFiAPClient.h"
#include "mesh/eth/ethClient.h"
#ifdef ARCH_ESP32
#include "mesh/http/WebServer.h"
@ -440,6 +441,9 @@ void setup()
// Initialize Wifi
initWifi(forceSoftAP);
// Initialize Ethernet
initEthernet();
#ifdef ARCH_ESP32
// Start web server thread.
webServerThread = new WebServerThread();

View File

@ -0,0 +1,55 @@
#include "mesh/eth/ethClient.h"
#include "NodeDB.h"
#include <SPI.h>
#include <RAK13800_W5100S.h>
#include "target_specific.h"
// Startup Ethernet
bool initEthernet()
{
if (config.network.eth_enabled) {
Ethernet.init( SS );
uint8_t mac[6];
getMacAddr(mac); // FIXME use the BLE MAC for now...
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
DEBUG_MSG("Ethernet shield was not found.\n");
} else if (Ethernet.linkStatus() == LinkOFF) {
DEBUG_MSG("Ethernet cable is not connected.\n");
} else if (config.network.eth_mode == Config_NetworkConfig_EthMode_DHCP) {
DEBUG_MSG("starting Ethernet DHCP\n");
if (Ethernet.begin(mac) == 0) {
DEBUG_MSG("DHCP failed\n");
} else{
DEBUG_MSG("DHCP assigned IP %s\n",Ethernet.localIP());
}
} else if (config.network.eth_mode == Config_NetworkConfig_EthMode_STATIC) {
DEBUG_MSG("starting Ethernet Static\n");
Ethernet.begin(mac, config.network.eth_config.ip, config.network.eth_config.dns, config.network.eth_config.subnet);
} else {
DEBUG_MSG("Ethernet Disabled\n");
return false;
}
return true;
} else {
DEBUG_MSG("Not using Ethernet\n");
return false;
}
}
bool isEthernetAvailable() {
if (!config.network.eth_enabled) {
return false;
} else if (Ethernet.hardwareStatus() == EthernetNoHardware) {
return false;
} else if (Ethernet.linkStatus() == LinkOFF) {
return false;
} else {
return true;
}
}

8
src/mesh/eth/ethClient.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include "configuration.h"
#include <Arduino.h>
#include <functional>
bool initEthernet();
bool isEthernetAvailable();

27
src/network-stubs.cpp Normal file
View File

@ -0,0 +1,27 @@
#include "configuration.h"
#if (HAS_WIFI == 0)
bool initWifi(bool forceSoftAP) {
return false;
}
void deinitWifi() {}
bool isWifiAvailable() {
return false;
}
#endif
#if (HAS_ETHERNET == 0)
bool initEthernet() {
return false;
}
bool isEthernetAvailable() {
return false;
}
#endif

View File

@ -1,19 +0,0 @@
//#include "mesh/wifi/WebServer.h"
#include "configuration.h"
#ifndef ARCH_ESP32
//#include "mesh/wifi/WiFiAPClient.h"
bool initWifi(bool forceSoftAP) {
return false;
}
void deinitWifi() {}
bool isWifiAvailable()
{
return false;
}
#endif

View File

@ -7,6 +7,7 @@ build_src_filter = ${nrf52_base.build_src_filter} +<../variants/rak4631>
lib_deps =
${nrf52840_base.lib_deps}
melopero/Melopero RV3028@^1.1.0
beegee-tokyo/RAK13800-W5100S@^1.0.1
debug_tool = jlink
; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm)
;upload_protocol = jlink

View File

@ -226,6 +226,8 @@ static const uint8_t SCK = PIN_SPI_SCK;
#define HAS_RTC 1
#define HAS_ETHERNET 1
#ifdef __cplusplus
}
#endif