|
|
Subscribe / Log in / New account

Using low-cost wireless sensors in the unlicensed bands

January 31, 2023

This article was contributed by Koen Vervloesem

When it comes to home automation, people often end up with devices supporting the Zigbee or Z-Wave protocols, but those devices are relatively expensive. When I was looking for a way to keep an eye on the temperature at home a few years ago, I bought a bunch of cheap temperature and humidity sensors emitting radio signals in the unlicensed ISM (Industrial, Scientific, and Medical) frequency bands instead. Thanks to rtl_433 and, more recently, rtl_433_ESP and OpenMQTTGateway, I was able to integrate their measurements easily into my home-automation system.

Unlicensed spectrum

Most of the radio spectrum is licensed by national regulators to specific users. This is why mobile operators or TV broadcasters have to pay a hefty licensing fee for the exclusive right to transmit on a specific frequency. The upside is that they can be relatively sure that no one else interferes with their transmissions.

However, there are also some frequency bands that are free to use by any transmitter: the ISM bands. That's why many manufacturers of doorbells, weather stations, and all sorts of wireless sensor devices choose to transmit in those bands. The specific frequencies depend on the region, as the radio regulations from the International Telecommunication Union (ITU) divide the world into three regions with their own frequency allocations.

Because devices don't have an exclusive right to transmit in the ISM band, there's much more potential for interference. However, manufacturers have to follow some rules, for instance about the permitted transmit power and the duty cycle (the maximal ratio of time transmitting over total time). That's why, in many situations, interference isn't that bad, for example when a lot of temperature sensors transmit every minute with a random start time.

To be able to read the sensor measurements, three things are needed: a receiver, an antenna, and a decoder. The first two are quite easy to find. A decoder is sometimes a bit more effort. Many of these sensors use a proprietary protocol, but luckily most don't use any encryption. There's a whole community of enthusiasts who try to reverse-engineer protocols of wireless sensors and implement decoders in open-source software.

A generic data receiver

The most well-known project to capture wireless sensor measurements is Benjamin Larsson's GPLv2-licensed rtl_433. It's a generic data receiver for the 433.92MHz, 868MHz, 315MHz, 345MHz, and 915MHz ISM bands. At the time of writing, the project's README on GitHub lists 234 supported device protocols, ranging from temperature sensors, soil-moisture sensors, wireless switches, and contact sensors to doorbells, tire-pressure monitoring systems, and energy monitors.

Rtl_433 is written in C99 and compiles on Linux, macOS, and Windows. Low resource consumption and few dependencies are two of its main design goals. This makes it possible to run rtl_433 on embedded hardware, like routers. The Raspberry Pi is also supported well.

The software supports various receivers using Osmocom's rtl-sdr or Pothosware's SoapySDR to interface with SDR (software-defined radio) devices. The rtl-sdr project builds on the discovery from more than a decade ago that a cheap DVB-T TV tuner dongle with the Realtek RTL2832U chipset can be used to build a wideband software-defined radio receiver. There are now even RTL-SDR dongles that are specifically designed for SDR purposes. So rtl-sdr talks to the RTL-SDR dongle, which returns the radio signal that is then decoded by rtl_433 and translated into sensor measurements from specific supported devices. In the same way, SoapySDR acts as a driver for other SDR devices, such as LimeSDR and HackRF One.

Using rtl_433

[RTL-SDR, antenna, and sensor]

The cheapest way to start with rtl_433 would be to buy such an RTL-SDR dongle. This also requires an antenna, preferably one with a length that works well with the wavelength for the frequency of the target devices. Some RTL-SDR dongles come in a kit with a telescoping dipole antenna, dipole base, tripod mount, and other accessories. At RTL-SDR.com there's a thorough explanation of how to use the dipole antenna kit. Something to be mindful of: when plugging the RTL-SDR dongle directly into a USB port, it will pick up a lot of RF noise from the computer. Using a short USB extension cable avoids this.

After installing udev rules for the RTL-SDR and connecting a supported RTL-SDR dongle with its antenna, just running rtl_433 finds the dongle and configures it to start listening at 433.92MHz with a sample rate of 250,000 samples per second. The software immediately starts spitting out decoded sensor measurements for all devices transmitting in the neighborhood. Rtl_433 supports a lot of options to choose the frequency, sample rate, device decoders, and output format.

Integrating rtl_433 with a home-automation system

Rtl_433 can be run as a service, for instance using a systemd service unit. George Hertz has created a multi-architecture Docker image, hertzg/rtl_433, that also runs on the Raspberry Pi. For automated processing, rtl_433 supports publishing sensor measurements to an MQTT broker, an InfluxDB time series database, or a syslog server. The MQTT export is especially interesting: many home-automation controllers, including Home Assistant and openHAB, support MQTT.

There are some caveats to using rtl_433 for home automation. First, although many of these devices transmit an ID to be able to distinguish them, their ID changes after replacing the battery. So a rule such as "if the temperature of the sensor with ID 106 is above 8 degrees, send a warning" needs to be changed after replacing the device's battery. Luckily it's quite common to run these devices a year or longer on a battery. Another drawback is that most of these devices transmit their data unencrypted. So they're not recommended for critical purposes, as people can sniff or even spoof the transmissions.

Adding support for new devices

[Spectrogram]

Rtl_433 is a collaborative effort, with many developers adding support for their wireless devices. The project has some documentation about supporting new devices. The endeavor always starts with recording test signals representing different conditions of the sensor, while taking note of what the device is showing on its display at the same time of the signal.

The project has extensive documentation about SDR concepts, I/Q (in-phase / quadrature) formats, and pulse formats. This is all necessary background information to be able to analyze the signals for adding support for a new device. There's also a step-by-step plan to analyze devices.

Rtl_433 also has a lot of supporting web-based tools to analyze signals. For instance, to visualize the I/Q spectrogram of test signals (seen above at left), to view and analyze pulses from test signals, and even to analyze bit strings to get an idea of what's in the data. All these are powerful tools that help with reverse-engineering the protocol and adding a decoder for the device to rtl_433.

Receiving sensors with a microcontroller

While rtl_433 is a powerful solution, the fact that it needs a computer with a full operating system can be a disadvantage. Some people prefer using a microcontroller, which runs more reliably and with lower power consumption. One of these solutions is Florian Robert's GPLv3-licensed OpenMQTTGateway. It not only supports receiving measurements from Bluetooth Low Energy devices, it also supports various RF devices using different receiver and decoder modules. The list of supported devices is big, but it depends on the microcontroller and receiver hardware you set up.

[Home Assistant dashboard]

The results of the measurements are published to an MQTT broker, for instance for integration in Home Assistant or another home-automation gateway. OpenMQTTGateway even supports Home Assistant's autodiscovery protocol. So all sensors the device recognizes will automatically be added into Home Assistant's devices, ready to be shown on its web-based dashboard (seen above).

On boards with an ESP32 microcontroller, OpenMQTTGateway 1.0 introduced support for a subset of the rtl_433 decoders. It does this by using NorthernMan54's GPLv3-licensed Arduino library rtl_433_ESP. This is a port of rtl_433 to the ESP32 microcontroller, using a CC1101 or SX127X receiver chip. These two are popular chips built into boards combining a microcontroller and receiver module. While rtl_433 implements signal demodulation in software, rtl_433_ESP uses the receiver chipset to do this. This limits the available device decoders, but at this writing, 81 of the 234 decoders of rtl_433 will run on the ESP32.

Conclusion

[LILYGO]

Since the first time I bought 433MHz sensors, I have put one in every room at home, in my fridge, my freezer, and on my terrace outside. I have been running rtl_433 with an RTL-SDR dongle for years on a Raspberry Pi to receive all these sensor measurements. The data are sent to the Eclipse Mosquitto MQTT broker and then fed into the home-automation controller Home Assistant.

Recently I have been evaluating OpenMQTTGateway with rtl_433_ESP on a LILYGO LoRa32 V2.1_1.6.1 433MHz board (seen at right). Since it seems to support all of my 433MHz temperature sensors, I'm considering a switch to this lower-power solution, which will free up the RTL-SDR for other purposes. However, the rtl_433_ESP's README mentions that the CC1101 receiver module is not as sensitive as the RTL-SDR dongle, resulting in only half the range. I had the same experience with the SX127X receiver on the LILYGO board. But those boards are so cheap that I could easily place a couple in various places to receive all of my sensors. Since they all send their decoded sensor values to the same MQTT broker, the result should be the same as having a single receiver with a longer range.

With this setup, Home Assistant allows me to see the temperature and humidity around the house in a web-based dashboard; I even get warnings when the temperature of the fridge or freezer rises too much. Other people are using sensors to monitor their pool temperature, their oil tank's level, water leaks, or the wind speed measured by their weather station.

All in all, these tools are quite useful for receiving measurements from a wide range of cheap wireless sensors. For a better range, more decoders, or when preferring a computer over a microcontroller, rtl_433 is a good choice. In other cases, OpenMQTTGateway with rtl_433_ESP on an ESP32 microcontroller board is a welcome addition to the toolbox of the open-source home-automation enthusiast.


Index entries for this article
GuestArticlesVervloesem, Koen


to post comments

Thanks for the quick start guide :-)

Posted Feb 1, 2023 4:08 UTC (Wed) by felixfix (subscriber, #242) [Link] (3 responses)

I used to have Hot Little Therms scattered all over, but they run RS-232, and when I switched from a tower to laptops, maintaining all those serial port connections would have required RS-232 to USB converters and had coverage only when the laptop was sitting unused. I switched to some cheap remote temperature sensors for the outside water pipes to make sure their temperature-sensitive heaters do come on appropriately and to monitor the fridge and freezers. This might be a more general purpose solution, and temperature graphs are always interesting.

Thanks for the quick start guide :-)

Posted Feb 1, 2023 10:42 UTC (Wed) by geert (subscriber, #98403) [Link] (2 responses)

For my 10-year-still-not-deployed home monitoring project, I have a bunch of one-wire DS1820 temperature sensors. I fitted and crimped them inside a standard RJ-45 connector, so they can be used with the omnipresent UTP cabling in my house. They are that small that my SO doesn't notice their presence, which is always a bonus for whatever permanent hardware you add to the house ;-)

Thanks for the quick start guide :-)

Posted Feb 1, 2023 13:50 UTC (Wed) by gevaerts (subscriber, #21521) [Link] (1 responses)

I suddenly feel less alone :) I also got a bunch of those sensors for that very same purpose ten years ago that still need to be installed.

Thanks for the quick start guide :-)

Posted Feb 1, 2023 16:52 UTC (Wed) by jacmet (subscriber, #19734) [Link]

Hah, me too - But mine are at least running!

Using low-cost wireless sensors in the unlicensed bands

Posted Feb 9, 2023 8:36 UTC (Thu) by callegar (guest, #16148) [Link] (4 responses)

> Since the first time I bought 433MHz sensors, I have put one in every room at home, in my fridge, my freezer, and on my terrace outside

May I ask which sensors? To the best of my experience, these sensors get sold as small consumer kits. For instance, 3 temperature/humidity sensors + a display station including another sensor (I happen to have a Bresser kit like this at home).
If you buy it in this way, you can get something like 3 RF sensors for ~35 € on places like Amazon, which gives you a sensor for about 10 €, which is cheaper than zigbee solutions that often go for ~60 € for 3 sensors on similar places.

However it remains unclear to me how you build a larger network. It is my understanding that you cannot just buy two kits with 3 sensors each from the same brand to get 6 sensors, because those will use the same modulation and ids. Is this the case?

Furthermore, is it possible to get these sensors for less than 10 € each somewhere? Even if it is 100% the price difference of 10€ does not seem to completely justify the choice of going for a 433MHz totally nonstandard solution with potential interference issues wrt a way more standardized zigbee solution.

Using low-cost wireless sensors in the unlicensed bands

Posted Feb 9, 2023 10:21 UTC (Thu) by mjg59 (subscriber, #23239) [Link] (1 responses)

I've used some Acurite sensors. They support broadcasting on three channels, and the base stations are configured to show the data from each channel (A, B and C). But each sensor also broadcasts an additional ID, and handling that through rtl433_sdr or something similar means it's possible to disambiguate the sensors even if they're on the same channel. I don't know if all other platforms in the 433MHz spectrum behave equivalently, though.

Using low-cost wireless sensors in the unlicensed bands

Posted Feb 9, 2023 13:07 UTC (Thu) by callegar (guest, #16148) [Link]

Thanks, the acurite sensors are way too expensive in Italy, but the information is quite useful. I guess the best that I can do is to experiment with my sensors and see if they also have an id associated to them in addition to the 3 channels.

Using low-cost wireless sensors in the unlicensed bands

Posted Feb 10, 2023 10:41 UTC (Fri) by eduperez (guest, #11232) [Link]

For the outdoor zones, I use the cheapest (~$10) 433MHz sensors I could find on AliExpress, it looks exactly like the one in the first photo. Ignoring the issue with the channel changing each time the batteries are replaced, it works perfectly fine. For the indoor zones, I use the cheapest (~$5) BLE sensors from Xiaomi I could find on AliExpress.

Using low-cost wireless sensors in the unlicensed bands

Posted Feb 11, 2023 17:16 UTC (Sat) by koenvervloesem (subscriber, #56573) [Link]

I just bought a bunch of the pictured DANIU sensors a few years ago. You can still find them on Banggood, but they cost more than 10 € now. At that time there was a big sale, so I was able to get them for around 5 € per piece. Waiting for the right time can be interesting. They each transmit a unique ID, by the way.

I never bought these consumer kits, so I'm not 100% sure about how to distinguish them by their ID.


Copyright © 2023, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds