Skip to content

Commit 8a59191

Browse files
committed
STM32duinoLoraWan new basic example sending calendar packet
Modifying the basic.ino to format the Tx packet with the current calendar Date and Time Get the RTC as an external object initialized in MIX mode Signed-off-by: Francois Ramu <[email protected]>
1 parent d2da46d commit 8a59191

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

examples/Basic/Basic.ino

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* This is a very basic example that demonstrates how to configure the
33
* library, join the network, send regular packets and print any
44
* downlink packets received.
5+
* This example is using the RTC in MIX (binary and BCD) mode
56
*
67
* Revised BSD License - https://spdx.org/licenses/BSD-3-Clause.html
78
*/
@@ -11,6 +12,10 @@ STM32LoRaWAN modem;
1112

1213
static const unsigned long TX_INTERVAL = 60000; /* ms */
1314
unsigned long last_tx = 0;
15+
uint8_t payload[27]; /* packet to be sent */
16+
17+
/* Get the rtc object */
18+
extern STM32RTC &rtc;
1419

1520
void setup()
1621
{
@@ -29,11 +34,20 @@ void setup()
2934
Serial.println("Join failed");
3035
while (true) /* infinite loop */;
3136
}
37+
38+
/* set the calendar */
39+
rtc.setTime(15, 30, 58);
40+
rtc.setDate(04, 07, 23);
41+
3242
}
3343

3444
void send_packet()
3545
{
36-
uint8_t payload[] = {0xde, 0xad, 0xbe, 0xef};
46+
/* prepare the Tx packet : get date and format string */
47+
sprintf((char *)payload, "%02d/%02d/%04d - %02d:%02d:%02d",
48+
rtc.getMonth(), rtc.getDay(), 2000 + rtc.getYear(),
49+
rtc.getHours(), rtc.getMinutes(), rtc.getSeconds());
50+
3751
modem.setPort(10);
3852
modem.beginPacket();
3953
modem.write(payload, sizeof(payload));

0 commit comments

Comments
 (0)