Blue digital cloud

Resource

From Wifi to LoRaWAN: A Step-by-Step Guide to Superior IoT Connectivity - Part 3

Published on 09 Jul, 2024 by Neil

In the previous two posts, we have talked about LoRaWAN hardware selection, library porting to a Particle P2 module and the failure to receive a Join Accept response from the LoRa Network Server (LNS).

In the final post we will be looking at the debug of the missing Join Accept response, an alternative LoRaWAN module and communication between a device and the AWS LPWAN services.

Debugging the missing Join Accept response.

Various tools were used to debug the missing Join Accept response. These include a SDRplay RSP1A Software Defined Radio receiver, the extended debug output from the Basic Station gateway running on a Raspberry Pi along with the RAK2287 hardware.

The register configuration of the SX1262 was checked to make sure that the receiver was programmed for the correct frequency. The gateway response LoRa chirps were received (but not decoded, although that is possible using Gnu Radio (GitHub - rpp0/gr-lora: GNU Radio blocks for receiving LoRa modulated radio messages using SDR).

868.000MHz LoRa chirp received during debug.

868.000MHz LoRa chirp received during debug. The low SDR sample rate and low-spreading factor has turned the LoRa symbols into discontinuous bursts. The synchronisation up-chirps and start of frame delimiter can be clearly seen.

A Preamble detect interrupt was seen and the internal interrupt status register was inspected which did not yield an clues as to why the LoRa packet was missed.

RAKWireless manufacture a range of IoT wireless modules that cover both gateways and devices for LoRaWAN. A RAK2287 was obtained along with the PCIe carrier board. This was mounted on a Raspberry Pi 4.

Raspberry Pi 4 and RAK2287 LoRaWAN gateway

Raspberry Pi 4 and RAK2287 LoRaWAN gateway

A port of the Semtech reference gateway code (Basic Station) was used and the gateway was configured to run on the AWSLPWAN.

The Solution

After a significant period of investigation, a small change to the receive window timing solved the problem and the SX1262 could connect and transmit data to the AWS LPWAN device.

The rest of this blog post describes successful use of the P2-Core1262-HF and the replacement of the Core1262-HF.

RAK2287 Gateway on AWS LPWAN

The debug data extracted from the gateway is extremely helpful - it details transmit frequencies, spreading factors, type of message etc. It is a useful tool for bringing up a LoRaWAN MAC port.

Here is example output from when the Basic Station gateway application connects to the AWS LoRaWAN Network Server (LNS):

AWS View of the RAK2287 Gateway

AWS View of the RAK2287 Gateway

The output from Basic Station as it connects.

pi@rak-gateway:~/balena $ ./basicstation/examples/rak2287/reset_lgw.sh start RAK2287 reset through GPIO17... pi@rak-gateway:~/balena $ /home/pi/balena/basicstation/build-corecell-std/bin/station 2023-03-22 11:33:59.490 [SYS:INFO] findDefaultEui -> protoEuiSrc /sys/class/net/eth0/address - protoEUI 251096701622022 2023-03-22 11:33:59.491 [SYS:INFO] Logging : stderr (maxsize=10000000, rotate=3) 2023-03-22 11:33:59.491 [SYS:INFO] Station Ver : 2.0.5(corecell/std) 2022-12-14 09:48:42 2023-03-22 11:33:59.491 [SYS:INFO] Package Ver : (null) 2023-03-22 11:33:59.491 [SYS:INFO] proto EUI(x) : 0:e45f:1b4:5706 (/sys/class/net/eth0/address) 2023-03-22 11:33:59.491 [SYS:INFO] prefix EUI : ::1 (builtin) 2023-03-22 11:33:59.491 [SYS:INFO] Station EUI : e45f:1ff:feb4:5706 2023-03-22 11:33:59.491 [SYS:INFO] Station home: ./ (builtin) 2023-03-22 11:33:59.491 [SYS:INFO] Station temp: /var/tmp/ (builtin) 2023-03-22 11:33:59.693 [TCE:INFO] Starting TC engine 2023-03-22 11:33:59.694 [any:INFO] ./tc.trust: cert. version : 3 serial number : A7:xx:xx:xx:xx:xx:xx:7F issuer name : C=US, O=Starfield Technologies, Inc., OU=Starfield Class 2 Certification Authority subject name : C=US, ST=Arizona, L=Scottsdale, O=Starfield Technologies, Inc., CN=Starfield Services Root Certificate Authority - G2 issued on : 2009-09-02 00:00:00 expires on : 2034-06-28 17:39:16 signed using : RSA with SHA-256 RSA key size : 2048 bits basic con2023-03-22 11:33:59.700 [any:INFO] ./tc.crt: cert. version : 3 serial number : A8:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:D4 issuer name : OU=Amazon Web Services O=Amazon.com Inc. L=Seattle ST=Washington C=US subject name : CN=AWS IoT Certificate issued on : 2023-03-21 16:59:00 expires on : 2049-12-31 23:59:59 signed using : RSA with SHA-256 RSA key size : 2048 bits basic constraints : CA=false key usage : Digital Signature 2023-03-22 11:33:59.700 [AIO:INFO] 2023-03-22 11:33:59.789 [AIO:XDEB] [3] ws_connecting state=1 2023-03-22 11:33:59.789 [TCE:INFO] Connecting to INFOS: wss://A135KGNL1C78AI.lns.lorawan.eu-west-1.amazonaws.com:443 2023-03-22 11:33:59.789 [CUP:INFO] Starting a CUPS session in 0 seconds. 2023-03-22 11:33:59.789 [CUP:INFO] Starting a CUPS session now. 2023-03-22 11:33:59.789 [CUP:INFO] Connecting to CUPS ... https://xxxxxxxxxxxx.cups.lorawan.eu-west-1.amazonaws.com:443 (try #1) 2023-03-22 11:33:59.790 [any:INFO] ./cups.trust: cert. version : 3 serial number : A7:xx:xx:xx:xx:xx:xx:7F issuer name : C=US, O=Starfield Technologies, Inc., OU=Starfield Class 2 Certification Authority subject name : C=US, ST=Arizona, L=Scottsdale, O=Starfield Technologies, Inc., CN=Starfield Services Root Certificate Authority - G2 issued on : 2009-09-02 00:00:00 expires on : 2034-06-28 17:39:16 signed using : RSA with SHA-256 RSA key size : 2048 bits basic c2023-03-22 11:33:59.796 [any:INFO] ./cups.crt: cert. version : 3 serial number : 52:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:27 issuer name : OU=Amazon Web Services O=Amazon.com Inc. L=Seattle ST=Washington C=US subject name : CN=AWS IoT Certificate issued on : 2023-03-21 16:55:24 expires on : 2049-12-31 23:59:59 signed using : RSA with SHA-256 RSA key size : 2048 bits basic constraints : CA=false key usage : Digital Signature 2023-03-22 11:33:59.796 [AIO:INFO] 2023-03-22 11:33:59.876 [CUP:VERB] Retrieving update-info from CUPS https://xxxxxxxxxxxx.cups.lorawan.eu-west-1.amazonaws.com:443... 2023-03-22 11:33:59.876 [AIO:XDEB] [3] ws_connecting state=1 2023-03-22 11:34:00.067 [AIO:XDEB] [3] ws_connecting state=1 2023-03-22 11:34:00.067 [AIO:XDEB] [3] ws_connecting state=2 2023-03-22 11:34:00.087 [AIO:XDEB] [3] ws_connecting state=3 2023-03-22 11:34:00.087 [AIO:XDEB] [3|WS] > {"router":"e45f:1ff:feb4:5706"} 2023-03-22 11:34:00.092 [AIO:XDEB] [4] http_read state=4 2023-03-22 11:34:00.104 [AIO:XDEB] [3|WS] < {"router":"e45f:xxxx:xxxx:xxxx","muxs":"e45f:01ff:feb4:5706","uri":"wss://A135KGNL1C78AI.lns.lorawan.eu-west-1.amazonaws.com:443/gateway/e45f01fffeb45706"} 2023-03-22 11:34:00.104 [TCE:INFO] Infos: e45f:xxxx:xxxx:xxxx xxxx:xxxx:xxxx:xxxx wss://xxxxxxxxxxxx.lns.lorawan.eu-west-1.amazonaws.com:443/gateway/xxxxxxxxxxxx 2023-03-22 11:34:00.104 [AIO:DEBU] [3] ws_close reason=1000 2023-03-22 11:34:00.104 [AIO:XDEB] [3] ws_closing_w state=5 2023-03-22 11:34:00.104 [AIO:DEBU] Echoing close - reason=1000 2023-03-22 11:34:00.105 [AIO:DEBU] [3|WS] Server sent close: reason=1006 2023-03-22 11:34:00.105 [AIO:DEBU] [3] WS connection shutdown... 2023-03-22 11:34:00.105 [any:INFO] ./tc.trust: cert. version : 3 serial number : A7:xx:xx:xx:xx:xx:xx:7F issuer name : C=US, O=Starfield Technologies, Inc., OU=Starfield Class 2 Certification Authority subject name : C=US, ST=Arizona, L=Scottsdale, O=Starfield Technologies, Inc., CN=Starfield Services Root Certificate Authority - G2 issued on : 2009-09-02 00:00:00 expires on : 2034-06-28 17:39:16 signed using : RSA with SHA-256 RSA key size : 2048 bits basic con2023-03-22 11:34:00.107 [any:INFO] ./tc.crt: cert. version : 3 serial number : A8:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:D4 issuer name : OU=Amazon Web Services O=Amazon.com Inc. L=Seattle ST=Washington C=US subject name : CN=AWS IoT Certificate issued on : 2023-03-21 16:59:00 expires on : 2049-12-31 23:59:59 signed using : RSA with SHA-256 RSA key size : 2048 bits basic constraints : CA=false key usage : Digital Signature 2023-03-22 11:34:00.107 [AIO:INFO] 2023-03-22 11:34:00.157 [AIO:XDEB] [3] ws_connecting state=1 2023-03-22 11:34:00.157 [TCE:VERB] Connecting to MUXS... 2023-03-22 11:34:00.157 [AIO:XDEB] [4] http_read state=4 2023-03-22 11:34:00.157 [AIO:DEBU] [4] HTTP connection shutdown... 2023-03-22 11:34:00.157 [CUP:INFO] Interaction with CUPS done (no updates) - next regular check in 1d 2023-03-22 11:34:00.178 [AIO:XDEB] [3] ws_connecting state=1 2023-03-22 11:34:00.179 [AIO:XDEB] [3] ws_connecting state=1 2023-03-22 11:34:00.182 [AIO:XDEB] [3] ws_connecting state=1 2023-03-22 11:34:00.277 [AIO:XDEB] [3] ws_connecting state=1 2023-03-22 11:34:00.277 [AIO:XDEB] [3] ws_connecting state=2 ERROR: Failed to stop TX trigger ERROR: Failed to stop TX trigger 2023-03-22 11:34:00.298 [AIO:XDEB] [3] ws_connecting state=3 2023-03-22 11:34:00.298 [TCE:VERB] Connected to MUXS. 2023-03-22 11:34:00.298 [AIO:XDEB] [3|WS] > {"msgtype":"version","station":"2.0.5(corecell/std)","firmware":null,"package":null,"model":"corecell","protocol":2,"features":"rmtsh"} 2023-03-22 11:34:00.317 [AIO:XDEB] [3|WS] < {"msgtype":"router_config","NetID":null,"JoinEUI":null,"region":"EU868","hwspec":"sx1301/1","freq_range":[863000000,870000000],"DRs":[[12,125,0],[11,125,0],[10,125,0],[9,125,0],[8,125,0],[7,125,0],[7,250,0],[0,0,0],[-1,0,0],[-1,0,0],[-1,0,0],[-1,0,0],[-1,0,0],[-1,0,0],[-1,0,0],[-1,0,0]],"sx1301_conf":[{"radio_0":{"enable":true,"freq":867500000},"radio_1":{"enable":true,"freq":868500000},"chan_FSK":{"enable":true},"chan_Lora_std":{"enable":true,"radio":1,"if" 2023-03-22 11:34:00.317 [AIO:XDEB] [3|WS] . :-200000,"bandwidth":250000,"spread_factor":7},"chan_multiSF_0":{"enable":true,"radio":0,"if":-400000},"chan_multiSF_1":{"enable":true,"radio":0,"if":-200000},"chan_multiSF_2":{"enable":true,"radio":0,"if":0},"chan_multiSF_3":{"enable":true,"radio":0,"if":200000},"chan_multiSF_4":{"enable":true,"radio":0,"if":400000},"chan_multiSF_5":{"enable":true,"radio":1,"if":-400000},"chan_multiSF_6":{"enable":true,"radio":1,"if":-200000},"chan_multiSF_7":{"enable":true 2023-03-22 11:34:00.317 [AIO:XDEB] [3|WS] . ,"radio":1,"if":0}}],"protocol":0,"regionid":0} 2023-03-22 11:34:00.317 [S2E:WARN] Unknown field in router_config - ignored: protocol (0xFD309030) 2023-03-22 11:34:00.317 [S2E:WARN] Unknown field in router_config - ignored: regionid (0xE6FFB211) 2023-03-22 11:34:00.317 [RAL:INFO] Lora gateway library version: Version: 1.0.5; 2023-03-22 11:34:00.319 [RAL:VERB] Connecting to device: /dev/spidev0.0 2023-03-22 11:34:00.319 [RAL:DEBU] SX130x txlut table (0 entries) 2023-03-22 11:34:00.319 [RAL:VERB] SX1302 rssi_tcomp: coeff_a=0.000 coeff_b=0.000 coeff_c=0.000 coeff_d=0.000 coeff_e=0.000 2023-03-22 11:34:00.319 [RAL:VERB] SX1302 rxrfchain 0: enable=1 freq=867.5MHz rssi_offset=-166.000000 type=5 tx_enable=1 2023-03-22 11:34:00.319 [RAL:VERB] SX1302 rxrfchain 1: enable=1 freq=868.5MHz rssi_offset=-166.000000 type=5 tx_enable=0 2023-03-22 11:34:00.319 [RAL:VERB] SX1302 ifchain 0: enable=1 rf_chain=0 freq=-400000 bw=0 SF=0 sync_word=0/0 2023-03-22 11:34:00.319 [RAL:VERB] SX1302 ifchain 1: enable=1 rf_chain=0 freq=-200000 bw=0 SF=0 sync_word=0/0 2023-03-22 11:34:00.319 [RAL:VERB] SX1302 ifchain 2: enable=1 rf_chain=0 freq=0 bw=0 SF=0 sync_word=0/0 2023-03-22 11:34:00.319 [RAL:VERB] SX1302 ifchain 3: enable=1 rf_chain=0 freq=200000 bw=0 SF=0 sync_word=0/0 2023-03-22 11:34:00.319 [RAL:VERB] SX1302 ifchain 4: enable=1 rf_chain=0 freq=400000 bw=0 SF=0 sync_word=0/0 2023-03-22 11:34:00.319 [RAL:VERB] SX1302 ifchain 5: enable=1 rf_chain=1 freq=-400000 bw=0 SF=0 sync_word=0/0 2023-03-22 11:34:00.319 [RAL:VERB] SX1302 ifchain 6: enable=1 rf_chain=1 freq=-200000 bw=0 SF=0 sync_word=0/0 2023-03-22 11:34:00.319 [RAL:VERB] SX1302 ifchain 7: enable=1 rf_chain=1 freq=0 bw=0 SF=0 sync_word=0/0 2023-03-22 11:34:00.319 [RAL:VERB] SX1302 ifchain 8: enable=1 rf_chain=1 freq=-200000 bw=5 SF=7 sync_word=0/0 [STD] Explicit header 2023-03-22 11:34:00.319 [RAL:VERB] SX1302 ifchain 9: enable=1 rf_chain=0 freq=0 bw=0 SF=0 sync_word=0/0 2023-03-22 11:34:00.319 [RAL:VERB] Station device: /dev/spidev0.0 (PPS capture disabled) 2023-03-22 11:34:02.860 [RAL:VERB] Concentrator started (2s540ms) 2023-03-22 11:34:02.860 [S2E:INFO] Configuring for region: EU868 -- 863.0MHz..870.0MHz 2023-03-22 11:34:02.860 [S2E:VERB] DR0 SF12/BW125 2023-03-22 11:34:02.860 [S2E:VERB] DR1 SF11/BW125 2023-03-22 11:34:02.860 [S2E:VERB] DR2 SF10/BW125 2023-03-22 11:34:02.860 [S2E:VERB] DR3 SF9/BW125 2023-03-22 11:34:02.860 [S2E:VERB] DR4 SF8/BW125 2023-03-22 11:34:02.860 [S2E:VERB] DR5 SF7/BW125 2023-03-22 11:34:02.860 [S2E:VERB] DR6 SF7/BW250 2023-03-22 11:34:02.860 [S2E:VERB] DR7 FSK 2023-03-22 11:34:02.860 [S2E:VERB] DR8 undefined 2023-03-22 11:34:02.860 [S2E:VERB] DR9 undefined 2023-03-22 11:34:02.860 [S2E:VERB] DR10 undefined 2023-03-22 11:34:02.860 [S2E:VERB] DR11 undefined 2023-03-22 11:34:02.860 [S2E:VERB] DR12 undefined 2023-03-22 11:34:02.860 [S2E:VERB] DR13 undefined 2023-03-22 11:34:02.860 [S2E:VERB] DR14 undefined 2023-03-22 11:34:02.860 [S2E:VERB] DR15 undefined 2023-03-22 11:34:02.860 [S2E:VERB] TX power: 14.0 dBm EIRP 2023-03-22 11:34:02.860 [S2E:VERB] JoinEUI list: 0 entries 2023-03-22 11:34:02.860 [S2E:VERB] NetID filter: FFFFFFFF-FFFFFFFF-FFFFFFFF-FFFFFFFF 2023-03-22 11:34:02.860 [S2E:VERB] Dev/test settings: nocca=0 nodc=0 nodwell=0 2023-03-22 11:34:44.871 [SYN:INFO] MCU/SX130X drift stats: min: +0.0ppm q50: -1.4ppm q80: -1.9ppm max: -2.4ppm - threshold q90: -1.9ppm 2023-03-22 11:34:44.871 [SYN:INFO] Mean MCU drift vs SX130X#0: -1.1ppm


The AWS console view of IoT LPWAN devices give the option of running a network analyser.

Here we can see the initial exchange of a successful connection and uplink from the Network Analyser:

AWS Network Analyser.

AWS Network Analyser.

  • Messages 1 to 5 are certificate downloads to the RAK2287 gateway.
  • Message 6 is a Configuration and Update Server (CUPS) request, which ironically contains no updates.
  • Message 7 is a Join Request from the LoRaWAN device, to the gateway and then on to the Join Server. This is authenticated and if the device attempting to join is recognised, a Join Accept is sent.
  • Message 8 The Join Accept response indicating that the device can join the LoRaWAN network.
  • Message 9 is the first uplink of data from the newly joined device.

The output from Basic Station gateway for the above sequence looks like this:

2023-03-22 11:34:51.498 [AIO:XDEB] [3|WS] > {"msgtype":"jreq","MHdr":0,"JoinEUI":"22-4C-DF-55-A0-00-00-01","DevEUI":"A2-A0-62-31-49-BA-39-EC","DevNonce":58714,"MIC":-238202304,"RefTime":0.000000,"DR":5,"Freq":868100000,"upinfo":{"rctx":0,"xtime":28428972696717558,"gpstime":0,"fts":-1,"rssi":0,"snr":14,"rxtime":1679484891.498428}} 2023-03-22 11:34:52.092 [AIO:XDEB] [3|WS] < {"msgtype":"dnmsg","DevEui":"00-00-00-00-00-00-00-00","regionid":1,"dnmode":"updn","dC":0,"diid":15510,"pdu":"206ab837711503a04be69d7afac4640e503a846545d43e49807ca5e3e002555771","priority":1,"RxDelay":5,"RX1DR":5,"RX1Freq":868100000,"xtime":28428972696717558,"rctx":0,"MuxTime":1679484892.081314} 2023-03-22 11:34:52.092 [S2E:WARN] Unknown field in dnmsg - ignored: regionid 2023-03-22 11:34:52.093 [S2E:DEBU] ::0 diid=15510 [ant#0] - next TX start ahead by 4s385ms 2023-03-22 11:34:56.458 [S2E:VERB] ::0 diid=15510 [ant#0] - starting TX in 19ms904us 2023-03-22 11:34:56.483 [S2E:INFO] TX ::0 diid=15510 [ant#0] - on air: 868.1MHz 14.0dBm ant#0(0) DR5 SF7/BW125 frame=206AB837711503A04BE69D7A..02555771 2023-03-22 11:34:56.551 [S2E:DEBU] Tx done diid=15510 2023-03-22 11:34:57.271 [any:XDEB] RX mod=LORA f=868500000 bw=-1735387324 sz=16 dr=8 4081CD8701C0C2C802267C7A7D32583C 2023-03-22 11:34:57.273 [S2E:VERB] RX 868.5MHz DR4 SF8/BW125 snr=10.8 rssi=0 xtime=0x65000003431F85 - updf mhdr=40 DevAddr=0187CD81 FCtrl=C0 FCnt=51394 FOpts=[] 02267C7A mic=1012413053 (16 bytes) 2023-03-22 11:34:57.273 [AIO:XDEB] [3|WS] > {"msgtype":"updf","MHdr":64,"DevAddr":25677185,"FCtrl":192,"FCnt":51394,"FOpts":"","FPort":2,"FRMPayload":"267C7A","MIC":1012413053,"RefTime":1679484897.261484,"DR":4,"Freq":868500000,"upinfo":{"rctx":0,"xtime":28428972702506885,"gpstime":0,"fts":-1,"rssi":0,"snr":10.75,"rxtime":1679484897.273115}} 2023-03-22 11:35:00.278 [any:XDEB] RX mod=LORA f=867900000 bw=-1732381065 sz=16 dr=8 4081CD8701C0C2C802267C7A7D32583C 2023-03-22 11:35:00.279 [S2E:VERB] RX 867.9MHz DR4 SF8/BW125 snr=15.2 rssi=-8 xtime=0x6500000370F180 - updf mhdr=40 DevAddr=0187CD81 FCtrl=C0 FCnt=51394 FOpts=[] 02267C7A mic=1012413053 (16 bytes) 2023-03-22 11:35:00.279 [AIO:XDEB] [3|WS] > {"msgtype":"updf","MHdr":64,"DevAddr":25677185,"FCtrl":192,"FCnt":51394,"FOpts":"","FPort":2,"FRMPayload":"267C7A","MIC":1012413053,"RefTime":1679484900.267767,"DR":4,"Freq":867900000,"upinfo":{"rctx":0,"xtime":28428972705509760,"gpstime":0,"fts":-1,"rssi":-8,"snr":15.25,"rxtime":1679484900.279392}} 2023-03-22 11:35:01.675 [SYN:INFO] Time sync qualities: min=240 q90=283 max=302 (previous q90=2147483647) 2023-03-22 11:35:03.284 [any:XDEB] RX mod=LORA f=867900000 bw=-1729375139 sz=16 dr=8 4081CD8701C0C2C802267C7A7D32583C 2023-03-22 11:35:03.285 [S2E:VERB] RX 867.9MHz DR4 SF8/BW125 snr=14.2 rssi=-9 xtime=0x650000039ECB1D - updf mhdr=40 DevAddr=0187CD81 FCtrl=C0 FCnt=51394 FOpts=[] 02267C7A mic=1012413053 (16 bytes) 2023-03-22 11:35:03.285 [AIO:XDEB] [3|WS] > {"msgtype":"updf","MHdr":64,"DevAddr":25677185,"FCtrl":192,"FCnt":51394,"FOpts":"","FPort":2,"FRMPayload":"267C7A","MIC":1012413053,"RefTime":1679484903.273694,"DR":4,"Freq":867900000,"upinfo":{"rctx":0,"xtime":28428972708514589,"gpstime":0,"fts":-1,"rssi":-9,"snr":14.25,"rxtime":1679484903.285315}}

  • Line 1 is the Join Request (device to the gateway) which is sent to the AWS IoT LPWAN.
  • Line 2 is the Join Accept (accept is sent from AWS to the gateway, then over the air to the device).
  • Looking carefully at the timestamps, line 4 shows that a transmission is queued ready to be transmitted in 19.904ms from now, the actual message went on air at 868.5MHz.
  • The first data uplink is received by the gateway on line 8.
  • Line 9 shows the spreading factor and bandwidth (SF8 and 125kHz respectively).

Data received on an MQTT topic

As part of the device configuration phase, a Destination is added and assigned to the device. The destination determines whether the received device data is forwarded directly to an MQTT topic or it is sent to a rule for processing. In this instance the data is forwarded to an MQTT topic as the payload does not change over time and can be decoded manually.

Destination is an MQTT topic

Destination is an MQTT topic

If we invoke the MQTT test client and subscribe to ‘topic/p2', we can see the following payload being received:

MQTT test client

The most interesting part of the received data is the payload, which here is

"PayloadData": "SGVsbG8h"

Using a Base64 decoder, the payload can be recovered as: Hello!

Of course, on a real system the payload is most likely a packed binary representation of sensor outputs and not human-readable text.

The back-up plan

After spending a lot of time trying to resolve the failure to receive the Join Accept message, an alternative was ordered just in case the problem could not be solved. It is the RAKWireless RAK3172 which can be sourced as a module to be mounted directly to a PCB or fitted to an header for use on the RAK WisBlock base board. RAK3172 is a Low-Power Long Range Transceiver module that is based on STM32WLE5CC chip. It provides an easy to use, small size, low-power solution for LoRa applications. The module complies with Class A, B & C of LoRaWAN 1.0.3 specifications.

Copyright © RAKWireless: RAK3172 Evaluation Board.

Copyright ©RAKWireless: RAK3172 Evaluation Board.

RAK3172 Bring-up

Connecting to the AWSLPWAN (LoRaWAN) network was trivial in comparison to porting the SX126x-Arduino MAC. From initial power-up of the board until successful downlinks (not just uplinks) was achieved in approximately forty minutes. This is many orders of magnitude faster and less painful than porting a LoRaWAN MAC.

To create a LPWAN device on AWS requires the DevEUI, the AppKey and the AppEUI. These three parameters are pre-programmed into the RAK3172 and can be accessed over the AT interface as follows:

AT+DEVEUI=? AT+DEVEUI=ACxxxxxxxxxxxxxx OK AT+APPKEY=? AT+APPKEY=ACxxxxxxxxxxxxxxACxxxxxxxxxxxxxx OK AT+APPEUI=? AT+APPEUI=ACxxxxxxxxxxxxxx OK

The LPWAN device can now be created using the values above, of course these will be different for different devices and can be changed on the device if required.

Once the LPWAN device is ready, the RAK3172 needs to join the LoRaWAN network. This is accomplished with:

AT+JOIN=1:0:10:8 where w:x:y:z w = 1 -> joining x = 0 -> don't re-join at startup y = 10 -> delay between join attempts z = 8 -> number of join attempts

A successful join is reported as:

OK +EVT:JOINED

The command to send data over LoRaWAN is as follows:

AT+SEND=3:9ABCDEF0 OK +EVT:SEND_CONFIRMED_OK

This breaks down to:

Send a message to FPort 3 (Frame port, similar in concept to a UDP port) . The payload has to be an even number of nibbles and each digit is the hex representation of a nibble.

The payload received on the MQTT topic looks like this:

"PayloadData": "mrze8A=="

Decoding this from Base64 to binary gives this:

10011010 10111100 11011110 11110000 Splitting into nibbles gives: 1001 1010 1011 1100 1101 1110 1111 0000 9 A B C D E F 0

Finally a queued downlink. As the LoRaWAN device is running as a Class A device, it can only receive a downlink (cloud to device) after it has transmitted an uplink (device to cloud). A downlink can be added via the AWSLPWAN console:

AWS Console view to initiate a downlink.

AWS Console view to initiate a downlink.

Click on the Queue downlink message tab. Use an online Base64 encoder to create a suitable message payload for the downlink. This site works well: https://www.base64encode.org/ (https://www.base64encode.org/

Here we have converted Green Custard into R3JlZW4gQ3VzdGFyZA==

Queue download link message

Click on the submit and then switch to the AT interface.

Successful queue

Send an uplink as follows:

AT+SEND=3:12345678 OK +EVT:SEND_CONFIRMED_OK +EVT:RX_1:-40:9:UNICAST:5:477265656e2043757374617264 +EVT:SEND_CONFIRMED_OK

After a short delay, the queued downlink is received. Notice a second SEND_EVEN_CONFIRMED, this is to acknowledge that the downlink was received which was chosen in the Queue downlink message console window. The received event can be broken down as follows:

+EVT:RX_1:-40:9:UNICAST:5:477265656e2043757374617264 RX_1 -> The downlink was received in the first receive window -40: -> The received signal strength indication (RSSI) for the downlink in dBm 9: -> The signal to noise ratio (SNR) which is dimensionless UNICAST: -> Rx is in unicast Class B mode 5: -> The FPort the message was received on <xxx> -> Received binary data.

Taking the received data:

477265656e2043757374617264 Breaking it into bytes: 47 72 65 65 6e 20 43 75 73 74 61 72 64 Convert to ascii: 47 -> G 72 -> r 65 -> e 65 -> e 6e -> n 20 -> ' ' 43 -> C 75 -> u 73 -> s 74 -> t 61 -> a 72 -> r 64 -> d

Interestingly the Base64 encoded payload sent from the cloud has been converted back to ascii values.

Lessons Learned

During the porting work, an alternative part was identified the RAKWireless RAK3172. This is a LoRaWAN module that uses an AT-interface, but the most interesting feature is that the entire LoRaWAN MAC runs on the module. One distinct advantage is that it is certified with the LoRa Alliance Certificate of Compliance:

https://downloads.rakwireless.com/LoRa/RAK3172/Certification/RAK3172_LoRa_Alliance_Certification.pdf

This certification means that the RAK3172 complies with the LoRaWAN v1.03 specification and will effectively communicate with a similarly compliant gateway. The benefits for this are enormous, interoperability between gateways when the device is installed is key. It may be that the device works perfectly when developed on the bench, but as soon as it is installed, any areas that have borderline timings, such as join request/accept procedure, may fail with an alternate gateway. Another area that was not tested on the P2-Core1262-HF combination was receiving downlinks. This requires an accurate timing window and could easily have demonstrated similar issues as seen on the Join request/accept procedure.

It is possible to take the custom hardware and software implementation of the LoRaWAN device to a LoRa Alliance Certified test lab and gain certification. This takes approximately one day (assuming no problems are encountered) and involves travel to either Germany, Spain or Sweden.

https://lora-alliance.org/lorawan-certification-test-houses/

The RAK3172 also has CE and FCC certification. When the module is mounted inside an enclosure and an external antenna is attached, the RF configuration is different to that presented for the certification test. This means that it will need to be CE or FCC certified as a complete product. However, certifying a product containing a pre-certified module is a far easier task as only the EIRP (due to a different antenna) should be affected

Summary

This series of blog posts described the steps taken from identifying suitable hardware which was physically small enough and at a competitive price point, porting a LoRaWAN MAC library, problems encountered and finally an alternative that was both cheaper and easier to use.

Back to the list