dawidchyrzynski / arduino-home-assistant

ArduinoHA allows to integrate an Arduino/ESP based device with Home Assistant using MQTT.
https://dawidchyrzynski.github.io/arduino-home-assistant/
GNU Affero General Public License v3.0
498 stars 118 forks source link

Support for wESP32 POE Board #160

Closed CV8R closed 1 year ago

CV8R commented 1 year ago

Hi,

I am attempting to have your fantastic library operate on the wESP32 board with wired Ethernet.

https://wesp32.com/

@xorbit

I have successfully had the ArduinoHA library working on the WiFi on the wESP but when trying to use the Wired Ethernet port with ETH.h the code compiles and runs but it never connects to the mqtt broker. I think there is some incompatibility between ETH.h and Ethernet.h regarding the Client class.

Note, network connectivity works fine (I can ping the wESP32) but the library never connects to the mqtt broker.

I have tried the very basic sketch copied below with no success.

Any chance we will be able to get this board running?

Thanks, CV8R


#include <Ethernet.h>
#include <ETH.h>
#include <ArduinoHA.h>

#define ARDUINOHA_DEBUG

#define BROKER_ADDR IPAddress(10,0,0,111)

byte mac[] = {0x94, 0xB5, 0x55, 0xA2, 0xF0, 0x89};

EthernetClient client;
HADevice device(mac, sizeof(mac));
HAMqtt mqtt(client, device);

HASensor valve("myValve");

void setup() {
    delay(1000);
    // Open serial communications and wait for port to open:
    Serial.begin(115200);
    delay(1000);

    // you don't need to verify return status
    //Ethernet.begin(mac);

    //WESP32 Code
    // Start the Ethernet, revision 7+ uses RTL8201
    ETH.begin(0, -1, 16, 17, ETH_PHY_RTL8201);

    delay(1000);
    Serial.println(F("Starting..."));

    mqtt.begin(BROKER_ADDR,"mqttusr","apasswordhere");

    // set device's details (optional)
    device.enableSharedAvailability();
    device.enableLastWill();
    device.setName("Water Vale Sensor");
    device.setSoftwareVersion("1.0.0");
    device.setManufacturer("ArduinoHA");
    device.setModel("wESP32");

    // configure sensor (optional)
    valve.setIcon("mdi:home");
    delay(2000);
    valve.setName("Water valve");
    delay(2000);

}

void loop() {
    Ethernet.maintain();
    mqtt.loop();

    // you can report different states as follows:
    Serial.println(F("Setting Open"));
    valve.setValue("Open");
    delay(5000);
    Serial.println(F("Setting Opening"));
    valve.setValue("Opening");
    delay(5000);
    Serial.println(F("Setting Close"));
    valve.setValue("Close");
    delay(5000);

}
CV8R commented 1 year ago

Can report that I have solved this issue by replacing Ethernet.h and EthernetClient.

Changing to:

#include <WiFiClient.h> and WiFiClient client;

Working great now and wired Ethernet is rock solid.