This repository contains the example code for The Things Summer Academy workshop about LoRaWAN devices.
The following list explains for each sketch / code what it's intended for.
-
ENVBlinkDemo: A blink Arduino sketch that works also when the MKR ENV shield is connected to the MKR WAN 1300 board. The regular blink sketch from the IDE doesn't work in this scenario because some additional configuration needs to be done.
-
ReadSensors: An Arduino sketch that shows how to read from the MKR ENV shield sensors. See: https://www.arduino.cc/en/Reference/ArduinoMKRENV
-
LoRa-Dev-EUI: An Arduino sketch that helps you to find out the device EUI which you will need to register your device with The Things Stack.
-
LoRaWAN-Print-Channel-Mask: An Arduino sketch that helps you to find out the channel mask for your desired channels to be enabled. This mask can then be used for joining a LoRaWAN network.
-
LoRaWAN-Channel-Mask-Join: An example Arduino sketch that shows you how to use channel masking to join The Things Stack. This may be required depending on where you're based. (E.g. US or AU). More info can be found here:
-
LoRaWAN-Message: An Arduino sketch that shows how to send a simple string message to a LoRaWAN backend (e.g. The Things Stack). See: https://www.arduino.cc/en/Reference/MKRWAN
-
payload-formatter-string.js: A javascript snippet that shows an implementation of a Payload Decoder which converts a bytes stream back into a human readable ASCII string. See: https://www.thethingsindustries.com/docs/integrations/payload-formatters/javascript/
-
ReadSensors-LoRaWAN: An Arduino sketch that shows how to read from the MKR ENV shield sensors and send those values as floats to a LoRaWAN backend.
-
ReadAnalogSensor-LoRaWAN: An Arduino sketch that shows how to read an analog sensors and send the value as an int to a LoRaWAN backend.
-
payload-formatter-float.js: A javascript snippet that shows an implementation of a Payload Decoder that unpacks float values from a byte stream and converts them into a javascript object. See: https://www.thethingsnetwork.org/docs/devices/bytes/
-
LoRaWAN-Downlink: An Arduino sketch that shows you how to use downlink messages to control your Arduino board. In this sketch, a message with the data
01
turns the on-board LED on, a message with00
turns it off. Keep in mind that downlink messages won't be received instantly. You may have to wait a few minutes until they are delivered to your device. -
ReadSensors-LoRaWAN-LowPower: An Arduino sketch that shows how to read from the MKR ENV shield sensors and send those values as floats to a LoRaWAN backend while using sleep modes to ensure maximum battery life. See: https://www.arduino.cc/en/Reference/ArduinoLowPower
Create your own LoRa powered environment sensor station!
- Create a TTS app and register your device
- Create your own sketch that reads from the ENV shield sensors
- Send the sensor values to TTS every 20 minutes. Put the board to sleep in the mean time.
- Add a payload decoder to decode the sensor values
- Round the float values to two digits in the payload decoder
- Add a warning message in the payload decoder if the temperature is too high / too cold (e.g. -5 / above 34 celsius)
- Define approximate illuminance thresholds for: day, twilight, night and add a “daylight” property with a value according to those thresholds (changes over the day)
- Add a “pressureTendency” property to see if atmospheric pressure is rising / falling. Do so by calculating the tendency over the last 3 hours. (Hint: millis())
- Add the weekly average temperature as a “averageTemperature” property
- Use a TTS downlink to maintain and synchronise a clock on the Arduino (manually).
- Now that you know the time, replace the twilight value of the “daylight” property with either dusk or dawn depending on the time of the day.
- Record the approximate sunrise / sunset times based on the daylight property and add them as “sunrise” / “sunset” properties (don’t change over the day)
- Think of a way of enabling/disabling the 4 sensors by sending a downlink messages with just 1 byte. (Hint: Use bit-wise operators). If a sensor is disabled, the sensor value shall not be read/sent via LoRaWAN to save energy and bandwidth. Send the same byte in your uplink message to let the payload decoder know how to decode the message. e.g. if The pressure sensor is disabled, only 3 * 4 = 12 bytes are sent for the sensor values and the bytes of the 3rd sensor in the byte stream belong now to the illuminance sensor rather than the pressure sensor.
If you have a micro SD card, save the sensor data to the SD card to prevent data loss when power goes out. Upon boot, check for existing sensor data and send it to TTS. SEE: https://www.arduino.cc/en/reference/SD
If you encounter any errors in the Arduino IDE, please refer to the Arduino help center: https://support.arduino.cc/hc/en-us