Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for POESP32 board #400

Closed
wants to merge 4 commits into from
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
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:ESPOE32]
platform = espressif32
board = m5stack-core-esp32
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 ESPOE32"

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

#ifdef ESPOE32
#include <ETH.h>
#define ETH_ADDR 1
#define ETH_POWER 5
#define ETH_MDC 23
#define ETH_MDIO 18
#endif

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

Expand All @@ -33,6 +41,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 +167,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 +179,54 @@ void checkWifi()
}
}

#ifdef ESPOE32
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);
#ifdef ESPOE32
ETH.begin(ETH_ADDR, ETH_POWER, ETH_MDC, ETH_MDIO, ETH_PHY_IP101, ETH_CLOCK_GPIO0_IN);
#endif

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

void setup_wifi()
{
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 +268,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,9 +340,14 @@ void setup()

EEPROM.begin(10);
readEEPROM();//Restore previous state
#ifdef ESPOE32
mqttSerial.print("Setting up ethernet...");
setupEthernet();
#else
mqttSerial.print("Setting up wifi...");
setup_wifi();
ArduinoOTA.setHostname("ESPAltherma");
setupWifi();
#endif
ArduinoOTA.setHostname(HOSTNAME);
ArduinoOTA.onStart([]() {
busy = true;
});
Expand Down Expand Up @@ -324,7 +382,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
3 changes: 3 additions & 0 deletions src/setup.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//Default device hostname:
#define HOSTNAME "ESPAltherma"

//Setup your credentials and mqtt info here:
//only change the value between the " " leave the rest of the line untouched.
#define WIFI_SSID "SSID"//**Your SSID here**
Expand Down