Skip to content

Commit 31866b7

Browse files
committed
Update to latest library, fixes #2
1 parent 7f9046a commit 31866b7

File tree

13 files changed

+385
-116
lines changed

13 files changed

+385
-116
lines changed

AUTHORS

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,2 @@
1-
# This is the official list of The Things Network authors for copyright purposes.
2-
#
3-
# The copyright owners listed in this document agree to release their work under
4-
# the MIT license that can be found in the LICENSE file.
5-
#
6-
# Names should be added to this file as
7-
# Firstname Lastname <email@address>
8-
#
9-
# Please keep the list sorted.
10-
111
Johan Stokking <johan@thethingsnetwork.org>
122
Fokke Zandbergen <mail@fokkezb.nl>

examples/Get-Device-Info/Get-Device-Info.ino renamed to examples/DeviceInfo/DeviceInfo.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#define debugSerial Serial
44
#define loraSerial Serial1
55

6-
TheThingsNetwork ttn;
6+
TheThingsNetwork THETHINGSNETWORK;
77

88
void setup()
99
{
@@ -12,14 +12,14 @@ void setup()
1212

1313
delay(3000);
1414

15-
ttn.init(loraSerial, debugSerial); //Initializing...
15+
THETHINGSNETWORK.init(loraSerial, debugSerial);
1616
}
1717

1818
void loop()
1919
{
2020
debugSerial.println("Device Information");
2121
debugSerial.println();
22-
ttn.showStatus();
22+
THETHINGSNETWORK.showStatus();
2323
debugSerial.println();
2424
debugSerial.println("Use the EUI to register the device for OTAA");
2525
debugSerial.println("-------------------------------------------");

examples/Downlink/downlink.ino

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <TheThingsNetwork.h>
2+
3+
// Set your AppEUI and AppKey
4+
const byte appEui[8] = { <insert AppEui> }; //for example: {0x70, 0xB3, 0xD5, 0x7E, 0xE0, 0xE0, 0x01, 0x4A1};
5+
const byte appKey[16] = { <insert AppKey> }; //for example: {0x73, 0x6D, 0x24, 0xD2, 0x69, 0xBE, 0xE3, 0xAE, 0x0E, 0xCE, 0xF0, 0xBB, 0x6C, 0xA4, 0xBA, 0xFE};
6+
7+
#define debugSerial Serial
8+
#define loraSerial Serial1
9+
10+
#define debugPrintLn(...) { if (debugSerial) debugSerial.println(__VA_ARGS__); }
11+
#define debugPrint(...) { if (debugSerial) debugSerial.print(__VA_ARGS__); }
12+
13+
TheThingsNetwork THETHINGSNETWORK;
14+
15+
void setup()
16+
{
17+
debugSerial.begin(115200);
18+
loraSerial.begin(57600);
19+
20+
delay(1000);
21+
THETHINGSNETWORK.init(loraSerial, debugSerial); //Initializing...
22+
THETHINGSNETWORK.reset();
23+
if (!THETHINGSNETWORK.join(appEui, appKey)) {
24+
delay(6000);
25+
}
26+
27+
delay(6000);
28+
THETHINGSNETWORK.showStatus();
29+
debugPrintLn("Setup for The Things Network complete");
30+
31+
delay(1000);
32+
}
33+
34+
void loop() {
35+
// Send a byte
36+
byte buf[1];
37+
buf[0] = 20;
38+
int downlinkBytes = THETHINGSNETWORK.sendBytes(buf, 1);
39+
40+
if (downlinkBytes > 0) {
41+
debugPrintLn("Received " + String(downlinkBytes) + " bytes")
42+
// Print the received bytes
43+
for (int i = 0; i < downlinkBytes; i++) {
44+
debugPrint(String(THETHINGSNETWORK.downlink[i]) + " ");
45+
}
46+
debugPrintLn();
47+
}
48+
49+
delay(20000);
50+
}

examples/SendABP/SendABP.ino

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <TheThingsNetwork.h>
2+
3+
// Set your DevAddr
4+
const byte devAddr[4] = { <insert DevAddr> }; //for example: {0x02, 0xDE, 0xAE, 0x00};
5+
6+
// Set your NwkSKey and AppSKey
7+
const byte nwkSKey[16] = { <insert NwkSKey> }; //for example: {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};
8+
const byte appSKey[16] = { <insert AppSKey> }; //for example: {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};
9+
10+
// Set your message to send
11+
String message = "Hello world"; //sending a string of chars "Hello world"
12+
13+
#define debugSerial Serial
14+
#define loraSerial Serial1
15+
16+
#define debugPrintLn(...) { if (debugSerial) debugSerial.println(__VA_ARGS__); }
17+
#define debugPrint(...) { if (debugSerial) debugSerial.print(__VA_ARGS__); }
18+
19+
TheThingsNetwork THETHINGSNETWORK;
20+
21+
void setup() {
22+
debugSerial.begin(115200);
23+
loraSerial.begin(57600);
24+
25+
delay(1000);
26+
THETHINGSNETWORK.init(loraSerial, debugSerial);
27+
THETHINGSNETWORK.reset();
28+
29+
//the device will configure the LoRa module
30+
THETHINGSNETWORK.personalize(devAddr, nwkSKey, appSKey);
31+
32+
delay(6000);
33+
THETHINGSNETWORK.showStatus();
34+
debugPrintLn("Setup for The Things Network complete");
35+
36+
delay(1000);
37+
}
38+
39+
void loop() {
40+
41+
THETHINGSNETWORK.sendString(message);
42+
delay(20000);
43+
}

examples/SendOTAA/SendOTAA.ino

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <TheThingsNetwork.h>
2+
3+
// Set your AppEUI and AppKey
4+
const byte appEui[8] = { <insert AppEui> }; //for example: {0x70, 0xB3, 0xD5, 0x7E, 0xE0, 0xE0, 0x01, 0x4A1};
5+
const byte appKey[16] = { <insert AppKey> }; //for example: {0x73, 0x6D, 0x24, 0xD2, 0x69, 0xBE, 0xE3, 0xAE, 0x0E, 0xCE, 0xF0, 0xBB, 0x6C, 0xA4, 0xBA, 0xFE};
6+
7+
#define debugSerial Serial
8+
#define loraSerial Serial1
9+
10+
// Set your message to send
11+
String message = "Hello world"; //sending a string of chars "Hello world"
12+
13+
#define debugPrintLn(...) { if (debugSerial) debugSerial.println(__VA_ARGS__); }
14+
#define debugPrint(...) { if (debugSerial) debugSerial.print(__VA_ARGS__); }
15+
16+
TheThingsNetwork THETHINGSNETWORK;
17+
18+
void setup() {
19+
debugSerial.begin(115200);
20+
loraSerial.begin(57600);
21+
22+
delay(1000);
23+
THETHINGSNETWORK.init(loraSerial, debugSerial);
24+
THETHINGSNETWORK.reset();
25+
26+
//the device will attempt a join every second till the join is successfull
27+
while(!THETHINGSNETWORK.join(appEui, appKey)){
28+
delay(6000);
29+
}
30+
31+
digitalWrite(13, HIGH); //turn on LED to confirm join
32+
33+
delay(6000);
34+
THETHINGSNETWORK.showStatus();
35+
debugPrintLn("Setup for The Things Network complete");
36+
37+
delay(1000);
38+
}
39+
40+
void loop() {
41+
THETHINGSNETWORK.sendString(message);
42+
delay(20000);
43+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//This library is not installed by default, istall from library manager
2+
#include <DHT.h> //DHT sensor library by Adafruit, supports DHT11/21/22 Sensors, more info: https://github.com/adafruit/DHT-sensor-library
3+
#include <TheThingsNetwork.h>
4+
5+
// Set your AppEUI and AppKey
6+
const byte appEui[8] = { <insert AppEui> }; //for example: {0x70, 0xB3, 0xD5, 0x7E, 0xE0, 0xE0, 0x01, 0x4A1};
7+
const byte appKey[16] = { <insert AppKey> }; //for example: {0x73, 0x6D, 0x24, 0xD2, 0x69, 0xBE, 0xE3, 0xAE, 0x0E, 0xCE, 0xF0, 0xBB, 0x6C, 0xA4, 0xBA, 0xFE};
8+
9+
#define DHTPIN 2
10+
11+
//Choose your DHT sensor moddel
12+
//#define DHTTYPE DHT11
13+
//#define DHTTYPE DHT21
14+
#define DHTTYPE DHT22
15+
16+
DHT dht(DHTPIN, DHTTYPE);
17+
18+
//data array for transmitting data
19+
byte data[4];
20+
21+
#define debugSerial Serial
22+
#define loraSerial Serial1
23+
24+
#define debugPrintLn(...) { if (debugSerial) debugSerial.println(__VA_ARGS__); }
25+
#define debugPrint(...) { if (debugSerial) debugSerial.print(__VA_ARGS__); }
26+
27+
TheThingsNetwork THETHINGSNETWORK;
28+
29+
void setup() {
30+
debugSerial.begin(115200);
31+
loraSerial.begin(57600);
32+
33+
dht.begin();
34+
35+
delay(1000);
36+
THETHINGSNETWORK.init(loraSerial, debugSerial);
37+
THETHINGSNETWORK.reset();
38+
39+
//the device will attempt a join every second till the join is successfull
40+
while(!THETHINGSNETWORK.join(appEui, appKey)){
41+
delay(6000);
42+
}
43+
44+
digitalWrite(13, HIGH); //turn on LED to confirm join
45+
46+
delay(6000);
47+
THETHINGSNETWORK.showStatus();
48+
debugPrintLn("Setup for The Things Network complete");
49+
50+
delay(1000);
51+
}
52+
53+
void loop() {
54+
55+
uint16_t temperature = dht.readTemperature(false)*100; //false = temp-Celsius //true = temp-farenheit
56+
uint16_t humidity = dht.readHumidity(false)*100;
57+
//put data into the data array
58+
data[0] = highByte(temperature);
59+
data[1] = lowByte(temperature);
60+
data[2] = highByte(humidity);
61+
data[3] = lowByte(humidity);
62+
//debug print
63+
debugPrint("Transmitting Temperature: ");
64+
debugPrintLn(temperature);
65+
debugPrint("Humidity: ");
66+
debugPrintLn(humidity);
67+
//send data
68+
THETHINGSNETWORK.sendBytes(data, sizeof(data));
69+
70+
delay(20000);
71+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <TheThingsNetwork.h>
2+
3+
// Set your AppEUI and AppKey
4+
const byte appEui[8] = { <insert AppEui> }; //for example: {0x70, 0xB3, 0xD5, 0x7E, 0xE0, 0xE0, 0x01, 0x4A1};
5+
const byte appKey[16] = { <insert AppKey> }; //for example: {0x73, 0x6D, 0x24, 0xD2, 0x69, 0xBE, 0xE3, 0xAE, 0x0E, 0xCE, 0xF0, 0xBB, 0x6C, 0xA4, 0xBA, 0xFE};
6+
7+
//define AnalogPin for sensor
8+
#define LightPin A0
9+
10+
//data array for transmitting data
11+
byte data[2];
12+
13+
#define debugSerial Serial
14+
#define loraSerial Serial1
15+
16+
#define debugPrintLn(...) { if (debugSerial) debugSerial.println(__VA_ARGS__); }
17+
#define debugPrint(...) { if (debugSerial) debugSerial.print(__VA_ARGS__); }
18+
19+
TheThingsNetwork THETHINGSNETWORK;
20+
21+
void setup() {
22+
debugSerial.begin(115200);
23+
loraSerial.begin(57600);
24+
25+
pinMode(LightPin, INPUT);
26+
27+
delay(1000);
28+
THETHINGSNETWORK.init(loraSerial, debugSerial);
29+
THETHINGSNETWORK.reset();
30+
31+
//the device will attempt a join every second till the join is successfull
32+
while(!THETHINGSNETWORK.join(appEui, appKey)){
33+
delay(6000);
34+
}
35+
36+
digitalWrite(13, HIGH); //turn on LED to confirm join
37+
38+
delay(6000);
39+
THETHINGSNETWORK.showStatus();
40+
debugPrintLn("Setup for The Things Network complete");
41+
42+
delay(1000);
43+
}
44+
45+
void loop() {
46+
47+
uint16_t light = analogRead(LightPin);
48+
//put data into the data array
49+
data[0] = highByte(light);
50+
data[1] = lowByte(light);
51+
//debug print
52+
debugPrint("Transmitting Light level: ");
53+
debugPrintLn(light);
54+
//send data
55+
THETHINGSNETWORK.sendBytes(data, sizeof(data));
56+
57+
delay(20000);
58+
}

examples/Workshop/Workshop.ino

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <TheThingsNetwork.h>
2+
3+
// Before your start, make sure that in the Tools menu, your Board and your
4+
// Port is set to Arduino Leonardo
5+
6+
// After you registered your ABP device, go to The Things Network Dashboard
7+
// and copy the Device Addr, Network Session Key and App Session Key
8+
9+
// Set your Device Address, for example: { 0x02, 0xDE, 0xAE, 0x00 };
10+
const byte devAddr[4] = { ... };
11+
12+
// Set your Network Session Key, for example: { 0x2B, 0x7E, 0x15, 0x16, ... };
13+
// This is used by the network to identify your device
14+
const byte nwkSKey[16] = { ... };
15+
16+
// Set your Application Session Key, for example: { 0x2B, 0x7E, 0x15, 0x16, ... };
17+
// This is used by the network for encryption
18+
const byte appSKey[16] = { ... };
19+
20+
#define debugSerial Serial
21+
#define loraSerial Serial1
22+
23+
#define debugPrintLn(...) { if (debugSerial) debugSerial.println(__VA_ARGS__); }
24+
#define debugPrint(...) { if (debugSerial) debugSerial.print(__VA_ARGS__); }
25+
26+
TheThingsNetwork THETHINGSNETWORK;
27+
28+
void setup() {
29+
// Set up the serial interfaces for the debugging serial monitor and LoRa module
30+
debugSerial.begin(115200);
31+
loraSerial.begin(57600);
32+
delay(1000);
33+
34+
// Initialize and reset The Things Uno
35+
THETHINGSNETWORK.init(loraSerial, debugSerial);
36+
THETHINGSNETWORK.reset();
37+
38+
// Here we activate the device with your address and keys
39+
THETHINGSNETWORK.personalize(devAddr, nwkSKey, appSKey);
40+
41+
// Show the status on the debugging serial monitor
42+
THETHINGSNETWORK.showStatus();
43+
debugPrintLn("Setup for The Things Network complete");
44+
}
45+
46+
void loop() {
47+
// Create a buffer with three bytes
48+
byte data[3] = { 0x01, 0x02, 0x03 };
49+
50+
// Send it to the network
51+
THETHINGSNETWORK.sendBytes(data, sizeof(data));
52+
53+
// Wait 10 seconds
54+
delay(10000);
55+
}

0 commit comments

Comments
 (0)