ESP32 + LAN8720

elmaya
Posts: 1482
Joined: Wed Jun 27, 2018 5:48 pm
Location: El Saucejo - Sevilla

Post

library for ESP32 + LAN8720.

Edited.
added the ability to select "I²C-address of Ethernet PHY" between 0 and 1.
paste the "esp32eth.h" library to your Supla library "\src\supla\network"
esp32eth.rar
https://github.com/SUPLA/supla-arduino/tree/develop

Code: Select all

 // LAN8720 Pin 10 connected to + 3.3v
#include <supla/network/esp32eth.h>
  Supla::ESPETH Eth(1);  // uint_t ETH_ADDR = I²C-address of Ethernet PHY (1)

Code: Select all

 // LAN8720 Pin 10 connected to GND
#include <supla/network/esp32eth.h>
  Supla::ESPETH Eth(0);  // uint_t ETH_ADDR = I²C-address of Ethernet PHY (0)
It is necessary to disable the 50MHz oscillator of the LAN8720 by bridging the oscillator pins 1 and 2.
LAN8720-ETH-Board.jpg

the connections are:
------ESP32----------LAN8720
GPIO22 - EMAC_TXD1 : TX1
GPIO19 - EMAC_TXD0 : TX0
GPIO21 - EMAC_TX_EN : TX_EN
GPIO26 - EMAC_RXD1 : RX1
GPIO25 - EMAC_RXD0 : RX0
GPIO27 - EMAC_RX_DV : CRS
GPIO17 - EMAC_TX_CLK : nINT/REFCLK (50MHz)
GPIO23 - SMI_MDC : MDC
GPIO18 - SMI_MDIO : MDIO
GND : GND
3V3 : VCC
ESP32+LAN8720_esquemático.png
code example:

Code: Select all

/*
  Copyright (C) AC SOFTWARE SP. Z O.O.

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

/*
-(50MHz) Osc. Enable to GND -
GPIO22 - EMAC_TXD1   : TX1
GPIO19 - EMAC_TXD0   : TX0
GPIO21 - EMAC_TX_EN  : TX_EN
GPIO26 - EMAC_RXD1   : RX1
GPIO25 - EMAC_RXD0   : RX0
GPIO27 - EMAC_RX_DV  : CRS
GPIO17 - EMAC_TX_CLK : nINT/REFCLK (50MHz)
GPIO23 - SMI_MDC     : MDC
GPIO18 - SMI_MDIO    : MDIO
GND                  : GND
3V3                  : VCC
*/

#define supla_lib_config_h_  // silences debug messages
#include <SuplaDevice.h>
#include <supla/control/rgbw_leds.h>
#include <supla/control/button.h>
#include <supla/network/esp32eth.h>
  Supla::ESPETH Eth(1);  // uint_t ETH_ADDR = I²C-address of Ethernet PHY (0 or 1)
 
/*
   Youtube: https://youtu.be/FE9tqzTjmA4
   Youtube example was done on older version of SuplaDevice library
*/

#define RED_PIN              4
#define GREEN_PIN            5
#define BLUE_PIN             12
#define BRIGHTNESS_PIN       13
#define BUTTON_PIN           0

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

  // Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
  char GUID[SUPLA_GUID_SIZE] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF};

  // Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
  char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF};

  /*
     Having your device already registered at cloud.supla.org,
     you want to change CHANNEL sequence or remove any of them,
     then you must also remove the device itself from cloud.supla.org.
     Otherwise you will get "Channel conflict!" error.
  */

  // CHANNEL0 - RGB controller and dimmer (RGBW)
  auto rgbw = new Supla::Control::RGBWLeds(
    RED_PIN, GREEN_PIN, BLUE_PIN, BRIGHTNESS_PIN);

  auto button = new Supla::Control::Button(BUTTON_PIN, true, true);
  button->setMulticlickTime(200);
  button->setHoldTime(400);
  button->repeatOnHoldEvery(200);

  button->addAction(Supla::ITERATE_DIM_ALL, rgbw, Supla::ON_HOLD);
  button->addAction(Supla::TOGGLE, rgbw, Supla::ON_CLICK_1);

  /*
     SuplaDevice Initialization.
     Server address is available at https://cloud.supla.org
     If you do not have an account, you can create it at
     https://cloud.supla.org/account/create SUPLA and SUPLA CLOUD are free of
     charge

  */

  SuplaDevice.begin(
      GUID,              // Global Unique Identifier
      "svr1.supla.org",  // SUPLA server address
      "email@address",   // Email address used to login to Supla Cloud
      AUTHKEY);          // Authorization key
}

void loop() {
  SuplaDevice.iterate();
}
You do not have the required permissions to view the files attached to this post.
User avatar
klew
Posts: 8798
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

Post

Nice :)
Finally something other than Arduino Mega with ethernet :)
Widzimy się na Supla Offline Party vol. 2 :!:
elmaya
Posts: 1482
Joined: Wed Jun 27, 2018 5:48 pm
Location: El Saucejo - Sevilla

Post

klew wrote: Thu Jan 13, 2022 9:28 am Nice :)
Finally something other than Arduino Mega with ethernet :)
have you checked it?
You may want to complete the code with the options to select the gpio "EMAC_TX_CLK" between "ETH_CLOCK_GPIO0_OUT" and "ETH_CLOCK_GPIO17_OUT" in addition to the option to select "I²C-address of Ethernet PHY (0 or 1)".
with those options it would be more compatible.
I'm sure that you can make it very elegant and you can add it to the Supla library.
User avatar
klew
Posts: 8798
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

Post

elmaya wrote: Thu Jan 13, 2022 9:52 am
klew wrote: Thu Jan 13, 2022 9:28 am Nice :)
Finally something other than Arduino Mega with ethernet :)
have you checked it?
You may want to complete the code with the options to select the gpio "EMAC_TX_CLK" between "ETH_CLOCK_GPIO0_OUT" and "ETH_CLOCK_GPIO17_OUT" in addition to the option to select "I²C-address of Ethernet PHY (0 or 1)".
with those options it would be more compatible.
I'm sure that you can make it very elegant and you can add it to the Supla library.
I took a look at this code, but didn't really dig into.
I don't have that module, and with those various network interfaces I don't have enough "courage" to modify something without cheking it on HW :).
Widzimy się na Supla Offline Party vol. 2 :!:
elmaya
Posts: 1482
Joined: Wed Jun 27, 2018 5:48 pm
Location: El Saucejo - Sevilla

Post

okay.
I have been testing it for a couple of days and it works as it should.
We wait for someone else to test it.
elmaya
Posts: 1482
Joined: Wed Jun 27, 2018 5:48 pm
Location: El Saucejo - Sevilla

Post

Example code for static IP.

Code: Select all

/*
  Copyright (C) AC SOFTWARE SP. Z O.O.

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

/*
  -(50MHz) Osc. Enable to GND -
  GPIO22 - EMAC_TXD1   : TX1
  GPIO19 - EMAC_TXD0   : TX0
  GPIO21 - EMAC_TX_EN  : TX_EN
  GPIO26 - EMAC_RXD1   : RX1
  GPIO25 - EMAC_RXD0   : RX0
  GPIO27 - EMAC_RX_DV  : CRS
  GPIO17 - EMAC_TX_CLK : nINT/REFCLK (50MHz)
  GPIO23 - SMI_MDC     : MDC
  GPIO18 - SMI_MDIO    : MDIO
  GND                  : GND
  3V3                  : VCC
*/

#define supla_lib_config_h_  // silences debug messages
#include <SuplaDevice.h>
#include <supla/control/rgbw_leds.h>
#include <supla/control/button.h>
#include <supla/network/esp32eth.h>
  Supla::ESPETH Eth(1);  // uint_t ETH_ADDR = I²C-address of Ethernet PHY (0 or 1)

// Set your Static IP address
IPAddress local_IP(192, 168, 1, 184);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8);   //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional


#define RED_PIN              4
#define GREEN_PIN            5
#define BLUE_PIN             12
#define BRIGHTNESS_PIN       13
#define BUTTON_PIN           0

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

  // Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
  char GUID[SUPLA_GUID_SIZE] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

  // Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
  char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

  /*
     Having your device already registered at cloud.supla.org,
     you want to change CHANNEL sequence or remove any of them,
     then you must also remove the device itself from cloud.supla.org.
     Otherwise you will get "Channel conflict!" error.
  */

  // CHANNEL0 - RGB controller and dimmer (RGBW)
  auto rgbw = new Supla::Control::RGBWLeds(
    RED_PIN, GREEN_PIN, BLUE_PIN, BRIGHTNESS_PIN);

  auto button = new Supla::Control::Button(BUTTON_PIN, true, true);
  button->setMulticlickTime(200);
  button->setHoldTime(400);
  button->repeatOnHoldEvery(200);

  button->addAction(Supla::ITERATE_DIM_ALL, rgbw, Supla::ON_HOLD);
  button->addAction(Supla::TOGGLE, rgbw, Supla::ON_CLICK_1);

  /*
     SuplaDevice Initialization.
     Server address is available at https://cloud.supla.org
     If you do not have an account, you can create it at
     https://cloud.supla.org/account/create SUPLA and SUPLA CLOUD are free of
     charge

  */

  SuplaDevice.begin(
    GUID,              // Global Unique Identifier
    "svr1.supla.org",  // SUPLA server address
    "email@address",   // Email address used to login to Supla Cloud
    AUTHKEY);          // Authorization key

  ETH.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS);

}

void loop() {
  SuplaDevice.iterate();
}
radzik_r
Posts: 405
Joined: Sun Aug 11, 2019 5:32 pm

Post

Fajne, przetestowałem, i działa.

Jeśli ktoś martwi sie zasięgiem wifi w szafie rozdzielczej to można już budować sterownik z potężnym mikroprocesorem i LAN

Cool, tested it, and it works.
If someone is worried about the range of wifi in the switch cabinet, you can already build a controller with a powerful microprocessor and LAN
You do not have the required permissions to view the files attached to this post.
dobo
Posts: 1049
Joined: Sun Apr 07, 2019 8:14 pm
Location: Nadarzyn

Post

Wyjaśnijcie mi sens połączenia tych modułów.
Ja widzę jedynie gdy mamy dużą odległość (100m lub więcej) do jakiegoś urządzenia, którym chcemy sterować poprzez połączenie z netem za pomocą LAN bo WiFi nie ma tam zasięgu.
Tylko koszty takiego rozwiązania kablowego są spore i muszą być przewidziane w instalacji domowej lub zewnętrznej (kabel LAN ziemny - żelowy). Tu rozwiązaniem mógłby być repeater WiFi na zewnątrz - było by taniej niż kabel LAN ziemny.
Czy LAN8720 w połączeniu z Arduino UNO czy NANO nie dał by tego samego?
Czy chodzi tu o moc obliczeniową ESP32?

Explain to me the sense of combining these modules.
I can only see when we have a large distance (100m or more) to a device that we want to control by connecting to the net via LAN because WiFi has no coverage there.
Only the costs of such a cable solution are considerable and must be provided for in a home or outdoor installation (earth-gel LAN cable). The solution here could be a WiFi repeater outside - it would be cheaper than a LAN cable.
Would LAN8720 in combination with Arduino UNO or NANO not give the same?
Is it about the computing power of ESP32?
elmaya
Posts: 1482
Joined: Wed Jun 27, 2018 5:48 pm
Location: El Saucejo - Sevilla

Post

please in English.

uno, nano, don't have enough ram.
User avatar
klew
Posts: 8798
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

Post

dobo wrote: Sun Jan 16, 2022 11:13 pm Explain to me the sense of combining these modules.
I can only see when we have a large distance (100m or more) to a device that we want to control by connecting to the net via LAN because WiFi has no coverage there.
Only the costs of such a cable solution are considerable and must be provided for in a home or outdoor installation (earth-gel LAN cable). The solution here could be a WiFi repeater outside - it would be cheaper than a LAN cable.
Would LAN8720 in combination with Arduino UNO or NANO not give the same?
Is it about the computing power of ESP32?
Arduino UNO and NANO doesn't have enough RAM to even load SuplaDevice on it (UNO has 2 kB).
Arduino Mega have 8 kB and it is enough to use it with Supla, however with 8 kB you can't do secured TLS connection (it takes at least 20-40 kB of RAM in order to load TLS library and to esablish secured connection with server). So neither of those will provide you secured LAN connection.

When it comes to ESP82xx vs ESP32 - well, ESP82xx are older and Espressif currently is developing ESP32 features. Most ESP82xx SDK changes are bugfixes only. It is a matter of time when those will be discontinued.
ESP32 has also bluetooth available and it seems that "smart device market" is going into direction of doing first device configuration/setup via bluetooth instead of Wi-Fi.

Wi-Fi vs Ethernet - you have to consider:
1. Security - Wi-Fi is usually encrypted but whole data is being transmitted on air, so anyone can listen. Ethernet requires physical access to cables to do the same
2. Air interface is in some places very crowded. In my previous apartment I was in range of dozens of Wi-Fi networks. Adding another Wi-Fi device doesn't help here.
3. Some people avoid wireless devices (i.e. in bedrooms) for health reasons (without going into discussion who is right or wrong). So Ethernet is a solution here.
4. When you need just single device in place of out Wi-Fi range, it may be better to install Ethernet there. It doesn't have range problems ;). Also it will take less power than Wi-Fi repeaters/APs + final device. You can power device from PoE, so you can use Ethernet cable for powering and communication. Think about gates, basements, etc.
Widzimy się na Supla Offline Party vol. 2 :!:

Return to “Ideas and concepts”