Skip to content

Commit aa1e0ed

Browse files
NicolasdejeanFokkeZB
authored andcommitted
Use strings for keys (closes #104)
1 parent ad73bc7 commit aa1e0ed

File tree

11 files changed

+57
-42
lines changed

11 files changed

+57
-42
lines changed

API.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ See the [Receive](https://github.com/TheThingsNetwork/arduino-device-lib/blob/ma
5555
Activate the device via OTAA (default).
5656
5757
```c
58-
bool join(const byte appEui[8], const byte appKey[16], int8_t retries = -1, uint32_t retryDelay = 10000);
58+
bool join(const char *appEui, const char *appKey, int8_t retries = -1, uint32_t retryDelay = 10000);
5959
bool join(int8_t retries = -1, uint32_t retryDelay = 10000);
6060
```
6161

62-
- `const byte appEui[8]`: Application EUI the device is registered to.
63-
- `const byte appKey[16]`: Application Key assigned to the device.
62+
- `const char *appEui`: Application EUI the device is registered to.
63+
- `const char *appKey`: Application Key assigned to the device.
6464
- `int8_t retries = -1`: Number of times to retry after failed or unconfirmed join. Defaults to `-1` which means infinite.
6565
- `uint32_t retryDelay = 10000`: Delay in ms between attempts. Defaults to 10 seconds.
6666

@@ -72,13 +72,13 @@ Call the method without the first two arguments if the device's LoRa module come
7272
Activate the device via ABP.
7373

7474
```c
75-
bool personalize(const byte devAddr[4], const byte nwkSKey[16], const byte appSKey[16]);
75+
bool personalize(const char *devAddr, const char *nwkSKey, const char *appSKey);
7676
bool personalize();
7777
```
7878
79-
- `const byte devAddr[4]`: Device Address assigned to the device.
80-
- `const byte nwkSKey[16]`: Network Session Key assigned to the device for identification.
81-
- `const byte appSKey[16]`: Application Session Key assigned to the device for encryption.
79+
- `const char *devAddr`: Device Address assigned to the device.
80+
- `const char *nwkSKey`: Network Session Key assigned to the device for identification.
81+
- `const char *appSKey`: Application Session Key assigned to the device for encryption.
8282
8383
Returns `true` or `false` depending on whether the activation was successful.
8484
@@ -124,8 +124,8 @@ See the [Receive](https://github.com/TheThingsNetwork/arduino-device-lib/blob/ma
124124
Sets the information needed to activate the device via OTAA, without actually activating. Call join() without the first 2 arguments to activate.
125125

126126
```c
127-
bool provision(const byte appEui[8], const byte appKey[16]);
127+
bool provision(const char *appEui, const char *appKey);
128128
```
129129
130-
- `const byte appEui[8]`: Application Identifier for the device.
131-
- `const byte appKey[16]`: Application Key assigned to the device.
130+
- `const char *appEui`: Application Identifier for the device.
131+
- `const char *appKey`: Application Key assigned to the device.

examples/ABP/ABP.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include <TheThingsNetwork.h>
22

33
// Set your DevAddr, NwkSKey and AppSKey
4-
const byte devAddr[4] = {0x00, 0x00, 0x00, 0x00};
5-
const byte nwkSKey[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
6-
const byte appSKey[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
4+
const char *devAddr = "00000000";
5+
const char *nwkSKey = "00000000000000000000000000000000";
6+
const char *appSKey = "00000000000000000000000000000000";
77

88
#define loraSerial Serial1
99
#define debugSerial Serial

examples/DeviceInfo/DeviceInfo.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ void loop()
2020
debugSerial.println("Use the EUI to register the device for OTAA");
2121
debugSerial.println("-------------------------------------------");
2222
debugSerial.println();
23-
23+
2424
delay(10000);
2525
}

examples/QuickStart/QuickStart.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <TheThingsNetwork.h>
22

33
// Set your AppEUI and AppKey
4-
const byte appEui[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5-
const byte appKey[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4+
const char *appEui = "0000000000000000";
5+
const char *appKey = "00000000000000000000000000000000";
66

77
#define loraSerial Serial1
88
#define debugSerial Serial

examples/Receive/Receive.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <TheThingsNetwork.h>
22

33
// Set your AppEUI and AppKey
4-
const byte appEui[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5-
const byte appKey[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4+
const char *appEui = "0000000000000000";
5+
const char *appKey = "00000000000000000000000000000000";
66

77
#define loraSerial Serial1
88
#define debugSerial Serial

examples/Send/Send.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <TheThingsNetwork.h>
22

33
// Set your AppEUI and AppKey
4-
const byte appEui[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5-
const byte appKey[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4+
const char *appEui = "0000000000000000";
5+
const char *appKey = "00000000000000000000000000000000";
66

77
#define loraSerial Serial1
88
#define debugSerial Serial

examples/Sensors/DHT/DHT.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <DHT.h>
55

66
// Set your AppEUI and AppKey
7-
const byte appEui[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
8-
const byte appKey[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
7+
const char *appEui = "0000000000000000";
8+
const char *appKey = "00000000000000000000000000000000";
99

1010
#define loraSerial Serial1
1111
#define debugSerial Serial

examples/Sensors/LightSensor/LightSensor.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <TheThingsNetwork.h>
22

33
// Set your AppEUI and AppKey
4-
const byte appEui[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5-
const byte appKey[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
4+
const char *appEui = "0000000000000000";
5+
const char *appKey = "00000000000000000000000000000000";
66

77
//define AnalogPin for sensor
88
#define LightPin A0

examples/Workshop/Workshop.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
// After you registered your ABP device, go to The Things Network Dashboard
77
// and copy the Device Addr, Network Session Key and App Session Key
88

9-
// Set your Device Address, for example: { 0x02, 0xDE, 0xAE, 0x00 };
10-
const byte devAddr[4] = { ... };
9+
// Set your Device Address, for example: "1C55B133";
10+
const char *devAddr = "00000000";
1111

12-
// Set your Network Session Key, for example: { 0x2B, 0x7E, 0x15, 0x16, ... };
12+
// Set your Network Session Key, for example: "0C11F84C5E4315CCDE50AB31C430BBE5";
1313
// This is used by the network to identify your device
14-
const byte nwkSKey[16] = { ... };
14+
const char *nwkSKey = "00000000000000000000000000000000";
1515

16-
// Set your Application Session Key, for example: { 0x2B, 0x7E, 0x15, 0x16, ... };
16+
// Set your Application Session Key, for example: "6C250A6B559B1BA0A51696ED20E3CF56";
1717
// This is used by the network for encryption
18-
const byte appSKey[16] = { ... };
18+
const char *appSKey = "00000000000000000000000000000000";
1919

2020
#define loraSerial Serial1
2121
#define debugSerial Serial

src/TheThingsNetwork.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,20 @@ void TheThingsNetwork::onMessage(void (*cb)(const byte* payload, size_t length,
100100
this->messageCallback = cb;
101101
}
102102

103-
bool TheThingsNetwork::personalize(const byte devAddr[4], const byte nwkSKey[16], const byte appSKey[16]) {
103+
bool TheThingsNetwork::personalize(const char *devAddr, const char *nwkSKey, const char *appSKey) {
104104
reset();
105-
sendCommand(F("mac set devaddr"), devAddr, 4);
106-
sendCommand(F("mac set nwkskey"), nwkSKey, 16);
107-
sendCommand(F("mac set appskey"), appSKey, 16);
105+
String addr = "mac set devaddr ";
106+
addr.concat(devAddr);
107+
sendCommand(addr);
108+
109+
String nKey = "mac set nwkskey ";
110+
nKey.concat(nwkSKey);
111+
sendCommand(nKey);
112+
113+
String aKey = "mac set appskey ";
114+
aKey.concat(appSKey);
115+
sendCommand(aKey);
116+
108117
return personalize();
109118
}
110119

@@ -124,9 +133,15 @@ bool TheThingsNetwork::personalize() {
124133
return true;
125134
}
126135

127-
bool TheThingsNetwork::provision(const byte appEui[8], const byte appKey[16]) {
128-
sendCommand(F("mac set appeui"), appEui, 8);
129-
sendCommand(F("mac set appkey"), appKey, 16);
136+
bool TheThingsNetwork::provision(const char *appEui, const char *appKey) {
137+
String eui = "mac set appeui ";
138+
eui.concat(appEui);
139+
sendCommand(eui);
140+
141+
String key = "mac set appkey ";
142+
key.concat(appKey);
143+
sendCommand(key);
144+
130145
return sendCommand(F("mac save"));
131146
}
132147

@@ -163,7 +178,7 @@ bool TheThingsNetwork::join(int8_t retries, uint32_t retryDelay) {
163178
return false;
164179
}
165180

166-
bool TheThingsNetwork::join(const byte appEui[8], const byte appKey[16], int8_t retries, uint32_t retryDelay) {
181+
bool TheThingsNetwork::join(const char *appEui, const char *appKey, int8_t retries, uint32_t retryDelay) {
167182
reset();
168183
provision(appEui, appKey);
169184
return join(retries, retryDelay);

0 commit comments

Comments
 (0)