Arduino: How you can make and set up a Mini Rete LoRa
Arduino and wireless network LoRa (long range)The document created by Paolo Bonelli is partially reproduced: it explains really well: How you can make and set up a Mini Rete LoRa ... ... and monitor (almost) anything
DOWNLOAD PDF version 06 Feb. 2023 at bottom of this page
Table of Contents
- What is a MiniReteLoRa and what is it for?
- Why should I choose a MiniReteLoRa?
- How do you make it?
- The board: LILYGO TTGO T-Deer Pro Mini, as a sensor node
- The board: LILYGO TTGO LoRa32 T3_V1.6.1 (LoRa32 V2.1_1.6), as RX node
- The board : LILYGO TTGO LORA32 868/915Mhz (LoRa32 V1.0), as RX node
- The structure of the sent message
- The program for a generic TX node: TX_Generic
- The program for the receiving node RX_Generic_autoconnect
- RSSI signal level and antennas
- Data Platform
- RX Node Operation
- Reliability test of a MiniReteLoRa
PrefaceToday we talk a lot about IOT (Internet Of Things), meaning objects scattered around the house, the factory or even on the open field, that send data to the Internet in order to monitor environmental parameters and eventually activate alarm messages.
Such systems are already on the market, but, in addition to the their price, the main obstacle for many people looking for a particular application is their lack of flexibility. In other words, a lot of people need to build their IOT system by putting together individual pieces of hardware and software like a LEGO.
Think of a farmer who needs weather variables on the own field, a small town community who needs to monitor rainfall, river levels or landslides in order to have alarm on their cell phone. OK, these guys don't know the basic of electronics but the Arduino revolution taught us that many people can learn very fast to manage these stuff. Furthermore, makerspaces and fablabs are almost everywhere and their communities often make themselves available to ordinary people to help them.
But what technologies can a guy, who wants to make and set up an IOT system, use?
For a private person with little familiarity with electronics, a data transmission technology is needed that uses cheap hardware and possibly easy-to-use open source software; it may also be useful for these systems to work outside the walls of the house, outdoors, where there is no electricity or WiFi facilities. In these cases LoRa transmission technology is an good opportunity and it can be used everywhere.
My job is just that: building pieces of IOT network with inexpensive materials and open source software that should be easy to modify to adapt it to your needs. Minimal Arduino experience and little DIY skills are required.
In this article I want to explain how to build a network of sensors that transmit data over the Internet at low cost, taking the first steps towards an exciting experience, perhaps on a par with the one experienced by Guglielmo Marconi at the end of the XIX century, when, in the park of his villa, he saw, with great jubilation on his rudimentary receiver, a signal transmitted via radio and sent by a transmitter few miles (kilometers) away!
What is a MiniReteLoRa and what is it for?
Let's start with some examples of practical applications:
- in a cultivated field there is the need to measure the temperature of the air and the ground, the water content in the soil and so on, but we are far from a house with WiFi and electric energy;
- still in the countryside, we have to control a pump to lift water from a well and fill a tank when it is about to empty, but this is located quite far away; we also want the pump to turn on automatically and follow the operation of the whole system on the Internet;
- we have a greenhouse where it is important to keep the air temperature under control at various points to manage the heating systems or the opening of the air vents, but we don't want to put a lot of electric wires in the middle of the plants;
- we want to install on a hill a small network of rain gauges and vibration sensors to alert the population of a small village in the event of a flood or landslide;
Monitoring air and water quality can help to prevent environmental disasters alerting people when the level of pollutants is too high
All of these applications require sensors, data acquisition and transmission electronics, and a receiver node located far away.
What system can be used to transmit the data? The GSM-4G network? A WiFi network? In the first case we would have to pay a fee and equip each sensor-card with a SIM with an energy consumption that does not allow us to power the node with a battery for months; in the second case we would need sensor-boards equipped with WiFi, again with a non-negligible battery consumption and a WiFi/GSM router for Internet with a coverage that could not exceed 300-600 ft (100-200 mt.)
For some years a new transmission technology has become available with the relative Hw and Sw: it is LoRa (Long Range). The acronym indicates a radio signal modulation technique which allows for great sensitivity at the receiving point, resulting in a coverage of kilometers, as the name implies, with the transmitter's output power reduced to a minimum and short transmission times for each sensor-board.
LoRa, in Europe, uses the free 868 MHz (915 MHz in USA) band provided you don't occupy it for more than 1% of the time. Imagine a sensor that transmits small quantity of data every 5 minutes with a transmission time of 70 ms (milliseconds), the bandwidth occupation percentage is about 0.02% which would allow us to have up to 50 sensor boards scattered everywhere!!
The typical consumption of a sensor board is 140 mA in transmission and 0.30 mA at rest, (with the CPU in sleep), therefore the average consumption, always for the same example, is 0.32mA. In these evaluations I have not taken into account the consumption of the sensors, which in any case can be negligible if these are activated only shortly before the transmission of their data.
The egg of Columbus for our needs?
Yes, but what difficulties are encountered in building such a network? Is there something turnkey on the market? Do you have to be super expert in Hw/Sw?
Here the world of open source helps us: that universe of knowledge available on the Net, free and often made easy by skilled disseminators. In addition, there is a low-cost hardware market that is expanding more and more, offering us sensors, microcontrollers and easy-to-wire solutions. If we are already able to connect a sensor to a microcontroller like Arduino, we can with little effort enter the world of the Internet of Things (IOT) that uses LoRa and build our own MiniReteLoRa.
Now I will try to describe the architecture of what I call MiniReteLoRa (literally in english mini network LoRa), a completely autonomous network of sensors-transmitters and concentrator-receiver, which does not need to rely on particular external servers and submit to complex protocols.
Figure 1 - Difference between MiniReteLoRa and LoRaWAN
A MiniReteLoRa is a technology that allows the acquisition and transmission of quantities detected by sensors, located in mainly outdoor locations, therefore without WiFi connectivity, requiring little energy and low costs. However, nothing prevents us from using this technique even in a closed environment, such as our home or factory.
While the term LoRa indicates the modulation technology of a radio carrier, patented by the Semtech company, the terms MiniReteLoRa and LoRaWAN are used to define a type of device architecture, with their software, which exploit LoRa technology to transmit and receive data .
The MiniReteLoRa, which I describe here, should not be confused with the LoRaWAN protocol, created for a more complex network infrastructure and more suitable for commercial use. LoRaWAN is made for many transmitter nodes and some receivers (gateways) connected on the Internet to a network server managed by the service provider. The LoRaWAN architecture, having multiple gateways in the network, offers greater spatial coverage.
In the Figure 1 I try to illustrate the difference between these two approaches in a simple way, while the Figure 2 shows the detailed scheme of a LoRaWAN network.
Figure 2 Detailed scheme of LoRaWAN (from www.internet4things.it)
I designed the MiniReteLoRa to work without third-party infrastructures, so it can be used anywhere and implemented by anyone.
The MiniReteLoRa has an architecture that includes:
- several detector/transmitter nodes (TX) which perform the function of acquiring data from the sensors, packaging them in a message which also reports some information on the node and transmitting these messages in broadcast mode with LoRa technology;
- one receiver node (RX) capable of receiving and selecting the messages sent by the TX nodes, extracting the data and presenting them in various ways, such as: display, LED, data logger. Another possibility of the RX node is that of being able to connect to the Internet via a WiFi hotspot and access a server on which to store the received data.
The TX and RX nodes consist of hardware boards equipped with a microcontroller, programmable with the Arduino IDE, and a LoRa radio module, which can be managed with special libraries. These boards can perform both the TX and RX functions, only by changing the software.
Data transmission can take place periodically, independently controlled by each TX node program, or following an external event recorded by the sensors. In any case it is a one-way transmission, the TX is not expected to send data upon request of an RX. This last feature is necessary if the TX node is to consume as little energy as possible, in fact the permanent listening state consumes more energy than a periodic transmission.
Typically a TX, which transmits a short 30 byte message for 70 milliseconds every 5 minutes and then goes into a sleep state for the rest of the time, can also consume only 0.3 -0.4 mA, while an RX always listening for messages consumes even 100 times as much.
For this reason, the RX nodes must be powered with an unlimited energy source or large-capacity batteries.
This need is even more evident if the RX node is connected to other boards that perform data logger functions or send data over the Internet with WiFi.
In certain particular applications, the TX node, after its switch-on, can listen to a start message sent by RX, for example to command the start of several TXs at different times, however, the need always remains for the TX to perform exclusively the data transmission.
Despite the possibility of setting small frequency variations near the main frequency of 868.0 MHz by software, all the TX nodes and the RX node of a MiniReteLoRa must operate on the same frequency. Possible interferences are minimized if the time between two transmissions of the TX nodes is long compared to the frequency occupation time at the moment of transmission. Being the latter time of the order of fractions of a second, a transmission periodicity of a few tens of seconds can be sufficient to guarantee a very low probability of interference between some TX nodes. Even better would be to set a different transmission periodicity for each node, perhaps equal to a sequence of prime numbers of seconds.
At this point in my explanation, someone will be asking a question:
Is a network where data travels one way reliable? In fact there is no feedback between the receiver and the transmitter, if a data is lost the transmitter will never know it.
I try to answer with two arguments:
- The LoRa transmission system, managed by the library that we will use in our applications, has its own internal data integrity control. So if an incoming message to the RX is corrupted, it will not be processed.
- Reliability must therefore be evaluated on the basis of any lost messages compared to the total (messages transmitted but not received or not processed due to internal errors). But the redundancy of messages will increase the reliability of the mini network. Let me explain better: if, for example, one datum every 10 minutes is enough to know the trend over time of an environmental quantity, the TX node will transmit it three or four times every 10 minutes, in order to be sure that at least one arrives at the correct destination.
Why should I choose a MiniReteLoRa?
- Inexpensive hardware;
- Low energy consumption;
- Simple and easy to understand software;
- Consolidated libraries;
- Compatibility with Arduino and its programming environment;
- Reception and archiving of data locally without the need for external servers;
- Possible re-transmission of data over the Internet to different servers.
How do you make it?Now let's talk first about the hardware needed to make a MiniReteLoRa and then about the software. For simplicity I present only three microcontroller boards, successfully tested by me; but it is good to know that MiniReteLoRa can also be built with other boards by making only very small changes to the software that I will introduce later.
-CONTINUE - - - - -> please download the complete document in PDF format, with links for all the sketches to try on Arduino, this is the link:
If you liked this article, click on one or more banner ads... we know they are boring and intrusive, but they allow us to pay server costs without making you spend anything. Thank you