# Using LoraWAN and The Things Network with Feather

## Overview

Danger: 

![](https://cdn-learn.adafruit.com/assets/assets/000/062/176/medium800thumb/feather_ezgif.com-video-to-gif_%2816%29.jpg?1537391934)

In this project, we're going to build a small weather-logging node using a Feather and a temperature sensor. The captured data will then be sent to The Things Network.

## What is **The Things Network**?
https://www.youtube.com/watch?v=U4UrXl-SGEo

The [Things Network](https://www.thethingsnetwork.org/) is a project dedicated to building a [network](https://www.thethingsnetwork.org/tech-stack) for the Internet of Things. While WiFi is used in most Internet of Things devices, The Things Network uses a protocol called **LoRaWAN** which allows devices to talk to the internet _without cellular or WiFi connectivity_. This means you don't need to worry about protected wireless hotspots, cellular data plans, or spotty WiFi connectivity.&nbsp;

It's **ideal** for most internet of things projects, and unlike cellular plans or WiFi - it's&nbsp; **free to use**.

Also, there are plenty of gateways available to connect your feather to - [if you'd like to find a gateway in your area, check the Gateway Map.](https://www.thethingsnetwork.org/community)

## Parts
We're going to use one of our RadioFruits, the Feather M0 LoRa. In The The Things Network terms, this will be used as our&nbsp;[_device_](https://www.thethingsnetwork.org/docs/devices/).

### Adafruit Feather M0 with RFM95 LoRa Radio - 900MHz

[Adafruit Feather M0 with RFM95 LoRa Radio - 900MHz](https://www.adafruit.com/product/3178)
This is the **Adafruit Feather M0 RFM95 LoRa Radio (900MHz)****. **We call these _RadioFruits** ,**_ our take on an microcontroller with a "[Long Range (LoRa)](https://www.lora-alliance.org/)" packet radio transceiver with built...

In Stock
[Buy Now](https://www.adafruit.com/product/3178)
[Related Guides to the Product](https://learn.adafruit.com/products/3178/guides)
![Angel shot Adafruit Feather M0 with RFM95 LoRa Radio - 900MHz](https://cdn-shop.adafruit.com/640x480/3178-07.jpg)

We'll also want to _send data from our device to a [gateway](https://www.thethingsnetwork.org/docs/gateways/).&nbsp;_This small sensor can read both the temperature and relative humidity. It's perfect for building small IoT data-loggers.

### Materials
### Part: Breadboard
quantity: 1
Half-size breadboard
[Breadboard](https://www.adafruit.com/product/64)

### Part: Breadboard Wires 
quantity: 1
Breadboard Wiring Bundle
[Breadboard Wires ](https://www.adafruit.com/product/153)

# Using LoraWAN and The Things Network with Feather

## Arduino Wiring

## Wiring the Antenna
Your _Feather M0 does not come with an antenna_, but there are two ways of wiring one up.

&nbsp;

For this guide, and to keep the build cost-effective, we soldered a small, 82mm wire to the&nbsp; **ANT&nbsp;** pad.

- Antenna Options and installation instructions are detailed on this product's learn guide's&nbsp;[_antenna options&nbsp;_page.&nbsp;](https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module/antenna-options)
- **Note:&nbsp;** Antenna length differs between regions, **make sure you cut the antenna to the correct length for your region.**

![featherm0.png](https://cdn-learn.adafruit.com/assets/assets/000/062/038/medium640/featherm0.png?1537292646)

 **Add a required jumper wire** - Pin 3 is internally connected to pin&nbsp;_io0_, but we'll need to **add a jumper wire between the&nbsp;Feather Digital Pin 6&nbsp;** and&nbsp; **Feather Pin _io1_** _._

![feather_wiring_bb_wire_only.png](https://cdn-learn.adafruit.com/assets/assets/000/062/054/medium640/feather_wiring_bb_wire_only.png?1537306176)

## Wiring
Make the following connections between the Feather M0 and the DHT22:

- **Feather 3V** &nbsp;to **&nbsp;DHT22 Pin 1**
- **Feather Pin 10&nbsp;** to&nbsp; **DHT22 Pin 2**
- **Feather Ground&nbsp;** to&nbsp; **DHT22 Pin 3**
- **Add a 10k ohm resistor&nbsp;** between the&nbsp;VCC (DHT Pin 1) and Data Pin (DHT Pin 2) on the DHT22.

Warning: 

# Using LoraWAN and The Things Network with Feather

## Registering a Feather with The Things Network

Before your Feather can communicate with The Things Network, you'll need to create an application.

First, we're going to register an account with TTN. [Navigate to their account registration page](https://account.thethingsnetwork.org/register) to set up an account.

Once logged in,&nbsp;[navigate to the The Things Network Console](https://console.thethingsnetwork.org/). This page is where you can register applications and add new devices or gateways. Click&nbsp; **Applications** &nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/062/026/medium800/feather_console-application.png?1537290244)

Click&nbsp; **add application**.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/062/028/medium800/feather_addapplication.png?1537290414)

Fill out an&nbsp; **Application ID** &nbsp;to identify the application by, and a **description** of what the application is. We set our&nbsp; **Handler Registration&nbsp;** to match our region, _us-west_. If you're not located in the U.S., TTN provides multiple regions for handler registration.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/062/032/medium800/feather_The_Things_Network_Console_add.png?1537290833)

Once created, you'll be directed to the Application Overview. From here, you can add devices, view data coming into (and out of) the application, add integrations for external services, and more. We'll come back to this section later in the guide.

**Click&nbsp;Register Device**

![](https://cdn-learn.adafruit.com/assets/assets/000/062/033/medium800/feather_The_Things_Network_Console_Add_device.png?1537290874)

On the **Register Device Page** ,&nbsp;The **Device ID** should be a unique string to identify the device.&nbsp;

The&nbsp; **Device EUI&nbsp;** is the unique identifier which came in the same bag as your Radiofruit Feather. We'll pad the middle of the string with four zeroes. The&nbsp; **App Key&nbsp;** will be randomly generated for you by TTN. Select the App EUI (used to identify the application) from the list.

![](https://cdn-learn.adafruit.com/assets/assets/000/062/037/medium800/feather_The_Things_Network_Console_REG_DEVICE.png?1537291676)

Now that the application is set up, and the device is registered to the application, let's move on to wiring the Feather for use with TTN.&nbsp;

## The Sticker (EUI) which came with my feather is missing! _What now?_
The Things Network's&nbsp; **Device EUI** can generate a device EUI. It also makes sure the EUI generated conforms to the IEEE spec.

![feather_The_Things_Network_Console.png](https://cdn-learn.adafruit.com/assets/assets/000/063/289/medium640/feather_The_Things_Network_Console.png?1539089489)

# Using LoraWAN and The Things Network with Feather

## Arduino Setup

Before proceeding with this guide, make sure your board is correctly set-up by following the&nbsp;[_Using the Arduino IDE_](https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module/using-with-arduino-ide)&nbsp; page of the setup guide for the Feather M0 LoRa.

We're going to use MCCI's _[arduino-lmic](https://github.com/mcci-catena/arduino-lmic)&nbsp;_library with this guide to communicate with The Things Network.&nbsp; **Open the Arduino Library Manager** ( **Sketch-\>Include Library-\>Manage Libraries** ). **In the search box, type&nbsp;** _ **MCCI**.&nbsp;_the&nbsp;_MCCI LoRaWAN LMIC library&nbsp;_should be the first result.&nbsp; **Click Install.**

![](https://cdn-learn.adafruit.com/assets/assets/000/062/526/medium800/feather_Library_Manager_MCCI.png?1537882799)

We've included the code for this guide inside the arduino-lmic library. To open it, from the Arduino IDE click&nbsp; **File-\>Examples-\>MCCI LoRaWAN LMIC library-\>ttn-otaa-feather-us915-dht22**

![](https://cdn-learn.adafruit.com/assets/assets/000/062/116/medium800/feather_lorawan_sketch_lib_manager.png?1537378674)

The code for the Feather M0 Weather Node should pop up.

![](https://cdn-learn.adafruit.com/assets/assets/000/062/527/medium800/ttn-otaa-feather-us915-dht22___Arduino_1_8_5.png?1537882976)

Now that our code is set up, let's learn how to send data from our Feather to TTN and decode it!

# Using LoraWAN and The Things Network with Feather

## Region Configuration

Info: 

Dont fret if you're not in the US - you'll just have to make some small modifications to your code to ensure it runs on the correct region. The Arduino-Lmic library supports the following regions:

- eu\_868: EU
- us\_915: US
- au\_921: Australia&nbsp;
- as\_923: Asia
- in\_866: India

First, navigate to the [lmic\_project\_config.h](https://github.com/mcci-catena/arduino-lmic/blob/master/project_config/lmic_project_config.h) file within the LMIC Arduino library. On Windows and Macintosh machines, the default name of the&nbsp; **folder** &nbsp;is " **Arduino**" and is&nbsp; **located** &nbsp;in your Documents&nbsp; **folder.**

![](https://cdn-learn.adafruit.com/assets/assets/000/062/179/medium800/feather_regionalization.png?1537395855)

Simply uncomment the region your device is located in. We use a SX1276 transceiver on the Feather M0 LoRA, so this definition should not be changed.&nbsp;

# Using LoraWAN and The Things Network with Feather

## Arduino Code

## Remove regression test code
If you see this chunk of code, you can remove it from your code

![](https://cdn-learn.adafruit.com/assets/assets/000/063/936/medium800/feather_image.png?1540016285)

## Code Setup

To register your Feather with The Things Network, you need to set three unique identifiers in the code: `APPEUI`, `DEVEUI`, and `APPKEY`.

Navigate to the&nbsp; **Device Overview&nbsp;** page for your Feather device. Make sure the&nbsp; **Activation Method** is set to **OTAA**.&nbsp;

![feather_The_Things_Network_Console.png](https://cdn-learn.adafruit.com/assets/assets/000/062/059/medium640/feather_The_Things_Network_Console.png?1537307469)

Before adding the unique identifiers to our sketch, we'll need to first expand them by **clicking the \<\> icon**. Then, we'll need to switch the order of the Device EUI and Application EUI to little-endian format. You can swap the order by **clicking the button with two arrows**.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/062/084/medium800thumb/feather_hero_eui_swap.jpg?1537373128)

We're going to copy each unique identifier from the Device Overview to the variables within the sketch.

First, copy the&nbsp; **Application EUI&nbsp;** in **lsb** format from the TTN console to&nbsp; **APPEUI&nbsp;** variable in the sketch.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/062/109/medium800/feather_app_eui.png?1537376942)

Next, copy the&nbsp; **Device EUI** in **lsb** format from the TTN console to the&nbsp; **DEVEUI** &nbsp;variable in the sketch.

![](https://cdn-learn.adafruit.com/assets/assets/000/062/110/medium800/feather_dev_eui.png?1537376949)

Finally, copy the&nbsp; **App Key&nbsp;** from the TTN console to&nbsp; **APPKEY&nbsp;** variable&nbsp;in the sketch.

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/062/111/medium800/feather_app_key.png?1537376969)

That's all for now - we're ready to upload the code onto our Arduino.&nbsp;

Note that to see the output you'll need to open up the Serial console. Once you've debugged your example, you can comment out or remove the `while (! Serial);` line from `setup()`

## Code Overview
Most of what happens in the code occurs in the `setup()`, `on_event()` and `do_send()` functions.

Within `setup()`, we initialize our DHT sensor and set up the&nbsp;LMIC (LoraWAN-in-C, formerly LoraMAC-in-C) framework for use with our radio (the&nbsp;RFM95) and region-specific radio settings.&nbsp;

Our main `loop()`&nbsp;calls `os_runloop_once()`, which calls the LMIC runloop processor. This loop causes radio events to occur based on events and time - such as callbacks for when the transmission is complete. While you&nbsp;_can_ place additional code within this loop() routine, we don't advise it - the LoRaWAN timing is tight.&nbsp;

If there isn't a transmission job currently running, we're going to prepare the packet to send to The Things Network. This occurs in the `do_send()`&nbsp;function.

To read the temperature, we're going to first create a floating point variable, `temperature`, and assign it to the temperature value from the sensor.&nbsp;

` float temperature = dht.readTemperature();`

While we can't directly send floating point numbers (like 50.62 degrees) to The Things Network dashboard, the MCCI-LMIC library includes some data encoding utility functions to encode floating point data into integer data using a special bit layout -[`sflt16`](https://github.com/mcci-catena/arduino-lmic#sflt16https://github.com/mcci-catena/arduino-lmic#sflt16).

Since the floating point is within the range -1 to -1, we'll need to divide the range (by 100 for temperature) to increase the exponent range. We're going to get the value back in the range by later multiplying it by the range (100, in this example) using the decoder on the TTN Console.&nbsp;

`// adjust for the f2sflt16 range (-1 to 1) temperature = temperature / 100; rHumidity = rHumidity / 100;`

Next, we're going to convert the float to an integer. To do this, we'll use the library's float-to-signed-float-16 function (`LMIC_f2sflt16`):

` // float -> intuint16_t payloadTemp = LMIC_f2sflt16(temperature);`

Almost there! Before loading our values into the payload, we'll need to convert them from an integer (payloadTemp) to bytes. To do this, we'll use the Arduino [lowByte](https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/lowbyte/) and [highByte](https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/highbyte/) functions:

` // int -> bytes`  
` byte tempLow = lowByte(payloadTemp);`  
` byte tempHigh = highByte(payloadTemp);`

We defined a payload further up in the code (`static uint8_t payload[5]`). Now, we place the bits (low byte first)&nbsp; into the payload:

` payload[0] = tempLow;`  
` payload[1] = tempHigh;`

and prepare the payload for sending to TTN at the next possible time.

`LMIC_setTxData2(1, payload, sizeof(payload)-1, 0);`

## Check Sketch Output

Compile ( **cmd/ctrl + R** ) and Upload ( **ctrl/cmd+U** ) the sketch onto the Feather. Then, pop open the serial monitor&nbsp;(**Tools-\>Serial Monitor)**. You should see the Feather joining the Things Network. Once it joins, it'll dump its connection info. Then, it'll show _EV\_TXStart_ (an event which begins the transmission) and _EV\_TXComplete_ (the transmission has been received and acknowledged by the gateway). The output should be similar to the following:

```
Starting
Temperature: 26.00 *C
%RH 48.10
105016549: EV_JOINING
105016641: EV_TXSTART
105357886: EV_JOINED
netid: 19
devaddr: 26022F78
artKey: 78-F6-78-6C-87-26-86-AE-E1-AC-6D-79-83-57-7E-11
nwkKey: FE-14-C4-A7-BF-D3-B6-E6-95-D4-2F-93-DC-F9-D7-25
105358155: EV_TXSTART
105579674: EV_TXCOMPLETE (includes waiting for RX windows)

```

If you're stuck on _EV\_JOINING_ or fail to join the network,&nbsp; make sure your device is within range of a The Things Network gateway.&nbsp;

If the code is looping _EV\_TXSTART_, make sure a jumper wire is connecting the Feather's Pin 6 and Feather Pin 'io1'.

## Check Things Network Data

Navigate to the The Things Network Console and select your application. From the menu on the right hand side of the page,&nbsp; **Click&nbsp;Data**.

![](https://cdn-learn.adafruit.com/assets/assets/000/062/164/medium800/feather_The_Things_Network_Console_data.png?1537385034)

If everything worked correctly, you'll see the payload from your device streaming into the page, in real time.&nbsp;

Neat, _right_? But while we received a payload, we still don't understand what it means...

![](https://cdn-learn.adafruit.com/assets/assets/000/062/163/medium800/feather_appdata_undecoded.png?1537384997)

# Using LoraWAN and The Things Network with Feather

## Payload Decoding

## Decoding the Payload
If you're sending packets in strange formats or encodings (like we are!), The Things Network Console has a [programmable data decoder](https://www.thethingsnetwork.org/docs/devices/bytes.html) to decode the packets, and assign useful labels to the data.

 **Copy and paste the decoder script** below into the decoder's integrated text editor and **click save**.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/064/110/medium800thumb/feather_ezgif.com-video-to-gif_%2818%29.jpg?1540430536)

Then,&nbsp; **click the data tab**. Next to the raw payload data, you should see the decoded data for humidity and temperature.

![](https://cdn-learn.adafruit.com/assets/assets/000/063/937/medium800/feather_image.png?1540017369)

### Decoder Code
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/TheThingsNetwork_Feather/ttn_lmic_dht22_decoder.js

## Code
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/TheThingsNetwork_Feather/ttn-featherm0-dht/ttn-featherm0-dht.ino

# Using LoraWAN and The Things Network with Feather

## Add an OLED

![](https://cdn-learn.adafruit.com/assets/assets/000/062/175/medium800thumb/feather_ezgif.com-video-to-gif_%2816%29.jpg?1537392124)

Now that we've got our Feather M0 connecting to The Things Network, we'll add a FeatherWing OLED to view the active connection with The Things Network and the sensor measurements.

### Adafruit FeatherWing OLED - 128x32 OLED Add-on For Feather

[Adafruit FeatherWing OLED - 128x32 OLED Add-on For Feather](https://www.adafruit.com/product/2900)
A Feather board without ambition is a Feather board without FeatherWings! This is the **FeatherWing OLED** : it adds a 128x32 monochrome OLED plus 3 user buttons to _any_ Feather main board. Using our [Feather Stacking...](https://www.adafruit.com/products/2830)

In Stock
[Buy Now](https://www.adafruit.com/product/2900)
[Related Guides to the Product](https://learn.adafruit.com/products/2900/guides)
![Angled shot of a Adafruit FeatherWing OLED - 128x32 OLED Add-on For Feather connected to a white breadboard and a lithium battery. ](https://cdn-shop.adafruit.com/640x480/2900-10.jpg)

Snap the FeatherWing onto your Feather, navigate to the FeatherWing OLED Arduino Setup guide, and [follow the instructions to set up and test the OLED](https://learn.adafruit.com/adafruit-oled-featherwing/usage). Once you verify that the FeatherWing OLED works, **copy and paste the code below into a new sketch**.

Warning: 

## Code
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/TheThingsNetwork_Feather/ttn-otaa-feather-us915-dht22-OLED/ttn-otaa-feather-us915-dht22-OLED.ino

# Using LoraWAN and The Things Network with Feather

## Using a Feather 32u4

Danger: 

If you're using a feather with a small flash size (like the Feather 32u4), you'll need a smaller library to experiment with than the one in this guide.

Enter&nbsp;[TinyLoRa](https://github.com/adafruit/TinyLoRa), an Arduino Library for Feathers and arduino-compatibles using the HopeRF RFM95/96W module. It's less than 8kB, making it perfect for smaller chips! It's also compatible with the Feather M0 LoRa, in case you want a smaller communications library for your speedy M0.

One of the trade-offs of using this tiny library (compared to a more featured library like the MCCI-LMIC Library) is that it uses a different method of device registration, Activation-by-Personalization (ABP). Instead of performing a secure join procedure, the security keys are hardcoded into the Sketch and "burned" into the Feather during compilation.&nbsp;

## Parts
First, let's gather the parts required for this project.

### Adafruit Feather 32u4 RFM95 LoRa Radio- 868 or 915 MHz

[Adafruit Feather 32u4 RFM95 LoRa Radio- 868 or 915 MHz](https://www.adafruit.com/product/3078)
This is the&nbsp;**Adafruit Feather 32u4 LoRa Radio (RFM9x)****. **We call these _RadioFruits** ,**_ our take on an microcontroller with a "[Long Range (LoRa)](https://www.lora-alliance.org/)" packet radio transceiver with built...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3078)
[Related Guides to the Product](https://learn.adafruit.com/products/3078/guides)
![Angled Shot of Adafruit Feather Microcontroller.](https://cdn-shop.adafruit.com/640x480/3078-07.jpg)

### Part: DHT22 Temperature + Humidity Sensor
quantity: 1
The DHT22 is a basic, low-cost digital temperature and humidity sensor. 
[DHT22 Temperature + Humidity Sensor](https://www.adafruit.com/product/385)

### Part: Breadboard
quantity: 1
Half-Sized Breadboard
[Breadboard](https://www.adafruit.com/product/64)

### Part: Breadboard Wires
quantity: 1
Breadboard Wiring Bundle
[Breadboard Wires](https://www.adafruit.com/product/153)

## Wiring
Next, let's wire up our circuit.&nbsp;

Your _Feather does not come with an antenna_, but there are two ways of wiring one up.

&nbsp;

For this guide, and to keep the build cost-effective, we soldered a small, 82mm wire to the&nbsp; **ANT&nbsp;** pad.

&nbsp;

- Antenna Options and installation instructions are detailed on this product's learn guide's&nbsp;[_antenna options&nbsp;_page.&nbsp;](https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module/antenna-options)
- **Note:&nbsp;** Antenna length differs between regions, **make sure you cut the antenna to the correct length for your region.**

![featherm0.png](https://cdn-learn.adafruit.com/assets/assets/000/065/267/medium640/featherm0.png?1541609121)

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/065/265/medium800/feather_32u4lora-dht22-wiring_bb_resie.png?1541608992)

Make the following connections **between the Feather 32u4 and the DHT22** :

- **Feather 3V** &nbsp;to **&nbsp;DHT22 Pin 1**
- **Feather Pin 10&nbsp;** to&nbsp; **DHT22 Pin 2**
- **Feather Ground&nbsp;** to&nbsp; **DHT22 Pin 3**
- **Add a 10k ohm resistor&nbsp;** between the **DHT22's&nbsp;VCC (DHT Pin 1) and Data Pin (DHT Pin 2).**

# Using LoraWAN and The Things Network with Feather

## TinyLoRa TTN Setup

Danger: 

Warning: 

Before your Feather can communicate with The Things Network, you'll need to create an application.

First, we're going to register an account with TTN. [Navigate to their account registration page](https://account.thethingsnetwork.org/register) to set up an account.

Once logged in,&nbsp;[navigate to the The Things Network Console](https://console.thethingsnetwork.org/). This page is where you can register applications and add new devices or gateways. Click&nbsp; **Applications** &nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/065/275/medium800/feather_console-application.png?1541611433)

Click **Add Application**.&nbsp;

Fill out an&nbsp; **Application ID** &nbsp;to identify the application, and a **description** of what the application is. We set our&nbsp; **Handler Registration&nbsp;** to match our region, _us-west_. If you're not located in the U.S., TTN provides multiple regions for handler registration.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/065/269/medium800/feather_The_Things_Network_Console.png?1541609514)

Once created, you'll be directed to the Application Overview. From here, you can add devices, view data coming into (and out of) the application, add integrations for external services, and more. We'll come back to this section later in the guide.

**Click&nbsp;Register Device**

![](https://cdn-learn.adafruit.com/assets/assets/000/065/276/medium800/feather_The_Things_Network_Console_2.png?1541611535)

On the **Register Device Page** ,&nbsp;The **Device ID** should be a unique string to identify the device.&nbsp;

The&nbsp; **Device EUI&nbsp;** is the unique identifier which came in the same bag as your Radiofruit Feather. We'll pad the middle of the string with four zeroes. Lost your key? No worries - you can also click the "mix" icon to switch it to auto-generate.

The&nbsp; **App Key&nbsp;** will be randomly generated for you by TTN. Select the **App EUI** (used to identify the application) from the list.

![](https://cdn-learn.adafruit.com/assets/assets/000/065/277/medium800/feather_The_Things_Network_Console_4.png?1541611564)

Next, we're going to switch the device settings from Over-the-Air-Activation to Activation-by-Personalization. From the Device Overview, **click Settings**

![](https://cdn-learn.adafruit.com/assets/assets/000/065/278/medium800/feather_The_Things_Network_Console_5.png?1541611643)

On the settings screen,&nbsp; **change the Activation Method from OTAA to ABP**.

&nbsp;

Then,&nbsp; **switch the Frame Counter Width from 32b to 16b** &nbsp;and&nbsp; **disable frame counter checks**. TTN will display a warning, ignore it, and&nbsp; **click Save**.

![feather_The_Things_Network_Console.png](https://cdn-learn.adafruit.com/assets/assets/000/065/281/medium640/feather_The_Things_Network_Console.png?1541611982)

![feather_The_Things_Network_Console_6.png](https://cdn-learn.adafruit.com/assets/assets/000/065/282/medium640/feather_The_Things_Network_Console_6.png?1541611997)

Warning: 

Now that the application is set up, and the device is registered to the application, let's move on to setting up Arduino with TinyLoRa.

### 

Disabling frame counter checks allows you to transmit data to The Things Network without requiring a match between your device's frame counter and the console's frame counter.

If you're making a project and doing a lot of prototyping/iteration to the code, disabling these checks is&nbsp;_okay_ as it'll let you reset the device and not re-register it to the application (it'll also prevent counter overflows).

If you're deploying a project, you'll want to re-activate the frame counter for security purposes. With the frame counter disabled, one could re-transmit the messages sent to TTN using a replay attack.&nbsp;

The Things Network's documentation page has&nbsp;[a full explanation about the role of the Frame Counter](https://www.thethingsnetwork.org/docs/lorawan/security.html#frame-counters).

# Using LoraWAN and The Things Network with Feather

## TinyLoRa Arduino Setup

Before proceeding with this page, make sure your board is correctly set-up by following the&nbsp;[_Using the Arduino IDE_](https://learn.adafruit.com/adafruit-feather-32u4-radio-with-lora-radio-module/setup)&nbsp; page of the setup guide for the Feather 32u4 LoRa.

To install [the TinyLoRa library](https://github.com/adafruit/TinyLoRa), **Open the Arduino Library Manager** ( **Sketch-\>Include Library-\>Manage Libraries** ). **In the search box, type&nbsp;** _ **TinyLoRa.** _ The _TinyLoRa_&nbsp;library should be the first result.&nbsp; **Click Install.**

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/065/284/medium800/feather_Library_Manager.png?1541612229)

We've added an example for using the DHT22 with the TinyLoRa Library.

To open it from the Arduino IDE, click **File -\> Examples -\> TinyLoRa -\> tinylora\_dht22**

![](https://cdn-learn.adafruit.com/assets/assets/000/065/308/medium800/feather_Pasted_Image_11_7_18__3_15_PM.png?1541621808)

The Arduino IDE should open a new window with the&nbsp;_tinylora\_dht22_ sketch.

![](https://cdn-learn.adafruit.com/assets/assets/000/065/306/medium800/feather_tinylora_dht22___Arduino_1_8_7_and_Skitch.png?1541621643)

Now that our IDE is setup up, let's learn how to send data from our Feather to The Things Network and decode it!

# Using LoraWAN and The Things Network with Feather

## TinyLoRa Usage

## Code Setup

To register your Feather with The Things Network using ABP, you'll need to set three unique identifiers in the sketch: the&nbsp;`Network Session Key`, the&nbsp;`Device Address`, and the&nbsp;`Application Session Key`.

Navigate to the&nbsp; **Device Overview&nbsp;** page for your Feather device.

&nbsp;

Make sure the&nbsp; **Activation Method** is set to **ABP**.&nbsp;

![feather_The_Things_Network_Console_7.png](https://cdn-learn.adafruit.com/assets/assets/000/065/310/medium640/feather_The_Things_Network_Console_7.png?1541622006)

Before adding the unique identifiers to our sketch, we'll need to first expand them by **clicking the \<\> icon**.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/065/311/medium800thumb/feather_keyexpandconsole.jpg?1541622113)

We're going to copy each unique identifier from the Device Overview to the variables within the sketch.

First, copy the&nbsp; **Network Session Key** &nbsp;from the TTN console to the `NwkSkey` **&nbsp;** variable in the sketch.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/065/312/medium800/feather_networkkey.png?1541622407)

Next, copy the&nbsp; **Application Session Key** &nbsp;from the TTN console to the `AppSkey` **&nbsp;** variable in the sketch.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/065/313/medium800/feather_appskey.png?1541622414)

Finally, copy the&nbsp; **Device Address** &nbsp;from the TTN console to the `DevAddr` **&nbsp;** variable in the sketch.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/065/314/medium800/feather_devaddr.png?1541622421)

That's all for now - we're ready to upload the code onto our Arduino.&nbsp;

Note that to see the output you'll need to open up the Serial console. Once you've debugged your example, you can comment out or remove the `while (! Serial);` line from `setup()`

## Running the Sketch

Compile ( **cmd/ctrl+r** ) and upload ( **cmd/ctrl+u** ) the sketch to the Feather.&nbsp;

Then, open the Serial Monitor. You should see the humidity and temperature values printed to the console. Then, the serial should print out the frame counter value.&nbsp;

Unlike the example using the OTAA activation method, the device does not send join requests to the network. Each time `lora.sendData()` is called, it'll randomize the frequency (from region-specific bands) and broadcast.

```
Starting LoRa...
Humidity: 33.20 %	Temperature: 23.30
Sending LoRa Data...
Frame Counter: 0
delaying...

```

## Checking Data on The Things Network Console

We want to make sure the data has been received on the other end. To do this, we'll navigate to the The Things Network Console and select the **application**. From the menu on the right hand side of the page,&nbsp; **Click&nbsp;Data**.

![](https://cdn-learn.adafruit.com/assets/assets/000/065/315/medium800/feather_Pasted_Image_11_7_18__3_46_PM.png?1541623636)

If everything worked correctly, you'll see the payload from your device streaming into the page, in real time.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/065/316/medium800/feather_The_Things_Network_Console_data.png?1541623985)

Neat, _right_? But while we received a payload, we still don't understand what it means...

## Decoding the Payload
If you're sending packets in strange formats or encodings (like we are!), The Things Network Console has a [programmable data decoder](https://www.thethingsnetwork.org/docs/devices/bytes.html) to decode the packets, and assign useful labels to the data.

 **Copy and paste the decoder script** below into the decoder's integrated text editor and **click save**.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/065/321/medium800thumb/feather_add_decoder.jpg?1541624213)

Then,&nbsp; **click the data tab**. Next to the raw payload data, you should see the decoded data for humidity and temperature.

![](https://cdn-learn.adafruit.com/assets/assets/000/065/317/medium800/feather_The_Things_Network_Console_decoded.png?1541624011)

### Decoder Code
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/TheThingsNetwork_Feather/tinylora_dht22_decoder.js


## Featured Products

### Adafruit Feather M0 with RFM95 LoRa Radio - 900MHz

[Adafruit Feather M0 with RFM95 LoRa Radio - 900MHz](https://www.adafruit.com/product/3178)
This is the **Adafruit Feather M0 RFM95 LoRa Radio (900MHz)****. **We call these _RadioFruits** ,**_ our take on an microcontroller with a "[Long Range (LoRa)](https://www.lora-alliance.org/)" packet radio transceiver with built...

In Stock
[Buy Now](https://www.adafruit.com/product/3178)
[Related Guides to the Product](https://learn.adafruit.com/products/3178/guides)
### Adafruit Feather 32u4 RFM95 LoRa Radio- 868 or 915 MHz

[Adafruit Feather 32u4 RFM95 LoRa Radio- 868 or 915 MHz](https://www.adafruit.com/product/3078)
This is the&nbsp;**Adafruit Feather 32u4 LoRa Radio (RFM9x)****. **We call these _RadioFruits** ,**_ our take on an microcontroller with a "[Long Range (LoRa)](https://www.lora-alliance.org/)" packet radio transceiver with built...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3078)
[Related Guides to the Product](https://learn.adafruit.com/products/3078/guides)
### The Things Gateway - 915Mhz Version

[The Things Gateway - 915Mhz Version](https://www.adafruit.com/product/3943)
 **The**  **Things Gateway** is open! Come forth all ye who wish for a community-led, open-source&nbsp;Internet of Things smart city network. This Internet gateway router is [designed by The Things Network](https://www.thethingsnetwork.org/), so you know<a...></a...>

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/3943)
[Related Guides to the Product](https://learn.adafruit.com/products/3943/guides)
### 8 Channel LoRa Gateway HAT with LoRa and GPS Antenna - SX1301

[8 Channel LoRa Gateway HAT with LoRa and GPS Antenna - SX1301](https://www.adafruit.com/product/4284)
If you're building a Raspberry Pi project and need to send data back-and-forth, the WiFi module built into newer Pi's should be fine for most cases.

_However_, WiFi does not have a long range and also requires both investment (through your ISP) and setup (routers, access...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/4284)
[Related Guides to the Product](https://learn.adafruit.com/products/4284/guides)
### DHT22  temperature-humidity sensor + extras

[DHT22  temperature-humidity sensor + extras](https://www.adafruit.com/product/385)
The DHT22 is a basic, low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin (no analog input pins needed). It's fairly simple to use but requires careful timing...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/385)
[Related Guides to the Product](https://learn.adafruit.com/products/385/guides)
### Half Sized Premium Breadboard - 400 Tie Points

[Half Sized Premium Breadboard - 400 Tie Points](https://www.adafruit.com/product/64)
This is a cute, half-size breadboard with&nbsp;400 tie points, good for small projects. It's 3.25" x 2.2" / 8.3cm&nbsp;x 5.5cm&nbsp;with a standard double-strip in the middle and two power rails on both sides.&nbsp;You can pull the power rails off easily to make the breadboard as...

Out of Stock
[Buy Now](https://www.adafruit.com/product/64)
[Related Guides to the Product](https://learn.adafruit.com/products/64/guides)
### Breadboarding wire bundle

[Breadboarding wire bundle](https://www.adafruit.com/product/153)
75 flexible stranded core wires with stiff ends molded on in red, orange, yellow, green, blue, brown, black and white. These are a major improvement over the "box of bent wires" that are sometimes sold with breadboards, and faster than stripping your own solid core wires. Makes...

In Stock
[Buy Now](https://www.adafruit.com/product/153)
[Related Guides to the Product](https://learn.adafruit.com/products/153/guides)
### Adafruit FeatherWing OLED - 128x32 OLED Add-on For Feather

[Adafruit FeatherWing OLED - 128x32 OLED Add-on For Feather](https://www.adafruit.com/product/2900)
A Feather board without ambition is a Feather board without FeatherWings! This is the **FeatherWing OLED** : it adds a 128x32 monochrome OLED plus 3 user buttons to _any_ Feather main board. Using our [Feather Stacking...](https://www.adafruit.com/products/2830)

In Stock
[Buy Now](https://www.adafruit.com/product/2900)
[Related Guides to the Product](https://learn.adafruit.com/products/2900/guides)

## Related Guides

- [Adafruit OLED FeatherWing](https://learn.adafruit.com/adafruit-oled-featherwing.md)
- [Introducing Adafruit Feather](https://learn.adafruit.com/adafruit-feather.md)
- [CircuitPython Hardware: Charlieplex LED Matrix](https://learn.adafruit.com/micropython-hardware-charlieplex-led-matrix.md)
- [Remote Effects Trigger Box](https://learn.adafruit.com/remote-effects-trigger.md)
- [Build a Cloud-Connected ESP8266 Power Meter](https://learn.adafruit.com/build-a-cloud-connected-esp8266-power-meter.md)
- [7 Segment Display Internet Clock](https://learn.adafruit.com/7-segment-display-internet-clock.md)
- [IoT Temperature Logger with Analog Devices ADT7410, Feather and Adafruit IO](https://learn.adafruit.com/iot-temperature-logger-with-arduino-and-adafruit-io.md)
- [CircuitPython Hardware: PCA9685 PWM & Servo Driver](https://learn.adafruit.com/micropython-hardware-pca9685-pwm-and-servo-driver.md)
- [MicroPython Displays: Drawing Shapes](https://learn.adafruit.com/micropython-displays-drawing-shapes.md)
- [3D Printed Case for Adafruit Feather](https://learn.adafruit.com/3d-printed-case-for-adafruit-feather.md)
- [Adafruit Feather M0 Radio with LoRa Radio Module](https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module.md)
- [WiFi OLED Display Badge](https://learn.adafruit.com/digital-display-badge.md)
- [CircuitPython 2FA TOTP Authentication Friend](https://learn.adafruit.com/circuitpython-totp-otp-2fa-authy-authenticator-friend.md)
- [Boomy The Boombox](https://learn.adafruit.com/boomy-the-boombox.md)
- [Stand for Feather ESP32 with Reverse TFT](https://learn.adafruit.com/stand-for-feather-esp32-with-reverse-tft.md)
- [PyPortal Thingiverse Viewer](https://learn.adafruit.com/pyportal-thingiverse-viewer.md)
