From bf7f136e5678f40fd17058b7a070e116b5d6618c Mon Sep 17 00:00:00 2001 From: richonguzman Date: Thu, 6 Mar 2025 10:51:58 -0300 Subject: [PATCH] not working --- include/ethernet_utils.h | 13 ++++ src/LoRa_APRS_iGate.cpp | 49 +++++++++++---- src/aprs_is_utils.cpp | 31 ++++++++-- src/ethernet_utils.cpp | 62 +++++++++++++++++++ .../ESP32C3_DIY_Ethernet_LoRa/board_pinout.h | 22 +++++++ .../ESP32C3_DIY_Ethernet_LoRa/platformio.ini | 10 +++ 6 files changed, 168 insertions(+), 19 deletions(-) create mode 100644 include/ethernet_utils.h create mode 100644 src/ethernet_utils.cpp create mode 100644 variants/ESP32C3_DIY_Ethernet_LoRa/board_pinout.h create mode 100644 variants/ESP32C3_DIY_Ethernet_LoRa/platformio.ini diff --git a/include/ethernet_utils.h b/include/ethernet_utils.h new file mode 100644 index 0000000..0798cd2 --- /dev/null +++ b/include/ethernet_utils.h @@ -0,0 +1,13 @@ +#ifndef ETHERNET_UTILS_H_ +#define ETHERNET_UTILS_H_ + +#include + + +namespace ETHERNET_Utils { + + void setup(); + +} + +#endif \ No newline at end of file diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index d785f13..c084f2d 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -23,7 +23,6 @@ ___________________________________________________________________*/ #include #include #include -#include #include #include "configuration.h" #include "battery_utils.h" @@ -35,7 +34,13 @@ ___________________________________________________________________*/ #include "query_utils.h" #include "power_utils.h" #include "lora_utils.h" -#include "wifi_utils.h" +#ifdef HAS_ETHERNET + #include + #include "ethernet_utils.h" +#else + #include + #include "wifi_utils.h" +#endif #include "digi_utils.h" #include "gps_utils.h" #include "web_utils.h" @@ -48,9 +53,15 @@ ___________________________________________________________________*/ #include "A7670_utils.h" #endif -String versionDate = "2025.03.03"; +String versionDate = "2025.03.06"; Configuration Config; -WiFiClient espClient; + +#ifdef HAS_ETHERNET + EthernetClient espClient; +#else + WiFiClient espClient; +#endif + #ifdef HAS_GPS HardwareSerial gpsSerial(1); TinyGPSPlus gps; @@ -80,9 +91,10 @@ String firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seven void setup() { Serial.begin(115200); + delay(5000); POWER_Utils::setup(); Utils::setupDisplay(); - LoRa_Utils::setup(); + //LoRa_Utils::setup(); Utils::validateFreqs(); GPS_Utils::setup(); STATION_Utils::loadBlackList(); @@ -133,7 +145,12 @@ void setup() { } #endif DIGI_Utils::checkEcoMode(); - WIFI_Utils::setup(); + #ifdef HAS_ETHERNET + ETHERNET_Utils::setup(); + #else + WIFI_Utils::setup(); + #endif + LoRa_Utils::setup(); NTP_Utils::setup(); SYSLOG_Utils::setup(); WX_Utils::setup(); @@ -147,14 +164,16 @@ void setup() { } void loop() { - WIFI_Utils::checkAutoAPTimeout(); + #ifndef HAS_ETHERNET + WIFI_Utils::checkAutoAPTimeout(); + #endif - if (isUpdatingOTA) { + /*if (isUpdatingOTA) { ElegantOTA.loop(); return; // Don't process IGate and Digi during OTA update - } + }*/ - if (Config.lowVoltageCutOff > 0) { + /*if (Config.lowVoltageCutOff > 0) { BATTERY_Utils::checkIfShouldSleep(); } @@ -182,8 +201,12 @@ void loop() { #ifdef HAS_A7670 if (Config.aprs_is.active && !modemLoggedToAPRSIS) A7670_Utils::APRS_IS_connect(); #else - WIFI_Utils::checkWiFi(); - if (Config.aprs_is.active && (WiFi.status() == WL_CONNECTED) && !espClient.connected()) APRS_IS_Utils::connect(); + #ifdef HAS_ETHERNET + if (Config.aprs_is.active && !espClient.connected()) APRS_IS_Utils::connect(); + #else + WIFI_Utils::checkWiFi(); + if (Config.aprs_is.active && (WiFi.status() == WL_CONNECTED) && !espClient.connected()) APRS_IS_Utils::connect(); + #endif #endif NTP_Utils::update(); @@ -237,5 +260,5 @@ void loop() { #endif Utils::checkRebootTime(); - Utils::checkSleepByLowBatteryVoltage(1); + Utils::checkSleepByLowBatteryVoltage(1);*/ } \ No newline at end of file diff --git a/src/aprs_is_utils.cpp b/src/aprs_is_utils.cpp index bfc9ac9..134b3e7 100644 --- a/src/aprs_is_utils.cpp +++ b/src/aprs_is_utils.cpp @@ -1,7 +1,7 @@ -#include #include "configuration.h" #include "aprs_is_utils.h" #include "station_utils.h" +#include "board_pinout.h" #include "syslog_utils.h" #include "query_utils.h" #include "A7670_utils.h" @@ -10,7 +10,15 @@ #include "utils.h" extern Configuration Config; -extern WiFiClient espClient; + +#ifdef HAS_ETHERNET + #include + extern EthernetClient espClient; +#else + #include + extern WiFiClient espClient; +#endif + extern uint32_t lastScreenOn; extern String firstLine; extern String secondLine; @@ -58,7 +66,7 @@ namespace APRS_IS_Utils { aprsAuth += Config.callsign; aprsAuth += " pass "; aprsAuth += Config.aprs_is.passcode; - aprsAuth += " vers CA2RXU_LoRa_iGate 2.0 filter "; + aprsAuth += " vers CA2RXU_LoRa_iGate 2.1 filter "; aprsAuth += Config.aprs_is.filter; upload(aprsAuth); } @@ -66,8 +74,14 @@ namespace APRS_IS_Utils { void checkStatus() { String wifiState, aprsisState; - if (WiFi.status() == WL_CONNECTED) { - wifiState = "OK"; + if (true) { + /*#ifdef HAS_ETHERNET + if (Ethernet.linkStatus() == LinkON) { + wifiState = "ET"; + #else + if (WiFi.status() == WL_CONNECTED) { + wifiState = "OK"; + #endif*/ } else { if (backUpDigiMode || Config.digi.ecoMode) { wifiState = "--"; @@ -362,7 +376,12 @@ namespace APRS_IS_Utils { } void firstConnection() { - if (Config.aprs_is.active && (WiFi.status() == WL_CONNECTED) && !espClient.connected()) { + + //#ifdef HAS_ETHERNET + if (Config.aprs_is.active && !espClient.connected()) { + //#else + // if (Config.aprs_is.active && (WiFi.status() == WL_CONNECTED) && !espClient.connected()) { + //#endif connect(); while (!passcodeValid) { listenAPRSIS(); diff --git a/src/ethernet_utils.cpp b/src/ethernet_utils.cpp new file mode 100644 index 0000000..9ad5908 --- /dev/null +++ b/src/ethernet_utils.cpp @@ -0,0 +1,62 @@ +/*#include +#include "configuration.h" +#include "station_utils.h" +#include "aprs_is_utils.h" +#include "query_utils.h" +#include "digi_utils.h" +#include "wifi_utils.h" +#include "lora_utils.h" +#include "gps_utils.h" +#include "display.h" +#include "utils.h"*/ +#include +#include +#include "ethernet_utils.h" +#include "board_pinout.h" + +/*extern Configuration Config; +extern uint32_t lastScreenOn; +extern String iGateBeaconPacket; +extern String firstLine; +extern String secondLine; +extern String thirdLine; +extern String fourthLine; +extern String fifthLine; +extern String sixthLine; +extern String seventhLine; +extern bool backUpDigiMode;*/ + + +byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; + +namespace ETHERNET_Utils { + + void setup() { + SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0)); + pinMode(Ethernet_CS, OUTPUT); + pinMode(Ethernet_MOSI, OUTPUT); + pinMode(Ethernet_MISO, INPUT); + pinMode(Ethernet_SCK, OUTPUT); + SPI.endTransaction(); + Ethernet.init(Ethernet_CS); + Ethernet.begin(mac); + delay(1000); + Serial.println(Ethernet.localIP()); + + delay(1000); + Serial.println(Ethernet.linkStatus()); + delay(1000); + Serial.println(Ethernet.linkStatus()); + delay(1000); + Serial.println(Ethernet.linkStatus()); + delay(1000); + Serial.println(Ethernet.linkStatus()); + delay(1000); + if (Ethernet.linkStatus() == LinkON) { + Serial.println("Ethernet connected..."); + } else { + Serial.println("Ethernet not connected..."); + } + } + +} \ No newline at end of file diff --git a/variants/ESP32C3_DIY_Ethernet_LoRa/board_pinout.h b/variants/ESP32C3_DIY_Ethernet_LoRa/board_pinout.h new file mode 100644 index 0000000..872cc49 --- /dev/null +++ b/variants/ESP32C3_DIY_Ethernet_LoRa/board_pinout.h @@ -0,0 +1,22 @@ +#ifndef BOARD_PINOUT_H_ +#define BOARD_PINOUT_H_ + + // LoRa Radio + #define HAS_SX1278 + #define RADIO_SCLK_PIN 4 + #define RADIO_MISO_PIN 5 + #define RADIO_MOSI_PIN 6 + #define RADIO_CS_PIN 20 + #define RADIO_RST_PIN 3 + #define RADIO_BUSY_PIN 2 + + // Ethernet W5500 + #define HAS_ETHERNET + #define Ethernet_SCK 4 // W5550 SCK + #define Ethernet_MISO 5 // W5550 MI + #define Ethernet_MOSI 6 // W5550 MO + #define Ethernet_CS 7 // W5550 CS (CS = NSS = SS) + //#define Ethernet_VCC 3.3v + //#define Ethernet_GND GND + +#endif \ No newline at end of file diff --git a/variants/ESP32C3_DIY_Ethernet_LoRa/platformio.ini b/variants/ESP32C3_DIY_Ethernet_LoRa/platformio.ini new file mode 100644 index 0000000..eb5ebed --- /dev/null +++ b/variants/ESP32C3_DIY_Ethernet_LoRa/platformio.ini @@ -0,0 +1,10 @@ +[env:ESP32C3_DIY_Ethernet_LoRa] +board = esp32-c3-devkitm-1 +board_build.mcu = esp32c3 +build_flags = + ${common.build_flags} + ${common.usb_flags} + -D ESP32C3_DIY_Ethernet_LoRa +lib_deps = + ${common.lib_deps} + arduino-libraries/Ethernet @ 2.0.2 \ No newline at end of file