-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcatena_hello_lora.ino
82 lines (63 loc) · 2.16 KB
/
catena_hello_lora.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
Module: catena_hello_lora.ino
Function:
Simple hello-world (and compile-test) app
Copyright notice and License:
See LICENSE file accompanying this project.
Author:
Terry Moore, MCCI Corporation April 2018
*/
#include <Catena.h>
#include <Catena_Led.h>
using namespace McciCatena;
// declare the global object for the platform.
Catena gCatena;
Catena::LoRaWAN gLoRaWAN;
// declare the LED object
StatusLed gLed (Catena::PIN_STATUS_LED);
// declare the callback function.
Arduino_LoRaWAN::SendBufferCbFn uplinkDone;
bool gfSuccess;
bool gfTxStarted;
bool gfTxDone;
uint8_t uplinkBuffer[] = { 0xCA, 0xFE, 0xBA, 0xBE };
void setup()
{
gCatena.begin();
gCatena.SafePrintf("Hello, world (with LoRa)!\n");
gCatena.SafePrintf("This is a basic demo program for the MCCI Catena-Arduino-Platform library.\n");
gCatena.SafePrintf("Enter 'help' for a list of commands.\n");
gCatena.SafePrintf("(remember to select 'Line Ending: Newline' at the bottom of the monitor window.)\n");
gLed.begin();
gCatena.registerObject(&gLed);
gLed.Set(LedPattern::FastFlash);
gLoRaWAN.begin(&gCatena);
gCatena.registerObject(&gLoRaWAN);
if (! gLoRaWAN.IsProvisioned())
gCatena.SafePrintf("LoRaWAN not provisioned yet. Use the commands to set it up.\n");
else
{
// send a confirmed uplink
if (gLoRaWAN.SendBuffer(uplinkBuffer, sizeof(uplinkBuffer), uplinkDone, nullptr, true, /* port */ 16))
gfTxStarted = true;
else
gCatena.SafePrintf("SendBuffer failed!\n");
}
}
void loop()
{
gCatena.poll();
if (gfTxStarted && gfTxDone)
{
gfTxStarted = false;
if (gfSuccess)
gCatena.SafePrintf("Transmit succeeded.\n");
else
gCatena.SafePrintf("Message uplink failed!\n");
}
}
void uplinkDone(void *pCtx, bool fSuccess)
{
gfTxDone = true;
gfSuccess = fSuccess;
}