Skip to content

Commit 3f3ba0d

Browse files
Merge pull request #183 from TheThingsNetwork/fix/cleanup
Various fixes and code cleanup
2 parents a39a9b7 + 4932859 commit 3f3ba0d

30 files changed

+1817
-1611
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ before_script:
1818
# Replace placeholders with actual frequency plan (on Mac OS folow -i by '')
1919
- find $PWD/examples -type f -name "*.ino" -exec sed -i 's/REPLACE_ME/TTN_FP_EU868/g' {} +
2020
script:
21-
- test/verify arduino:avr:leonardo examples/ABP/ABP.ino
21+
- test/verify arduino:avr:leonardo examples/SendABP/SendABP.ino
2222
- test/verify arduino:avr:leonardo examples/DeviceInfo/DeviceInfo.ino
23-
- test/verify arduino:avr:leonardo examples/Message/Receive/Receive.ino
24-
- test/verify arduino:avr:leonardo examples/Message/Send/Send.ino
23+
- test/verify arduino:avr:leonardo examples/TheThingsMessage/Receive/Receive.ino
24+
- test/verify arduino:avr:leonardo examples/TheThingsMessage/Send/Send.ino
2525
- test/verify sparkfun:avr:promicro:cpu=8MHzatmega32U4 examples/Node/Node.ino
2626
- test/verify arduino:avr:leonardo examples/PassThrough/PassThrough.ino
2727
- test/verify arduino:avr:leonardo examples/QuickStart/QuickStart.ino
2828
- test/verify arduino:avr:leonardo examples/Receive/Receive.ino
29-
- test/verify arduino:avr:leonardo examples/Send/Send.ino
29+
- test/verify arduino:avr:leonardo examples/SendOTAA/SendOTAA.ino
3030
- test/verify arduino:avr:leonardo examples/Sensors/DHT/DHT.ino
3131
- test/verify arduino:avr:leonardo examples/Sensors/LightSensor/LightSensor.ino
3232
- test/verify arduino:avr:leonardo examples/Workshop/Workshop.ino

examples/Node/Node.ino

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ TheThingsNode *node;
1919
#define PORT_MOTION 3
2020
#define PORT_BUTTON 4
2121

22-
void setup() {
22+
void setup()
23+
{
2324
loraSerial.begin(57600);
2425
debugSerial.begin(9600);
2526

2627
// Wait a maximum of 10s for Serial Monitor
27-
while (!debugSerial && millis() < 10000);
28+
while (!debugSerial && millis() < 10000)
29+
;
2830

2931
// Config Node
3032
node = TheThingsNode::setup();
@@ -50,33 +52,39 @@ void setup() {
5052
sendData(PORT_SETUP);
5153
}
5254

53-
void loop() {
55+
void loop()
56+
{
5457
node->loop();
5558
}
5659

57-
void interval() {
60+
void interval()
61+
{
5862
node->setColor(TTN_BLUE);
59-
63+
6064
debugSerial.println("-- SEND: INTERVAL");
6165
sendData(PORT_INTERVAL);
6266
}
6367

64-
void wake() {
68+
void wake()
69+
{
6570
node->setColor(TTN_GREEN);
6671
}
6772

68-
void sleep() {
73+
void sleep()
74+
{
6975
node->setColor(TTN_BLACK);
7076
}
7177

72-
void onMotionStart() {
78+
void onMotionStart()
79+
{
7380
node->setColor(TTN_BLUE);
7481

7582
debugSerial.print("-- SEND: MOTION");
7683
sendData(PORT_MOTION);
7784
}
7885

79-
void onButtonRelease(unsigned long duration) {
86+
void onButtonRelease(unsigned long duration)
87+
{
8088
node->setColor(TTN_BLUE);
8189

8290
debugSerial.print("-- SEND: BUTTON");
@@ -85,25 +93,26 @@ void onButtonRelease(unsigned long duration) {
8593
sendData(PORT_BUTTON);
8694
}
8795

88-
void sendData(uint8_t port) {
96+
void sendData(uint8_t port)
97+
{
8998
ttn.showStatus();
9099
node->showStatus();
91100

92-
byte* bytes;
101+
byte *bytes;
93102
byte payload[6];
94103

95104
uint16_t battery = node->getBattery();
96-
bytes = (byte*) &battery;
105+
bytes = (byte *)&battery;
97106
payload[0] = bytes[1];
98107
payload[1] = bytes[0];
99108

100109
uint16_t light = node->getLight();
101-
bytes = (byte*) &light;
110+
bytes = (byte *)&light;
102111
payload[2] = bytes[1];
103112
payload[3] = bytes[0];
104113

105114
int16_t temperature = round(node->getTemperatureAsFloat() * 100);
106-
bytes = (byte*) &temperature;
115+
bytes = (byte *)&temperature;
107116
payload[4] = bytes[1];
108117
payload[5] = bytes[0];
109118

examples/PassThrough/PassThrough.ino

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,25 @@
1111
#define loraSerial Serial1
1212
#define debugSerial Serial
1313

14-
void setup() {
15-
while(!debugSerial || !loraSerial);
14+
void setup()
15+
{
16+
while (!debugSerial || !loraSerial)
17+
;
1618

1719
debugSerial.begin(115200);
1820
delay(1000);
1921

2022
loraSerial.begin(57600);
2123
}
2224

23-
void loop() {
24-
while (debugSerial.available()) {
25+
void loop()
26+
{
27+
while (debugSerial.available())
28+
{
2529
loraSerial.write(debugSerial.read());
2630
}
27-
while (loraSerial.available()) {
31+
while (loraSerial.available())
32+
{
2833
debugSerial.write(loraSerial.read());
2934
}
3035
}

examples/QuickStart/QuickStart.ino

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ const char *appKey = "00000000000000000000000000000000";
1212

1313
TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
1414

15-
void setup() {
15+
void setup()
16+
{
1617
loraSerial.begin(57600);
1718
debugSerial.begin(9600);
1819

1920
// Wait a maximum of 10s for Serial Monitor
20-
while (!debugSerial && millis() < 10000);
21+
while (!debugSerial && millis() < 10000)
22+
;
2123

2224
// Set callback for incoming messages
2325
ttn.onMessage(message);
@@ -29,7 +31,8 @@ void setup() {
2931
ttn.join(appEui, appKey);
3032
}
3133

32-
void loop() {
34+
void loop()
35+
{
3336
debugSerial.println("-- LOOP");
3437

3538
// Prepare payload of 1 byte to indicate LED status
@@ -42,19 +45,23 @@ void loop() {
4245
delay(10000);
4346
}
4447

45-
void message(const byte* payload, size_t length, port_t port) {
48+
void message(const byte *payload, size_t length, port_t port)
49+
{
4650
debugSerial.println("-- MESSAGE");
4751

4852
// Only handle messages of a single byte
49-
if (length != 1) {
53+
if (length != 1)
54+
{
5055
return;
5156
}
5257

53-
if (payload[0] == 0) {
58+
if (payload[0] == 0)
59+
{
5460
debugSerial.println("LED: off");
5561
digitalWrite(LED_BUILTIN, LOW);
56-
57-
} else if (payload[0] == 1) {
62+
}
63+
else if (payload[0] == 1)
64+
{
5865
debugSerial.println("LED: on");
5966
digitalWrite(LED_BUILTIN, HIGH);
6067
}

examples/Receive/Receive.ino

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ const char *appKey = "00000000000000000000000000000000";
1212

1313
TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
1414

15-
void setup() {
15+
void setup()
16+
{
1617
loraSerial.begin(57600);
1718
debugSerial.begin(9600);
1819

1920
// Wait a maximum of 10s for Serial Monitor
20-
while (!debugSerial && millis() < 10000);
21+
while (!debugSerial && millis() < 10000)
22+
;
2123

2224
// Set callback for incoming messages
2325
ttn.onMessage(message);
@@ -29,7 +31,8 @@ void setup() {
2931
ttn.join(appEui, appKey);
3032
}
3133

32-
void loop() {
34+
void loop()
35+
{
3336
debugSerial.println("-- LOOP");
3437

3538
// Send single byte to poll for incoming messages
@@ -38,11 +41,13 @@ void loop() {
3841
delay(10000);
3942
}
4043

41-
void message(const byte* payload, size_t length, port_t port) {
44+
void message(const uint8_t *payload, size_t size, port_t port)
45+
{
4246
debugSerial.println("-- MESSAGE");
43-
debugSerial.print("Received " + String(length) + " bytes on port " + String(port) + ":");
47+
debugSerial.print("Received " + String(size) + " bytes on port " + String(port) + ":");
4448

45-
for (int i = 0; i < length; i++) {
49+
for (int i = 0; i < size; i++)
50+
{
4651
debugSerial.print(" " + String(payload[i]));
4752
}
4853

examples/ABP/ABP.ino renamed to examples/SendABP/SendABP.ino

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ const char *appSKey = "00000000000000000000000000000000";
1313

1414
TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
1515

16-
void setup() {
16+
void setup()
17+
{
1718
loraSerial.begin(57600);
1819
debugSerial.begin(9600);
1920

2021
// Wait a maximum of 10s for Serial Monitor
21-
while (!debugSerial && millis() < 10000);
22+
while (!debugSerial && millis() < 10000)
23+
;
2224

2325
debugSerial.println("-- PERSONALIZE");
2426
ttn.personalize(devAddr, nwkSKey, appSKey);
@@ -27,7 +29,8 @@ void setup() {
2729
ttn.showStatus();
2830
}
2931

30-
void loop() {
32+
void loop()
33+
{
3134
debugSerial.println("-- LOOP");
3235

3336
// Prepare payload of 1 byte to indicate LED status

examples/Send/Send.ino renamed to examples/SendOTAA/SendOTAA.ino

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ const char *appKey = "00000000000000000000000000000000";
1212

1313
TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
1414

15-
void setup() {
15+
void setup()
16+
{
1617
loraSerial.begin(57600);
1718
debugSerial.begin(9600);
1819

1920
// Wait a maximum of 10s for Serial Monitor
20-
while (!debugSerial && millis() < 10000);
21+
while (!debugSerial && millis() < 10000)
22+
;
2123

2224
debugSerial.println("-- STATUS");
2325
ttn.showStatus();
@@ -26,7 +28,8 @@ void setup() {
2628
ttn.join(appEui, appKey);
2729
}
2830

29-
void loop() {
31+
void loop()
32+
{
3033
debugSerial.println("-- LOOP");
3134

3235
// Prepare payload of 1 byte to indicate LED status

examples/Sensors/DHT/DHT.ino

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ DHT dht(DHTPIN, DHTTYPE);
2424

2525
TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
2626

27-
void setup() {
27+
void setup()
28+
{
2829
loraSerial.begin(57600);
2930
debugSerial.begin(9600);
3031

3132
// Wait a maximum of 10s for Serial Monitor
32-
while (!debugSerial && millis() < 10000);
33+
while (!debugSerial && millis() < 10000)
34+
;
3335

3436
debugSerial.println("-- STATUS");
3537
ttn.showStatus();
@@ -40,7 +42,8 @@ void setup() {
4042
dht.begin();
4143
}
4244

43-
void loop() {
45+
void loop()
46+
{
4447
debugSerial.println("-- LOOP");
4548

4649
// Read sensor values and multiply by 100 to effictively have 2 decimals

examples/Sensors/LightSensor/LightSensor.ino

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ const char *appKey = "00000000000000000000000000000000";
1515

1616
TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
1717

18-
void setup() {
18+
void setup()
19+
{
1920
loraSerial.begin(57600);
2021
debugSerial.begin(9600);
2122

2223
// Wait a maximum of 10s for Serial Monitor
23-
while (!debugSerial && millis() < 10000);
24+
while (!debugSerial && millis() < 10000)
25+
;
2426

2527
pinMode(LightPin, INPUT);
2628

@@ -34,7 +36,8 @@ void setup() {
3436
debugSerial.println("Setup for The Things Network complete");
3537
}
3638

37-
void loop() {
39+
void loop()
40+
{
3841

3942
uint16_t light = analogRead(LightPin);
4043

examples/Message/Receive/Receive.ino renamed to examples/TheThingsMessage/Receive/Receive.ino

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ void setup()
2323
debugSerial.begin(9600);
2424

2525
// Wait a maximum of 10s for Serial Monitor
26-
while (!debugSerial && millis() < 10000);
26+
while (!debugSerial && millis() < 10000)
27+
;
2728

2829
debugSerial.println("-- STATUS");
2930
ttn.showStatus();
@@ -37,7 +38,8 @@ void setup()
3738
data.has_water = true;
3839
}
3940

40-
void loop() {
41+
void loop()
42+
{
4143
// Read sensors
4244
data.motion = digitalRead(TTN_PIN_LED) == HIGH;
4345
data.water = 682;
@@ -53,9 +55,11 @@ void loop() {
5355
delay(10000);
5456
}
5557

56-
void message(const byte* payload, size_t length, port_t port) {
58+
void message(const uint8_t *payload, size_t length, port_t port)
59+
{
5760
//standard message always received on port 100 or more
58-
if (port >= 100) {
61+
if (port >= 100)
62+
{
5963
appdata_t appData = api_AppData_init_default;
6064
TheThingsMessage::decodeAppData(&appData, payload, length);
6165
}

0 commit comments

Comments
 (0)