Getting Started with Aptinex IsolPoE – ESP32 ProDev Kit

First Glimpse at PoE Ethernet for DIY IoT Projects.

IntermediateProtip74
Getting Started with Aptinex IsolPoE – ESP32 ProDev Kit

Things used in this project

Hardware components

Aptinex IsolPoE – ESP32 ProDev Kit
×1
Aptinex Dual Channel Relay Module 12V 10A (2 channel)
×1
PoE Injector
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×4

Software apps and online services

Arduino IDE
Arduino IDE
Socket Test

Story

Read more

Schematics

Wire connection

Code

aptinex_poe_dev_test.ino

C/C++
/****************************************************************************************************************************
  Async_UdpServer.ino

  AsyncUDP_WT32_ETH01 is a Async UDP library for the WT32_ETH01 (ESP32 + LAN8720)

  Based on and modified from ESPAsyncUDP Library (https://github.com/me-no-dev/ESPAsyncUDP)
  Built by Khoi Hoang https://github.com/khoih-prog/AsyncUDP_WT32_ETH01
  Licensed under MIT license
 *****************************************************************************************************************************/
#include <Arduino.h>

#define ASYNC_UDP_WT32_ETH01_DEBUG_PORT      Serial

// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_UDP_WT32_ETH01_LOGLEVEL_      1

#include <AsyncUDP_WT32_ETH01.h>


/////////////////////////////////////////////

// Select the IP address according to your local network
IPAddress myIP(192, 168, 1, 155);
IPAddress myGW(192, 168, 1, 1);
IPAddress mySN(255, 255, 255, 0);

// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);

/////////////////////////////////////////////
#define ETH_CLK_MODE     ETH_CLOCK_GPIO0_IN 

// Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source)
#define ETH_PHY_POWER   17

// Type of the Ethernet PHY (LAN8720 or TLK110)
#define ETH_PHY_TYPE        ETH_PHY_LAN8720

// IC-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)
#define ETH_PHY_ADDR        1

// Pin# of the IC clock signal for the Ethernet PHY
#define ETH_PHY_MDC     23

// Pin# of the IC IO signal for the Ethernet PHY
#define ETH_PHY_MDIO    18

//UDP Port number
#define udp_port 1234

AsyncUDP udp;

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  
  Serial.print("\nStarting Async_UDPClient on " + String(ARDUINO_BOARD));
  Serial.println(" with " + String(SHIELD_TYPE));
  Serial.println(WEBSERVER_WT32_ETH01_VERSION);
  Serial.println(ASYNC_UDP_WT32_ETH01_VERSION);

  Serial.setDebugOutput(true);

  delay(3000);
  // To be called before ETH.begin()
  WT32_ETH01_onEvent();

  //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 
  //           eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE);
  //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE);
  ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE);

  // Static IP, leave without this line to get IP via DHCP
  //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
  ETH.config(myIP, myGW, mySN, myDNS);

  WT32_ETH01_waitForConnect();

  // Client address
  Serial.print("AsyncUDPServer started @ IP address: ");
  Serial.println(ETH.localIP());
 
  if (udp.listen(udp_port)) 
  {
    Serial.print("UDP Listening on IP: ");
    Serial.println(ETH.localIP());
    
    udp.onPacket([](AsyncUDPPacket packet) 
    {
      Serial.print("UDP Packet Type: ");
      Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
      Serial.print(", From: ");
      Serial.print(packet.remoteIP());
      Serial.print(":");
      Serial.print(packet.remotePort());
      Serial.print(", To: ");
      Serial.print(packet.localIP());
      Serial.print(":");
      Serial.print(packet.localPort());
      Serial.print(", Length: ");
      Serial.print(packet.length());
      Serial.print(", Data: ");
      Serial.write(packet.data(), packet.length());
      Serial.println();
      //reply to the client
      packet.printf("Got %u bytes of data", packet.length());
    });
  }

} 


void loop()
{
  delay(1000);
  //Send broadcast
  udp.broadcast("Hello");
 Serial.println("MSG BRDCASTED !!!");
}

Switch_Relays_Via_Ethernet.ino

C/C++
#include <Arduino.h>

#define ASYNC_UDP_WT32_ETH01_DEBUG_PORT Serial

// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_UDP_WT32_ETH01_LOGLEVEL_ 1

#include <AsyncUDP_WT32_ETH01.h>

/////////////////////////////////////////////

// Select the IP address according to your local network
IPAddress myIP(192, 168, 1, 155);
IPAddress myGW(192, 168, 1, 1);
IPAddress mySN(255, 255, 255, 0);

// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);

/////////////////////////////////////////////
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN

// Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source)
#define ETH_PHY_POWER 17

// Type of the Ethernet PHY (LAN8720 or TLK110)
#define ETH_PHY_TYPE ETH_PHY_LAN8720

// IC-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)
#define ETH_PHY_ADDR 1

// Pin# of the IC clock signal for the Ethernet PHY
#define ETH_PHY_MDC 23

// Pin# of the IC IO signal for the Ethernet PHY
#define ETH_PHY_MDIO 18

// UDP Port number
#define udp_port 1234

// Onboard LED pin
#define ONBOARD_LED_PIN 2  // Replace with the correct pin for your board

//Define Relay Pins
#define Relay1_pin 12
#define Relay2_pin 14

AsyncUDP udp;

void setup() {
  Serial.begin(115200);
  while (!Serial)
    ;

  Serial.print("\nStarting Async_UDPClient on " + String(ARDUINO_BOARD));
  Serial.println(" with " + String(SHIELD_TYPE));
  Serial.println(WEBSERVER_WT32_ETH01_VERSION);
  Serial.println(ASYNC_UDP_WT32_ETH01_VERSION);

  Serial.setDebugOutput(true);

  delay(3000);
  // To be called before ETH.begin()
  WT32_ETH01_onEvent();

  // ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE);
  ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE);

  // Static IP, leave without this line to get IP via DHCP
  ETH.config(myIP, myGW, mySN, myDNS);

  WT32_ETH01_waitForConnect();

  // Client address
  Serial.print("AsyncUDPServer started @ IP address: ");
  Serial.println(ETH.localIP());

  if (udp.listen(udp_port)) {
    Serial.print("UDP Listening on IP: ");
    Serial.println(ETH.localIP());

    udp.onPacket([](AsyncUDPPacket packet) {
      Serial.print("UDP Packet Type: ");
      Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast"
                                                                             : "Unicast");
      Serial.print(", From: ");
      Serial.print(packet.remoteIP());
      Serial.print(":");
      Serial.print(packet.remotePort());
      Serial.print(", To: ");
      Serial.print(packet.localIP());
      Serial.print(":");
      Serial.print(packet.localPort());
      Serial.print(", Length: ");
      Serial.print(packet.length());
      Serial.print(", Data: ");
      Serial.write(packet.data(), packet.length());
      Serial.println();


      // Check the received message
      String receivedMsg = String((char *)packet.data());


      // Check if the message is "R1_ON", turn on the Relay 1
      if (receivedMsg == "R1_ON") {
        digitalWrite(Relay1_pin, HIGH);
        udp.broadcast("Relay 1 turned on");
        Serial.println("Relay 1 turned on");
      }
      // Check if the message is "R1_OFF", turn off the Relay 1
      else if (receivedMsg == "R1_OFF") {
        digitalWrite(Relay1_pin, LOW);
        udp.broadcast("Relay 1 turned off");
        Serial.println("Relay 1 turned off");
      }
      //Check if the message is "R2_ON", turn on the Relay 2
      else if (receivedMsg == "R2_ON") {
        digitalWrite(Relay2_pin, HIGH);
        udp.broadcast("Relay 2 turned on");
        Serial.println("Relay 2 turned on");
      }
      // Check if the message is "R2_OFF", turn off the Relay 2
      else if (receivedMsg == "R2_OFF") {
        digitalWrite(Relay2_pin, LOW);
        udp.broadcast("Relay 2 turned off");
        Serial.println("Relay 2 turned off");
      }
    });
  }

  // Set the onboard Relay pins as OUTPUT
  pinMode(Relay1_pin, OUTPUT);
  pinMode(Relay2_pin, OUTPUT);
}

void loop() {
}

Credits

Chathura Yapa Bandara
19 projects • 5 followers
Contact
Kesara Malinda
3 projects • 1 follower
Contact
Bhuvisara Dharmasena
5 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.