star-mesh LoRa network

Dependencies:   sx12xx_hal

start-mesh

radio chip selection

Radio chip driver is not included, because options are available.
If you're using SX1272 or SX1276, then import sx127x driver into your program.
if you're using SX1261 or SX1262, then import sx126x driver into your program.
If you're using NAmote72 or Murata discovery, then you must import only sx127x driver.

In this network, devices repeat messages to/from devices out of range of central gateway device. Appropriate for use when slightly larger batteries cost less than extra LoRaWAN gateways. This network uses LoRa transceiver directly and is not LoRaWAN. This network is appropriate for use where extra latency added from store-and-forward is of minimal consequence.

network implementation

Network achieves low-power operation by device waking up at regular intervals to check if LoRa preamble exists. If so, packet is received, otherwise devices sleeps. In this type of operation, trade-off is made between transmitter sending long preamble, and receiver waking up to receive this preamble along with associate message at the end of preamble. This long preamble is only used for request packets: the reply packet will have normal 8-symbol preamble length. This is known as asynchronous low-power operation, permitting an arbitrary number of devices to operate.

Devices start operation on the network by sending a discovery request to any devices that can hear it. Any devices which hears this discovery request will then send a discovery reply at randomized time offset relative to the request. After a pre-established time limit, the discovering device will decide which device to attach to depending on signal quality and how many hops away from the central gateway the device resides.

After device has attached to network, downlinks and uplinks can be sent to/from device. To facilitate downlinks, the devices closer to central gateway will be sent a new-device-notification to inform all devices between the central gateway and the newly attached device, which devices the new device can be reached via.

All devices have two logical interfaces to the network: An upstream interface, and a downstream interface. However, the central gateway device only has a downstream interface, because the "upstream" is only a UART interface to the user handling the user payloads on central gateway.

All devices on network are programmed with same firmware, except for gateway. In main.h #define GATEWAY is commented-out for devices on network, or is defined for central gateway device. Only one central gateway must exist on this network. The unique identifying address of device is derived from CPU unique ID registers, of which 4 byte ID number is used on this network. Using this CPU serial number permits the same binary file to be programmed into any number of devices.

network configuration

Network is configured in main.h

define in main.h
spreading factorSPREADING_FACTOR
bandwidthBW_KHZ
operating radio frequencyCF_MHZ
gateway or deviceGATEWAY
transmit powerTX_DBM

MAC layer timing scales according to LoRa symbol period. When spreading factor and/or bandwidth is changed, all network timing is scaled accordingly by MAC layer.
The transceivers used with the project operate at one datarate. This datarate is fixed, and must be defined at compile time for all devices and gateway.

low power operation

This MAC layer uses mbed eventqueue for scheduling. To enable low power operation, events.use-lowpower-timer-ticker is defined in mbed_app.json. This requires bare-metal operation to have eventqueue use low power timer, permitting deep sleep. LoRa applications such as this do not require RTOS: bare-metal mode is preferred for typical LoRa use.

application layer

User payloads are handled in app_endDevice.cpp. Uplinks are send from application layer by calling uplink(uint8_t *buffer_ptr, uint8_t length) Downlinks are handled in callback function app_downlink()

For gateway, app_gateway.cpp handles user payloads. For downlinks, an example is provided in cmd_downlink() where destination and payload is entered on serial port. All uplinks are handled in callback function gateway_uplink().

Header file app.h contains definitions common to application layer on both network central control and end device.

Note

This page describes how to use the network, for more detailed description of implementation, see details page.

serial terminal user interface

The STDIO UART is used to send and receive user-payload on the gateway, but is also available on end-devices. This serial port is configured at 115200 : 8,N,1.

commandargumentsdescription
?list commands
dldestID byte0 byte1 etcsend downlink to device (from gateway)
lslist downstream devices attached
opdBmmanually change transmit power

For the list of downstream devices, on start each row is printed directly attached device. If devices are attached further downstream, they will be subsequently printed on the same row.

testing / evaluation

Use 3 devices for testing: one gateway and two devices.
Three devices required for checking message repeating (relaying) function. The gateway device must be installed at some distance to prevent both devices from connecting directly to gateway.
Gateway needs to be located far enough away, so signal strength preference overrides hop count from gateway.

Committer:
Wayne Roberts
Date:
Tue Dec 03 09:50:00 2019 -0800
Revision:
1:fcd4c56fc56c
Parent:
0:6015834e4279
remove radio driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wayne Roberts 0:6015834e4279 1 #include "main.h"
Wayne Roberts 0:6015834e4279 2 #ifndef GATEWAY
Wayne Roberts 0:6015834e4279 3 #include "app.h"
Wayne Roberts 0:6015834e4279 4
Wayne Roberts 0:6015834e4279 5 InterruptIn but(USER_BUTTON);
Wayne Roberts 0:6015834e4279 6
Wayne Roberts 0:6015834e4279 7 /* downlink handler */
Wayne Roberts 0:6015834e4279 8 void app_downlink(uint8_t len, const uint8_t* payload)
Wayne Roberts 0:6015834e4279 9 {
Wayne Roberts 0:6015834e4279 10 unsigned n;
Wayne Roberts 0:6015834e4279 11 pc.printf("downlink %u: ", len);
Wayne Roberts 0:6015834e4279 12 for (n = 0; n < len; n++)
Wayne Roberts 0:6015834e4279 13 pc.printf("%02x ", payload[n]);
Wayne Roberts 0:6015834e4279 14
Wayne Roberts 0:6015834e4279 15 pc.printf("\r\n");
Wayne Roberts 0:6015834e4279 16 }
Wayne Roberts 0:6015834e4279 17
Wayne Roberts 0:6015834e4279 18 void button_check()
Wayne Roberts 0:6015834e4279 19 {
Wayne Roberts 0:6015834e4279 20 static uint8_t cnt = 0;
Wayne Roberts 0:6015834e4279 21
Wayne Roberts 0:6015834e4279 22 if (but.read() == 0) {
Wayne Roberts 0:6015834e4279 23 uint8_t buf[2];
Wayne Roberts 0:6015834e4279 24 buf[0] = BUTTON_PRESS;
Wayne Roberts 0:6015834e4279 25 buf[1] = cnt++;
Wayne Roberts 0:6015834e4279 26 pc.printf("appUp ");
Wayne Roberts 0:6015834e4279 27 if (uplink(buf, 2))
Wayne Roberts 0:6015834e4279 28 pc.printf("upFail\r\n");
Wayne Roberts 0:6015834e4279 29 } else {
Wayne Roberts 0:6015834e4279 30 pc.printf("appBounce\r\n");
Wayne Roberts 0:6015834e4279 31 but.enable_irq();
Wayne Roberts 0:6015834e4279 32 }
Wayne Roberts 0:6015834e4279 33 }
Wayne Roberts 0:6015834e4279 34
Wayne Roberts 0:6015834e4279 35 void button_pressed()
Wayne Roberts 0:6015834e4279 36 {
Wayne Roberts 0:6015834e4279 37 queue.call_in(10, button_check);
Wayne Roberts 0:6015834e4279 38 but.disable_irq();
Wayne Roberts 0:6015834e4279 39 }
Wayne Roberts 0:6015834e4279 40
Wayne Roberts 0:6015834e4279 41 void app_uplink_complete()
Wayne Roberts 0:6015834e4279 42 {
Wayne Roberts 0:6015834e4279 43 but.enable_irq();
Wayne Roberts 0:6015834e4279 44 }
Wayne Roberts 0:6015834e4279 45
Wayne Roberts 0:6015834e4279 46 void app_init()
Wayne Roberts 0:6015834e4279 47 {
Wayne Roberts 0:6015834e4279 48 /* nucleo: user button active low, inactive hi */
Wayne Roberts 0:6015834e4279 49 but.fall(button_pressed);
Wayne Roberts 0:6015834e4279 50 }
Wayne Roberts 0:6015834e4279 51 #endif /* !GATEWAY */