Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the RTC in MIX mode and convert timeout values #25

Merged
merged 11 commits into from
Oct 12, 2023
2 changes: 1 addition & 1 deletion .github/workflows/check-astyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ jobs:
steps:
- run: sudo apt install astyle
- uses: actions/checkout@v3
- run: astyle --project=.astylerc --recursive '*.c' '*.h' '*.ino'
- run: astyle --project=.astylerc --recursive '*.c' '*.h'
# If anything changed, this will fail and show the needed changes
- run: git diff --exit-code
8 changes: 2 additions & 6 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,8 @@ This library makes use of:
- The radio module, obviously. The library handles enabling the module
and the associated SPI block, so nothing is needed in the sketch.

- The RTC for timing. This library currently completely configures the
RTC and defines the interrupt handler, making it impossible to use
the RTC for anything else. In the future, this library could be
modified to co-exist with e.g. the STM32RTC library or use
a (low-power) timer instead of the RTC, but this is not possible
right now.
- The RTC for timing (Since v0.2.0). This library uses the
[STM32RTC library](https://github.com/stm32duino/STM32RTC).

- A number of GPIO pins that are connected to external RF circuitry on
the board. This just uses the Arduino `digitalWrite()` functions.
30 changes: 20 additions & 10 deletions examples/Basic/Basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* This is a very basic example that demonstrates how to configure the
* library, join the network, send regular packets and print any
* downlink packets received.
* This example is using the RTC in MIX (binary and BCD) mode
*
* Revised BSD License - https://spdx.org/licenses/BSD-3-Clause.html
*/
Expand All @@ -12,8 +13,10 @@ STM32LoRaWAN modem;
static const unsigned long TX_INTERVAL = 60000; /* ms */
unsigned long last_tx = 0;

void setup()
{
/* Get the rtc object */
STM32RTC& rtc = STM32RTC::getInstance();

void setup() {
Serial.begin(115200);
Serial.println("Start");
modem.begin(EU868);
Expand All @@ -27,17 +30,25 @@ void setup()
Serial.println("Joined");
} else {
Serial.println("Join failed");
while (true) /* infinite loop */;
while (true) /* infinite loop */
;
}

/* set the calendar */
rtc.setTime(15, 30, 58);
rtc.setDate(04, 07, 23);
}

void send_packet()
{
uint8_t payload[] = {0xde, 0xad, 0xbe, 0xef};
void send_packet() {
char payload[27] = { 0 }; /* packet to be sent */
/* prepare the Tx packet : get date and format string */
sprintf(payload, "%02d/%02d/%04d - %02d:%02d:%02d",
rtc.getMonth(), rtc.getDay(), 2000 + rtc.getYear(),
rtc.getHours(), rtc.getMinutes(), rtc.getSeconds());
modem.setPort(10);
modem.beginPacket();
modem.write(payload, sizeof(payload));
if (modem.endPacket() == sizeof(payload)) {
modem.write(payload, strlen(payload));
if (modem.endPacket() == (int)strlen(payload)) {
Serial.println("Sent packet");
} else {
Serial.println("Failed to send packet");
Expand All @@ -57,8 +68,7 @@ void send_packet()
}
}

void loop()
{
void loop() {
if (!last_tx || millis() - last_tx > TX_INTERVAL) {
send_packet();
last_tx = millis();
Expand Down
4 changes: 2 additions & 2 deletions examples/ScheduledAsync/ScheduledAsync.ino
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void do_blink()
}

/*********************************************************************
* This part of the sketch defines the lora work task, which iniates new
* work and the lora_done() function that processes the results.
* This part of the sketch defines the lora work task, which initiates
* new work and the lora_done() function that processes the results.
*********************************************************************/

static const unsigned long TX_INTERVAL = 60000; /* ms */
Expand Down
1 change: 1 addition & 0 deletions library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ paragraph=Provides APIs to communicate with LoRa® and LoraWAN® networks
category=Communication
url=https://github.com/stm32duino/STM32LoRaWAN
architectures=stm32
depends=STM32duino RTC
50 changes: 0 additions & 50 deletions src/BSP/main.h

This file was deleted.

156 changes: 0 additions & 156 deletions src/BSP/rtc.c

This file was deleted.

53 changes: 0 additions & 53 deletions src/BSP/rtc.h

This file was deleted.

Loading