This repository has been archived by the owner on May 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
ttn-otaa.ino
56 lines (51 loc) · 1.62 KB
/
ttn-otaa.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <TTN_esp32.h>
#include "TTN_CayenneLPP.h"
/***************************************************************************
* Go to your TTN console register a device then the copy fields
* and replace the CHANGE_ME strings below
****************************************************************************/
const char* devEui = "CHANGE_ME"; // Change to TTN Device EUI
const char* appEui = "CHANGE_ME"; // Change to TTN Application EUI
const char* appKey = "CHANGE_ME"; // Chaneg to TTN Application Key
TTN_esp32 ttn ;
TTN_CayenneLPP lpp;
void message(const uint8_t* payload, size_t size, uint8_t port, int rssi)
{
Serial.println("-- MESSAGE");
Serial.printf("Received %d bytes on port %d (RSSI=%ddB) :", size, port, rssi);
for (int i = 0; i < size; i++)
{
Serial.printf(" %02X", payload[i]);
}
Serial.println();
}
void setup()
{
Serial.begin(115200);
Serial.println("Starting");
ttn.begin();
ttn.onMessage(message); // Declare callback function for handling downlink
// messages from server
ttn.join(devEui, appEui, appKey);
Serial.print("Joining TTN ");
while (!ttn.isJoined())
{
Serial.print(".");
delay(500);
}
Serial.println("\njoined !");
ttn.showStatus();
}
void loop()
{
static float nb = 18.2;
nb += 0.1;
lpp.reset();
lpp.addTemperature(1, nb);
if (ttn.sendBytes(lpp.getBuffer(), lpp.getSize()))
{
Serial.printf("Temp: %f TTN_CayenneLPP: %d %x %02X%02X\n", nb, lpp.getBuffer()[0], lpp.getBuffer()[1],
lpp.getBuffer()[2], lpp.getBuffer()[3]);
}
delay(10000);
}