Hi
I make script to communicate Domoticz with ESP32 POE
I can connect to DOmoticz, set static IP and send data but I don't know how recive data by ethernet in ESP32
/*
This sketch shows the Ethernet event usage
*/
#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
#define ETH_PHY_POWER 12
#include <ETH.h>
#include <SPI.h>
#include <Ethernet.h>
//IPAddress domoticz(192,168,8,102); // Domoticz IP Address
static bool eth_connected = false;
void WiFiEvent(WiFiEvent_t event)
{
switch (event) {
case SYSTEM_EVENT_ETH_START:
Serial.println("ETH Started");
//set eth hostname here
ETH.setHostname("esp32-ethernet");
break;
case SYSTEM_EVENT_ETH_CONNECTED:
Serial.println("ETH Connected");
break;
case SYSTEM_EVENT_ETH_GOT_IP:
Serial.print("ETH MAC: ");
Serial.print(ETH.macAddress());
Serial.print(", IPv4: ");
Serial.print(ETH.localIP());
if (ETH.fullDuplex()) {
Serial.print(", FULL_DUPLEX");
}
Serial.print(", ");
Serial.print(ETH.linkSpeed());
Serial.println("Mbps");
eth_connected = true;
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
Serial.println("ETH Disconnected");
eth_connected = false;
break;
case SYSTEM_EVENT_ETH_STOP:
Serial.println("ETH Stopped");
eth_connected = false;
break;
default:
break;
}
}
void testClient(const char * host, uint16_t port)
{
Serial.print("\nconnecting to ");
Serial.println(host);
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
return;
}else{
Serial.println("Podlaczony do Domoticza");
client.print( "GET /json.htm?type=command¶m=switchlight&idx=1&switchcmd=Off");
client.println( " HTTP/1.1");
client.print( "Host: ");
client.println(host);
client.println( "Connection: close");
client.println();
delay(2000);
Serial.println("closing connection\n");
client.stop();
}
}
void setup()
{
Serial.begin(115200);
WiFi.onEvent(WiFiEvent);
ETH.begin();
ETH.config(IPAddress(192, 168, 8, 109),IPAddress(192, 168, 8, 1),IPAddress(255, 255, 255, 0),IPAddress(192, 168, 8, 1), IPAddress(192, 168, 8, 1));
}
void loop()
{
if (eth_connected) {
testClient("192.168.8.102", 8080);
}
delay(10000);
///try recive data ///////////////////
while(Serial.available()>0)
{
int val = Serial.parseInt();
if(Serial.read()== '\n'){
Serial.println(val);
int wys = 18 ;
Serial.print(wys);
Serial.println("\n");
}
}
////////end recive data ////////////////
}
Did you first test the most basic Ethernet example:
https://github.com/espressif/arduino-esp32/blob/1.0.4/libraries/WiFi/examples/ETH_LAN8720/ETH_LAN8720.ino
It is also mentioned in this documnet:
https://www.olimex.com/Products/IoT/ESP32/_resources/Arudino-ESP32.txt
Hi
Looking at the "most basic Ethernet example" am I correct in saying that WiFiEvent(WiFiEvent_t event) is a WiFi routine and not a wired RMII routine?
We want to use the Olimex ESP32 PoE on cabled Ethernet but are STILL looking for code examples. There are plenty for WiFi and SPI to Ethernet Shields but not RMII it seems.
Ask in the Arduino IDE GitHub about the name WiFiEvent. It starts the Ethernet tho with SYSTEM_EVENT_ETH_START.
Of course, ESP-IDF is the suggested environment for ESP32 and this example also sets the Ethernet: https://github.com/OLIMEX/ESP32-POE/tree/master/SOFTWARE/ESP-IDF/ESP32_PoE_Ethernet