Skip to content

Commit

Permalink
Add basic support for WT32-ETH01 board
Browse files Browse the repository at this point in the history
  • Loading branch information
bgcngm committed Feb 19, 2024
1 parent 92216ee commit 2b04916
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 6 deletions.
16 changes: 16 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ lib_deps =

build_flags = "-D ARDUINO_M5Stick_C_Plus"

[env:wt32-eth01]
platform = espressif32
board = wt32-eth01
framework = arduino
monitor_speed = 115200
upload_speed = 115200
; Uncomment this line to allow for remote upgrade. If name resolution does not work for you, replace with the IP of ESPAltherma
; upload_port = ESPAltherma.local
; Uncomment this line if you want to define the protocol. Autodetected otherwise.
; upload_protocol = espota

lib_deps =
PubSubClient

build_flags = "-D WT32_ETH01"

[env:native]
# Used to run unit test; g++ must be in PATH.
platform = native
Expand Down
64 changes: 58 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#endif
#include <HardwareSerial.h>

#ifdef WT32_ETH01
#include <ETH.h>
#endif

#include <PubSubClient.h>
#include <ArduinoOTA.h>

Expand All @@ -33,6 +37,8 @@ Converter converter;
char registryIDs[32]; //Holds the registries to query
bool busy = false;

static bool eth_connected = false;

#if defined(ARDUINO_M5Stick_C) || defined(ARDUINO_M5Stick_C_Plus)
long LCDTimeout = 40000;//Keep screen ON for 40s then turn off. ButtonA will turn it On again.
#endif
Expand Down Expand Up @@ -157,7 +163,7 @@ void get_wifi_bssid(const char *ssid, uint8_t *bssid, uint32_t *wifi_channel)
void checkWifi()
{
int i = 0;
while (WiFi.status() != WL_CONNECTED)
while (!WiFi.isConnected())
{
delay(500);
Serial.print(".");
Expand All @@ -169,11 +175,52 @@ void checkWifi()
}
}

void setup_wifi()
#ifdef WT32_ETH01
void WiFiEvent(WiFiEvent_t event)
{
switch (event) {
case ARDUINO_EVENT_ETH_START:
Serial.println("ETH Started");
// The hostname must be set after the interface is started, but needs
// to be set before DHCP, so set it from the event handler thread.
ETH.setHostname(HOSTNAME);
break;
case ARDUINO_EVENT_ETH_CONNECTED:
Serial.println("ETH Connected");
break;
case ARDUINO_EVENT_ETH_GOT_IP:
Serial.println("ETH Got IP");
eth_connected = true;
break;
case ARDUINO_EVENT_ETH_DISCONNECTED:
Serial.println("ETH Disconnected");
eth_connected = false;
break;
case ARDUINO_EVENT_ETH_STOP:
Serial.println("ETH Stopped");
eth_connected = false;
break;
default:
break;
}
}

void setupEthernet()
{
WiFi.onEvent(WiFiEvent);
ETH.begin();

if (ETH.linkUp()) {
Serial.printf("Connected. IP Address: %s\n", ETH.localIP().toString().c_str());
}
}
#endif

void setupWifi()
{
delay(10);
// We start by connecting to a WiFi network
mqttSerial.printf("Connecting to %s\n", WIFI_SSID);
Serial.printf("Connecting to %s\n", WIFI_SSID);

#if defined(WIFI_IP) && defined(WIFI_GATEWAY) && defined(WIFI_SUBNET)
IPAddress local_IP(WIFI_IP);
Expand Down Expand Up @@ -215,7 +262,7 @@ void setup_wifi()
WiFi.begin(WIFI_SSID, WIFI_PWD, 0, 0, true);
}
checkWifi();
mqttSerial.printf("Connected. IP Address: %s\n", WiFi.localIP().toString().c_str());
Serial.printf("Connected. IP Address: %s\n", WiFi.localIP().toString().c_str());
}

void initRegistries(){
Expand Down Expand Up @@ -287,8 +334,13 @@ void setup()

EEPROM.begin(10);
readEEPROM();//Restore previous state
#ifdef WT32_ETH01
mqttSerial.print("Setting up ethernet...");
setupEthernet();
#else
mqttSerial.print("Setting up wifi...");
setup_wifi();
setupWifi();
#endif
ArduinoOTA.setHostname(HOSTNAME);
ArduinoOTA.onStart([]() {
busy = true;
Expand Down Expand Up @@ -324,7 +376,7 @@ void waitLoop(uint ms){
void loop()
{
unsigned long start = millis();
if (WiFi.status() != WL_CONNECTED)
if (!eth_connected && !WiFi.isConnected())
{ //restart board if needed
checkWifi();
}
Expand Down
5 changes: 5 additions & 0 deletions src/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@
#define TX_PIN 26// Pin connected to the RX pin of X10A
#else
//Default GPIO PINs for Serial2:
#if defined(WT32_ETH01)
#define RX_PIN 5// Pin connected to the TX pin of X10A
#define TX_PIN 17// Pin connected to the RX pin of X10A
#else
#define RX_PIN 16// Pin connected to the TX pin of X10A
#define TX_PIN 17// Pin connected to the RX pin of X10A
#endif
#endif

#define PIN_THERM 0// Pin connected to the thermostat relay (normally open)

Expand Down

0 comments on commit 2b04916

Please sign in to comment.