├── .gitignore ├── Getting Started ├── 1_PotMeter │ ├── Potmeter.ino │ └── connections.png ├── 2_DeviceInfo │ └── DeviceInfo.ino ├── 3_Join │ └── Join.ino ├── 4_Traffic │ ├── payload-formatter.js │ └── traffic.ino ├── README.md ├── TTN_Arduino_Lib.png └── TTN_Serial_monitor.png ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /Getting Started/1_PotMeter/Potmeter.ino: -------------------------------------------------------------------------------- 1 | int sensorPin = A0; 2 | int sensorValue = 0; 3 | 4 | void setup() { 5 | pinMode(sensorPin, INPUT); 6 | Serial.begin(9600); 7 | } 8 | 9 | void loop() { 10 | sensorValue = analogRead(sensorPin); 11 | Serial.println(sensorValue); 12 | delay(250); 13 | } 14 | -------------------------------------------------------------------------------- /Getting Started/1_PotMeter/connections.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheThingsNetwork/workshops/602a1165a7bbcd91a0f9a8af123829dc1049e8d0/Getting Started/1_PotMeter/connections.png -------------------------------------------------------------------------------- /Getting Started/2_DeviceInfo/DeviceInfo.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define loraSerial Serial1 4 | #define debugSerial Serial 5 | 6 | // Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915 7 | #define freqPlan TTN_FP_EU868 8 | 9 | TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan); 10 | 11 | void setup() 12 | { 13 | loraSerial.begin(57600); 14 | debugSerial.begin(9600); 15 | } 16 | 17 | void loop() 18 | { 19 | debugSerial.println("Device Information"); 20 | debugSerial.println(); 21 | ttn.showStatus(); 22 | debugSerial.println(); 23 | debugSerial.println("Use the EUI to register the device for OTAA"); 24 | debugSerial.println("-------------------------------------------"); 25 | debugSerial.println(); 26 | 27 | delay(10000); 28 | } 29 | -------------------------------------------------------------------------------- /Getting Started/3_Join/Join.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Set your AppEUI and AppKey 4 | const char *appEui = ""; 5 | const char *appKey = ""; 6 | 7 | #define loraSerial Serial1 8 | #define debugSerial Serial 9 | 10 | // Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915 11 | #define freqPlan REPLACE_ME 12 | 13 | TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan); 14 | 15 | void setup() 16 | { 17 | loraSerial.begin(57600); 18 | debugSerial.begin(9600); 19 | 20 | // Wait a maximum of 10s for Serial Monitor 21 | while (!debugSerial && millis() < 10000) 22 | ; 23 | 24 | debugSerial.println("-- STATUS"); 25 | ttn.showStatus(); 26 | 27 | debugSerial.println("-- JOIN"); 28 | ttn.join(appEui, appKey); 29 | } 30 | 31 | void loop() 32 | { 33 | debugSerial.println("-- LOOP"); 34 | 35 | // Prepare payload of 1 byte to indicate LED status 36 | byte payload[1]; 37 | payload[0] = (digitalRead(LED_BUILTIN) == HIGH) ? 1 : 0; 38 | 39 | // Send it off 40 | ttn.sendBytes(payload, sizeof(payload)); 41 | 42 | delay(10000); 43 | } 44 | -------------------------------------------------------------------------------- /Getting Started/4_Traffic/payload-formatter.js: -------------------------------------------------------------------------------- 1 | function decodeUplink(input) { 2 | var data = {}; 3 | data.sensorValue = (input.bytes[0] << 8) + input.bytes[1]; 4 | var warnings = []; 5 | return { 6 | data: data, 7 | warnings: warnings 8 | }; 9 | } 10 | -------------------------------------------------------------------------------- /Getting Started/4_Traffic/traffic.ino: -------------------------------------------------------------------------------- 1 | #include 2 | // Set your AppEUI and AppKey 3 | const char *appEui = "800000000000007B"; 4 | const char *appKey = "bbad768dd0e311d470524d12c28b903f"; 5 | 6 | #define loraSerial Serial1 7 | #define debugSerial Serial 8 | 9 | // Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915 10 | #define freqPlan TTN_FP_EU868 11 | 12 | TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan); 13 | 14 | int sensorPin = A0; 15 | int sensorValue = 0; 16 | int SENSOR_THRESHOLD_LOW = 640; 17 | int SENSOR_THRESHOLD_HIGH = 670; 18 | 19 | void setup() { 20 | pinMode(sensorPin, INPUT); 21 | 22 | loraSerial.begin(57600); 23 | debugSerial.begin(9600); 24 | 25 | // Wait a maximum of 10s for Serial Monitor 26 | while (!debugSerial && millis() < 10000) 27 | ; 28 | 29 | debugSerial.println("-- STATUS"); 30 | ttn.showStatus(); 31 | 32 | debugSerial.println("-- JOIN"); 33 | ttn.join(appEui, appKey); 34 | } 35 | 36 | void loop() { 37 | sensorValue = analogRead(sensorPin); 38 | Serial.println(sensorValue); 39 | 40 | if(sensorValue < SENSOR_THRESHOLD_LOW || sensorValue > SENSOR_THRESHOLD_HIGH){ 41 | // Prepare payload of 2 bytes to indicate sensor value 42 | byte payload[2]; 43 | payload[0] = highByte(sensorValue); 44 | payload[1] = lowByte(sensorValue); 45 | 46 | // Send it as an Uplink 47 | ttn.sendBytes(payload, sizeof(payload)); 48 | debugSerial.println("Sending data"); 49 | 50 | delay(10000); 51 | } 52 | 53 | else{ 54 | delay(1000); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Getting Started/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started With LoRaWAN 2 | 3 | This workshop will guide you through working with The Things Uno to send sensor data over The Things Stack to an application. 4 | 5 | ## Pre-requisites 6 | 7 | 1. The Things Uno 8 | 2. Micro-USB cable 9 | 3. Sensors, jumpers and optional breadboard as provided, ex: a Potentiometer and connecting wires. 10 | 4. Computer running Windows 7 or higher, Mac OS X or Linux 11 | 5. Wifi for your laptop. 12 | 6. Gateway coverage to The Things Stack instance that you are sending data to. 13 | 14 | ## Preparation 15 | 16 | ### Setting up the Arduino IDE 17 | 18 | Head over to the documentation page on [The Things Uno](https://www.thethingsindustries.com/docs/devices/the-things-uno/#setting-up-arduino-ide) and setup the IDE. 19 | 20 | ### Setting up an account with The Things Stack Community Edition 21 | 22 | To follow along with this workshop, you'll need an account with an instance of The Things Stack. Check the page on setting up [an account with The Things Stack Community Edition](https://www.thethingsindustries.com/docs/getting-started/ttn/). 23 | 24 | ## Procedure 25 | 26 | ### General steps with the Arduino IDE 27 | 28 | For this workshop there are two actions with the Arduino IDE that will be used the most. 29 | 30 | The Serial Monitor is used to read serial data from the Arduino. It's recommended to keep this window open in the background. 31 | 32 | To enable this go to `Tools` > `Serial Monitor`. Set the baud-rate to `9600` if not set already. 33 | 34 | ![TTN_Serial_monitor](TTN_Serial_monitor.png) 35 | 36 | Secondly, to upload your code to the Arduino, use the options under `Sketch`. For this guide, since you're using a USB connection, always upload via the `Upload` option (and not `Upload using programmer`). 37 | 38 | ### "Calibrate" the sensor 39 | 40 | - Connect the USB cable to the Arduino IDE and select the port as explained the preparatory step. 41 | - Connect the Pot with the 42 | ![schematic](./1_PotMeter/connections.png) 43 | - Open the [PotMeter.ino](./1_PotMeter/Potmeter.ino) sketch in the Arduino IDE. 44 | - Upload it. 45 | - Play around with the pot and note the values printed on the screen. 46 | - Choose a lower threshold and and upper threshold for your specific pot. These values will be used in later steps. 47 | 48 | ### Register the Device 49 | 50 | - Connect the USB cable to the Arduino IDE and select the port as explained the preparatory step. 51 | - Open the [DeviceInfo.ino](./2_DeviceInfo/DeviceInfo.ino) sketch in the Arduino IDE and upload it. 52 | - Copy the screen the `DevEUI` and `JoinEUI` values to a separate file. 53 | - Register this device on [The Things Stack Community Edition](https://www.thethingsindustries.com/docs/devices/adding-devices/). 54 | - For the App Key, provide an arbitrary value or to generate one from the Console. 55 | ```bash 56 | openssl rand -hex 16 57 | ``` 58 | 59 | ### Perform a LoRaWAN Join 60 | 61 | - Connect the USB cable to the Arduino IDE and select the port as explained the preparatory step. 62 | - Open the [Join.ino](./3_Join/Join.ino) sketch in the Arduino IDE. 63 | - Replace the following fields in the sketch 64 | - `appEUI`: Value you noted earlier 65 | - `appKey`: The same random value used for the `App Key` field while registering the device. 66 | - `freqPlan`: Replace the word `REPLACE_ME` with the correct frequency plan based on your region. 67 | - Go to `Sketch` -> `Verify/Compile`. If correct, upload the sketch. 68 | - Check the serial monitor for the device to Join the network. 69 | 70 | ### Send Sensor Data 71 | 72 | - Connect the USB cable to the Arduino IDE and select the port as explained the preparatory step. 73 | - Open the [Traffic](./4_Traffic/traffic.ino) sketch in the Arduino IDE. 74 | - Set the `SENSOR_THRESHOLD_LOW` and `SENSOR_THRESHOLD_HIGH` values based on your own sensor value that were noted in step 1. 75 | - Go to `Sketch` -> `Verify/Compile`. If correct, upload the sketch. 76 | - Head over to the application tab of [The Things Stack Community Edition](https://console.cloud.thethings.network) and check your data payloads. 77 | - Add the Payload formatter to translate the array of bytes to a human-readable format. [Link to Payload Formatter](./4_Traffic/payload-formatter.js) 78 | -------------------------------------------------------------------------------- /Getting Started/TTN_Arduino_Lib.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheThingsNetwork/workshops/602a1165a7bbcd91a0f9a8af123829dc1049e8d0/Getting Started/TTN_Arduino_Lib.png -------------------------------------------------------------------------------- /Getting Started/TTN_Serial_monitor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheThingsNetwork/workshops/602a1165a7bbcd91a0f9a8af123829dc1049e8d0/Getting Started/TTN_Serial_monitor.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 The Things Network 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Workshops 2 | 3 | This repository contains a collection of files used for various workshops. 4 | 5 | ## Topics 6 | 7 | - [Getting Started](./Getting%20Started): An introduction to LoRaWAN using [The Things Uno](https://www.thethingsindustries.com/docs/devices/the-things-uno/). 8 | --------------------------------------------------------------------------------