How should we connect devices to our home
network? Wireless or wired? Do these new boards from TTGO and Olimex change anything?
Interesting questions. Let’s have a closer look.
Grüezi YouTubers. Here is the guy with the Swiss
accent. With a new episode and fresh ideas around sensors and microcontrollers. Remember: If you
subscribe, you will always sit in the first row.
We all know: Wireless IOT devices are cool. But
they have some drawbacks. This is why we want to look at the alternative: Wired IOT devices:
- What are the pros and cons of both technologies?
- Which cables do I have to use for my home network and why?
- What do I have to know if I want to crimp my own Ethernet cables?
- How does the ESP32 support Ethernet, and which boards are available?
- What is the downside of using Ethernet on the ESP32?
- How complicated is it to change a “wireless” sketch to a wired one?
- Of course, we create an example to test if it works. As an MQTT sensor and actuator
Wireless is fascinating to me since I was young. It has many advantages, like no cables
to deploy and the flexibility to freely move everywhere in the range of the device. But
wireless also has disadvantages: Because information moves through the air, it is prone
to hacking and interference. A proof: All modern armies have an electronic warfare department.
Its throughput is limited because all devices within reach have to share the same channels.
In addition, the faster a connection, the more bandwidth it needs and the
more power we need for a transmission. If you want to know more about wireless
communication, watch videos #219 and #221
Wired connections are simpler, faster, and
more energy-efficient for short ranges. Because they use a “star” topology,
they have fewer resources to share. Wired connections are hard to hack
if you do not have physical access.
For me, as a rule of thumb: I use wired
connections where possible. My PC and my Raspberry server are connected
with Ethernet cables, for example.
There is another cabling possibility for home
automation: Two-wire busses like RS485. A few years ago, I probably would have thought
about using such a bus for my home. But with the standardization and the rise of Ethernet,
those busses became less and less attractive. So, in this video, I will concentrate on Ethernet.
The decision for that video was sparked by this board from TTGO. It contains an ESP32
module and an Ethernet connector. We will later see why it has this sticker. BTW:
Olimex also has new boards in the shop.
What does a typical Maker have to know about
Ethernet? Here are the most important things:
It is a very standardized cable connection that
uses RJ45 connectors on both ends. Not like power cables, which have different connectors on
both sides. The cables contain four cable pairs, and the newer ones also have shielding against
interferences. The pairs have different colors: Orange, green, blue, and brown. One wire of
a pair has a solid color, and the other not.
Two different wire diagrams exist, mainly to
confuse us. Flip a coin on which one to use and stick with it. At least for both connectors
on one cable. Because it does not matter.
These days all wires are connected straight from
one side to the other, not crossed. In the old days, we had to use crossed “patch“ cables
for specific purposes. Today the routers and switches have autosensing and adapt their pins.
Like many other things, Ethernet was invented at XEROX PARC in 1973. And of course, I have to
mention that Digital equipment corporation, one of my early employers, was responsible for
its fast distribution in the 1980s. Against IBMs token ring concept, BTW.
Back then, the speeds were low, and the cables therefore simple. When
speeds increased, cables had to become more sophisticated. To get some order, they
started to categorize them using numbers.
At the time of making this video, Cat 6, Cat 6a,
and Cat 7 cables are in focus. As we see on this list, Cat1-5 and Cat 8 cables exist, but they are
not important. Cat 1-5 are too slow, and Cat 8 is too expensive and not needed. Most of us will
use 1 or 10 Gbps networks for the next years.
The difference between Cat 6 and 7 is the
transmission speed they support, the diameter, and the price. Cat6 is suitable for 1 Gbps, Cat 7
for 10Gbps. You also get Cat 6a as a compromise, but the uplift to Cat 7 is not significant.
So Cat 7 is the right choice for new cabling.
Fortunately, Ethernet connections are backward
compatible. This means you can connect a slow device to a fast device without problems. Even if
you connect two fast devices with an old cable, they will work. Just slower. So Ethernet is
one of the more stable standards. And it is here to stay. We can depend on it.
You can buy prefabricated cables, but you can also crimp your own. Just some
recommendations: Buy a good crimper and a cheap test device to check the wiring of the
cable before you use them. Like that, you are sure that the sequence is correct and all wires
are connected. And buy the right connectors that match the Category of the cable you want to crimp.
They are different, even if they are compatible.
Ethernet offers another great feature: Power
over Internet or POE. If you want a brush-up your know-how on that topic, I suggest you watch
video #276 right after this one. In a nutshell, we can use the Ethernet cable to power our devices,
which is extremely useful. We do not need a power supply for each device and no second cable.
Modern routers like mine support POE. The standard voltage is 48 volts, and it provides enough power
for most applications. These 48 volts are, BTW, probably the reason for that “danger”
sticker in the area of the POE parts.
And now we are back to the ESP32 board.
In addition to a standard WROOM module, it has the needed circuit for Ethernet and POE.
It also has an SD card reader, if you need one. But attention: It does not have a USB to serial
chip on board. This means you either have to order the additional converter or build a cable
for your standard adapter. Here is the pinout.
Please be aware that the programming connector
does not have the standard pin distance of 2.54mm; its distance is 2mm. So I suggest ordering one
adapter with your first board. This USB-C socket is only for power. Which is not needed in my
case because power comes via the Ethernet cable.
But how does Ethernet work on the ESP32?
It uses the Wi-Fi commands. Very strange, indeed. But it is a good idea. As we later will
see, you do not need to change your sketches a lot. As a demonstrator, I created an example of
a typical application where a BME280 transmits its readings via MQTT. The device also waits for
MQTT commands and switches an LED on and off.
What are the changes from a Wi-Fi enabled
sketch? We have to include this library and to add the pin definitions for the chip.
And here, we see a function that shows us what happens and also shows us the IP address. In
setup, we have to call this function and start the Ethernet with all pins from before.
The loop stays more or less the same.
Where did I get the sketch from? I combined a
few sources and did some tests till it worked. Unfortunately, Ethernet on the ESP32 is not used
a lot up till now. Maybe this will change now?
The speed on the cable is 100Mbps max. Which
is for sure no limit for an IOT device. And what about power consumption and deep sleep? I
have to tell you: I do not care about that in this setup because we have enough energy coming
through the cable and do not need deep sleep.
A warning: I tried to use BLE with Ethernet.
Unfortunately, it did not work. I did not investigate why. Maybe you know?
Another important remark: Comparing the pins of the breakout connector
with the priority pin list of my last video, we see that we only have six freely useable pins.
And worse, we do not have the standard I2C pins available. Fortunately, the Adafruit library for
the BME280 supports free I2C pin assignment.
Looking at the Olimex diagram of a similar board,
we see that Ethernet uses eight pins of the ESP32, also the two standard I2C pins. Olimex BTW
uses the LAN8710 chip and TTGO the 8720.
Was it worthwhile for TTGO and OLIMEX to
create new Ethernet boards? What do you think?
That's it.
Summarized:
- Wired connections have three main
advantages over wireless networks
o Privacy, because it is not easy to hack them
o Speed, because it is easier to reach high speeds in a wire than over air
and because the connections do not need to share the same resources
o Energy: Over a short distance, wired communication needs less energy. And, with
POE, we can power our device without problems
- Wireless connections are
far more flexible and mobile
- Ethernet cables are categorized. Today I
suggest using Cat7 cables for new projects
- You can either buy ready-made or crimp your own
cables. Select the right connectors and a good crimper. And test all cables before you use them
- Fortunately, the ESP32 natively supports Ethernet, and an Arduino library exists
- Unfortunately, the Ethernet chip needs 8 GPIO pins, which leaves us with 12
usable pins at the breakout connector. Only 6 of them belong to the priority list.
Another four are input-only pins. GPIO 2 and 12 are strapping pins with special functions
- An example sketch connects to the MQTT server via cable, transmits a few sensor readings, and
waits for commands to switch an LED or a relay
- Ethernet uses the Wi-Fi commands.
Strange to read, but very useful because we do not have to adapt our sketches too much
- Because we cannot use the standard I2C pins, we have to “tweak” some libraries if
they do not support free pin assignment.
- All-in-all a valid alternative for
fixed devices in home automation
As always, you find all the
relevant links in the description.
I hope this video was useful or at
least interesting for you. If true, please consider supporting the channel to
secure its future existence. Thank you! Bye