M5Stack recently released an updated LoRaWAN module using a heltec cubecell chip based on the ASR6501. This chip can theoretically be programmed using Arduino, but the module is intended to be used by AT-commands. You can find a list of supported commands at M5Stacks documentation page: https://docs.m5stack.com/#/en/module/comx_lorawan?id=related-link
The module supports two different modes: LoRa (point to point) and LoRaWAN. This project is about using LoRaWAN to connect the module to The Things Network - TTN (https://www.thethingsnetwork.org/).
Hardware SetupBefore you connect the module to your M5Stack device, make sure you set the TXD/RXD dip switches correctly. If you use the grey or basic and have nothing else connected, the default UART pin configuration 16/17 is fine. For the Fire you should use 13/5, as all other settings can interfere with internals of the Fire.
Communication with the COM.LoRaWAN chipAfter connecting everything correctly, let's make sure the communication between the module and the chip works.
Open UIFlow and load the UART passthrough demo. If you changed the pin configuration using the dip switches earlier, make sure to change it in the UART set block. For the Fire I changed it from 17/16 to 5/13. Now run the app on your device. From now on serial data you send through the usb cable will be forwarded to the COM.LoRaWAN chip.
To send data using USB, we will use the M5Burner software provided by M5Stack. Connect your device to your computer, open the M5Burner app and make sure the correct com port is selected. Now click on Com Monitor and you will see a window that will allow us to interact with the COM.LoRaWAN chip.
Here you can enter commands in the bottom by typing them and clicking send. You can also hit Ctrl-Enter on your keyboard. In the top you will see the answers of the chip.
The chip supports a low power mode and can be woken up by sending any command. If you see "ASR is Waked,LowPower Mode Stopped"
you just woke up the chip and will have to repeat the command for the chip to respond to it.
First let's see if the chip is in LoRa or LoRaWAN mode. You can do this by sending the follwing command:
AT+LORAWAN=?
The chip should now respond with 0 for LoRa and 1 for LoRaWAN mode.
Let's set it to LoRaWAN mode:
AT+LORAWAN=1
The chip should respond with the LoRaWAN data that is stored in the chip. All of these settings are saved and will survive disconnecting the chip from power.
For now the only thing you need is the Device EUI. Select and copy it. Now let's register the device in TTN.
Configuration of TTNFollow the device registration tutorial from TTN's website (https://www.thethingsnetwork.org/docs/devices/registration.html) to create an account and register an app as well as the device. When it asks for a device id, paste the id you copied earlier in the M5Burner app. The ABP part of the tutorial can be ignored.
From that registration process you should now have two more settings necessary for joining the TTN network: App Key and App EUI. In the next chapter we will save them into the COM.LoRaWAN chip.
Setup and first JoinLet's get back to the M5Burner app and save the settings provided by TTN from the previous step. You will have to set the settings one after the other. They will be stored in the chip and you don't have to set them again after a reset of the device.
AT+AppEui=AABBCCDD
AT+AppKey=AABBCCDD
Now you can try to join the network:
AT+Join=1
The chip should answer with "Joining...". If you did everything right, after a while you should see "joined". If it doesn't work, make sure you did all the previous steps correctly. If you are not in reach of a TTN gateway, you will also not be able to join. You can check on https://ttnmapper.org/ where the nearest gateway is.
Sending dataIf you successfully join, you can now send something through TTN, by sending the following command:
AT+SendHex=CAFE
If you go to your device in your app on TTN and click on the data tab, you should now see the data arrive.
Next StepsWith your new knowledge you should be able to modify M5Stacks COM.LoRaWAN point to point example (https://github.com/m5stack/M5-ProductExampleCodes/blob/master/Module/COM_LoRaWAN/UIFlow/COM.LoRaWAN.m5f) to use LoRaWAN instead. Let me know in the comments if you want me to write a separate tutorial for this.
Comments