In a perfect world everything is easy, in a real world...
...even a long range radio may not be enough: when there are obstacles, walls, non ideal placement of nodes.
Your nodes are out of range of your gateway? You need to add a node but...? You need a repeater?
No, you need a mesh ( and maybe a few more nodes )!
Here the steps to setup our mesh network ( we will cover each separately ):
1) build the mesh between nodes - easy ( covered here )
2) bridge to internet and low power nodes - intermediate
3) ota update - intermediate
4) adding mqtt/http/db/graphing/debugging capability to the bridge
5) a complete project...
Let's start from the first step.
After programming one board with the node.ino software and one board with the bridge.ino software you should have something like this:
NOTE1: If you want to program additional nodes board you need to change the address of the board ( line 23 ), every board should have a different address
NOTE2: These examples are adapted from the original radiohead ones, with minimal code changes for esp32 boards compatibility and changed the names: from client to node and from server to bridge ( this sound more 'natural' to me an these are the names we will use in next steps )
this is the log from a node and the bridge:
Node code summary:
- include necessary libraries ( see lines 14-16 )
- define node and bridge addresses ( see lines 19-20 )
- define/initialize the objects we need to handle our meshing library ( see lines 48, 51, 58 )
- initialize lora parameters ( see line 64, 66, 67, 89 )
- in line 64 power settings: 2dBm is ok for indoor testing ( 20 for real application )
- in line 66 frequency setting: set accordingly to your module and location ( 868 MHz in Europe, 915MHz in USA, 433MHz in Asia... )
- send the message 'Hello World!' to the bridge every 3 seconds ( see line 108 )
You can add other nodes and they will be automatically discovered and added to the mesh ( after a small delay )
Bridge code summary:
- include necessary libraries ( see lines 14-16 )
- define bridge address ( see lines 19 )
- define/initialize the objects we need to handle our meshing library ( see lines 47, 50, 57 )
- initialize lora parameters ( see line 63, 65, 66, 88 )
- wait for a message and acknowledges it ( see line 103 )
Now you know that the nodes ( a few inches apart ) on your desk are able to communicate.
So lets space a node until it is out of the mesh range ( until the server's serial log stops reporting the node messages ) at this point add a new node 'in between' ( let's call it 'the-node-in-the-middle' )... and after a small delay... the original node is automagically reconnected.
If you find this a little bit impractical ( I mean moving the nodes a few hundred meters apart ) here a few hints:
- lower the power of the nodes ( setting the power to 2 dBm for example ) so that e few walls inside your house could be enough ( well... some walls )
- use the 'test network' function of the radiohead library, in file RHRouter.h near line 33, uncomment one of the four #defines RH_TEST_NETWORK 1-4, each define simulate a network as shown in the following image ( in which a few nodes are mutually invisible ), simple as that... but remember to comment the define when your testing are done
Good job, your mesh is indeed self configuring, self healing, self recovering, self... in a word resilient ( did you say resilient this morning? ).
NOTE It is never a good idea to keep the nodes too close to each other ( as shown on the video ; - )
Air TimeLong range = low data rate = long air time
This means, for example, that if we use:
a) 125KHz bandwidth, SF = 12 and Code Rate = 4/8
- a 1 byte payload ( + 4 bytes mesh overhead ) will be transmitted in 0.92s ( roughly 1.2s measured by me )
- a 12 byte payload 'Hello World!' ( + 4 bytes mesh overhead ) will be transmitted in 1.71s ( roughly 1.7s measured by me )
These are the RadioHead library fixed settings ( useful to calculate air time ):
- 8 symbol PREAMBLE
- Explicit header with header CRC (default CCITT, handled internally by the radio)
- 4 octets HEADER: (TO, FROM, ID, FLAGS)
- 0 to 251 octets DATA
- CRC (default CCITT, handled internally by the radio)
SX127x are able to detect channel activity ( from semtech datasheet: radio receiver captures LoRa preamble symbol of data from the channel ), in roughly 2*Ts ( symbol time ), which is quite fast.
Newer semtech radio sx1262 is able to detect CAD activity during preamble or data symbols ( unfortunately RadioHead library currently does not support sx1262 ).
Note- The radiohead mesh library does not guarantee the delivery of the message to the final destination ( the ack received after every transmission means only that the message has travelled to the first hop ). And in lots of cases this is enough.
- If you want a proof that the message has been delivered you can add a reply in the bridge code. You can find this small addition in bridge_polite.ino ( it is always polite to answer at every request ).
- Any esp32 board + sx1276/sx1278 lora radio can be used, but currently RadioHead library doesn't support sx1262 radio
This is the first ( and easy ) step of our job.
In the next step we'll continue adding a bridge to the 'net' and an esp32 low power node.
Comments