Skip to content

Commit ce7c55a

Browse files
Merge pull request #142 from TheThingsNetwork/changeProto
Added fields in appData and sensorData
2 parents 5f385cb + e286e0b commit ce7c55a

17 files changed

+233
-140
lines changed

docs/TheThingsMessage.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# API Reference
2-
The `TheThingsMessage` class provides structs for sensor and application data you can encode and decode as bytes.
2+
The `TheThingsMessage` class provides structs for device and application data you can encode and decode as bytes.
33

44
## Class: TheThingsMessage
55

66
```c
77
#include <TheThingsMessage.h>
88
```
99

10-
## Type: sensordata_t
10+
## Type: devicedata_t
1111

12-
Create a struct of this type using `api_SensorData_init_default` as defaults.
12+
Create a struct of this type using `api_DeviceData_init_default` as defaults.
1313

1414
```c
15-
sensordata_t data = api_SensorData_init_default;
15+
devicedata_t data = api_DeviceData_init_default;
1616
```
1717

1818
Then in your `setup()` function select what fields of the struct should be included when encoding it as bytes:
@@ -41,14 +41,14 @@ You can also add other analog readings.
4141

4242
> **TODO:** Document how this works and include in example.
4343
44-
## Method: encodeSensorData
44+
## Method: encodeDeviceData
4545
Encode the message you want to send.
4646

4747
```c
48-
static void encodeSensorData(sensordata_t *data, byte **buffer, size_t *size);
48+
static void encodeDeviceData(devicedata_t *data, byte **buffer, size_t *size);
4949
```
5050
51-
- `sensordata_t *data`: Structure containing all the message we can send.
51+
- `devicedata_t *data`: Structure containing typical fields that devices send.
5252
- `byte **buffer`: Bytes to send.
5353
- `size_t *size`: The number of bytes to send.
5454
@@ -57,7 +57,7 @@ Usage:
5757
```c
5858
byte *buffer;
5959
size_t size;
60-
TheThingsMessage::encodeSensorData(&data, &buffer, &size);
60+
TheThingsMessage::encodeDeviceData(&data, &buffer, &size);
6161
```
6262

6363
## Method: decodeAppData

examples/Message/Receive/Receive.ino

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const char *appKey = "00000000000000000000000000000000";
1313

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

16-
sensordata_t sensorData = api_SensorData_init_default;
16+
devicedata_t data = api_DeviceData_init_default;
1717

1818
void setup()
1919
{
@@ -33,24 +33,21 @@ void setup()
3333

3434
ttn.onMessage(message);
3535

36-
sensorData.has_motion = true;
37-
sensorData.has_water = true;
38-
sensorData.has_temperature_celcius = false;
39-
sensorData.has_temperature_fahrenheit = false;
40-
sensorData.has_humidity = false;
36+
data.has_motion = true;
37+
data.has_water = true;
4138
}
4239

4340
void loop() {
4441
// Read sensors
45-
sensorData.motion = digitalRead(TTN_PIN_LED) == HIGH;
46-
sensorData.water = 682;
42+
data.motion = digitalRead(TTN_PIN_LED) == HIGH;
43+
data.water = 682;
4744

4845
// Encode data
4946
byte *buffer;
5047
size_t size;
5148

5249
// Send standard message on port 100
53-
TheThingsMessage::encodeSensorData(&sensorData, &buffer, &size);
50+
TheThingsMessage::encodeDeviceData(&data, &buffer, &size);
5451
ttn.sendBytes(buffer, size, 100);
5552

5653
delay(10000);

examples/Message/Send/Send.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const char *appKey = "00000000000000000000000000000000";
1313

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

16-
sensordata_t data = api_SensorData_init_default;
16+
devicedata_t data = api_DeviceData_init_default;
1717

1818
void setup() {
1919
loraSerial.begin(57600);
@@ -49,7 +49,7 @@ void loop() {
4949
// Encode the selected fields of the struct as bytes
5050
byte *buffer;
5151
size_t size;
52-
TheThingsMessage::encodeSensorData(&data, &buffer, &size);
52+
TheThingsMessage::encodeDeviceData(&data, &buffer, &size);
5353

5454
ttn.sendBytes(buffer, size);
5555

examples/waterNet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 68d00c1be0f938e848e84b569d19a9c3f75810ab

keywords.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ poll KEYWORD2
2323
calculateAirtime KEYWORD2
2424
airtime KEYWORD2
2525

26-
encodeSensorData KEYWORD2
26+
encodeDeviceData KEYWORD2
2727
decodeAppData KEYWORD2
2828

2929
#######################################

src/TheThingsMessage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ bool TheThingsMessage::decodeAppData(appdata_t *receiveData, const byte *payload
99
return true;
1010
}
1111

12-
void TheThingsMessage::encodeSensorData(sensordata_t *data, byte **buffer, size_t *size) {
12+
void TheThingsMessage::encodeDeviceData(devicedata_t *data, byte **buffer, size_t *size) {
1313
byte message[TTN_BUFFER_SIZE];
1414

1515
pb_ostream_t sendStream = pb_ostream_from_buffer(message, sizeof(message));
16-
pb_encode(&sendStream, api_SensorData_fields, data);
16+
pb_encode(&sendStream, api_DeviceData_fields, data);
1717
*buffer = message;
1818
*size = sendStream.bytes_written;
1919
}

src/TheThingsMessage.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
#include <pb.h>
66
#include <pb_encode.h>
77
#include <pb_decode.h>
8-
#include "sensorData.pb.h"
8+
#include "deviceData.pb.h"
99
#include "appData.pb.h"
1010

1111
#define TTN_PIN_LED A2
1212

13-
typedef api_SensorData sensordata_t;
13+
typedef api_DeviceData devicedata_t;
1414
typedef api_AppData appdata_t;
1515

1616
class TheThingsMessage
1717
{
1818
public:
19-
static void encodeSensorData(sensordata_t *data, byte **buffer, size_t *size);
19+
static void encodeDeviceData(devicedata_t *data, byte **buffer, size_t *size);
2020
static bool decodeAppData(appdata_t *receiveData, const byte *payload, size_t length);
2121
};
2222

src/api/appData.proto

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ package api;
44

55
message AppData {
66
optional bool light = 1;
7-
}
7+
optional bool activation_limit = 2;
8+
optional bool switch_state = 3;
9+
optional float deactivation_limit = 4;
10+
}

src/api/deviceData.proto

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
syntax = "proto2";
2+
3+
package api;
4+
5+
message Location {
6+
optional float longitude = 1;
7+
optional float latitude = 2;
8+
optional int32 altitude = 3;
9+
}
10+
11+
message DeviceData {
12+
optional bool motion = 1;
13+
optional uint32 water = 2;
14+
optional float temperature_celcius = 3;
15+
optional float temperature_fahrenheit = 4;
16+
optional float humidity = 5;
17+
18+
optional Location location = 6;
19+
optional float level = 7;
20+
optional bool triggered = 8;
21+
optional bool actuator_active = 9;
22+
optional float actuator_time = 10;
23+
24+
repeated uint32 analog_readings = 110;
25+
}

src/api/sensorData.proto

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)