Hi. Need some help to set the timer to > 1hour. It’s a limitation somewhere ?
Our Heavy machinery position don’t need to be checked every ~1h, maybe daily/weekly/… so,
the q. is: How I can increase the periodical running task time ?
I Should to use something else to manage this large data update period ?
Thank for all your suggestions, I’ll need them !
/// I made some tests using the folowing code from this forum:
#include <Arduino.h>
#include <SPI.h>
bool initMsg = true;
/* Time the device is sleeping in milliseconds = 2 minutes * 60 seconds * 1000 milliseconds */
#define SLEEP_TIME 7200000 // 2h
extern SemaphoreHandle_t loraEvent;
// Main loop stuff
void periodicWakeup(TimerHandle_t unused);
extern SemaphoreHandle_t taskEvent;
extern uint8_t rcvdDataLen;
extern uint8_t eventType;
/** Semaphore used by events to wake up loop task */
SemaphoreHandle_t taskEvent = NULL;
/** Timer to wakeup task frequently and send message */
SoftwareTimer taskWakeupTimer;
void periodicWakeup(TimerHandle_t unused)
{
// Give the semaphore, so the loop task will wake up
xSemaphoreGiveFromISR(taskEvent, pdFALSE);
}
void setup(void)
{
time_t serial_timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - serial_timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Serial.println("RAK Init => OK");
// Create the LoRaWan event semaphore
taskEvent = xSemaphoreCreateBinary();
// Initialize semaphore
xSemaphoreGive(taskEvent);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(LED_CONN, OUTPUT);
digitalWrite(LED_CONN, LOW);
digitalWrite(LED_BUILTIN, LOW);
xSemaphoreTake(taskEvent, 10);
taskWakeupTimer.begin(SLEEP_TIME, periodicWakeup);
taskWakeupTimer.start();
}
void loop(void)
{
// Try getting the semaphore, sleep while doing that
if (xSemaphoreTake(taskEvent, portMAX_DELAY) == pdTRUE || initMsg)
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
Serial.println("***");
digitalWrite(LED_BUILTIN, LOW);
initMsg = false;
// Go back to sleep
xSemaphoreTake(taskEvent, 10);
}
}