Fix delay of first uplink message after join

After a join cancel the next scheduled doWork job and re-schedule it for
direct execution to prevent delay of the first uplink message.
This commit is contained in:
Leonel Lopes Parente 2021-05-23 16:40:44 +02:00
parent 4089d4773f
commit e5452124c7
3 changed files with 15 additions and 1 deletions

View file

@ -216,9 +216,14 @@ To run the job the `doWorkCallback()` function is executed by the LMIC scheduler
`doWorkCallback()` calls the `processWork()` function where the actual work is performed.
The first `doWork` run is started in `setup()`. On completion `doWork` reschedules itself for the next run.
When the node has joined and the `EV_JOINED` event is handled by the event handler, the next scheduled doWork job is cancelled and is re-scheduled for immediate execution. This is done to prevent that any uplink will have to wait until the current doWork interval ends. `processWork()` skips doing any work while the node is still joining. As a result sending the first uplink message may have to wait until the current doWork interval ends (max `DO_WORK_INTERVAL_SECONDS` seconds). Directly running the doWork job after a join prevents the in this case unnecessary and unwanted delay.
### 3.3 processWork() function
The `processWork()` function contains user code that performs the actual work like reading sensor data and scheduling uplink messages.
The `processWork()` function contains user code that performs the actual work like reading sensor data and scheduling uplink messages. In LMIC-node `processWork()` will skip doing any work if the node is still joining for two reasons:
1. To prevent unnecessary incrementing of the counter.
2. Uplink messages cannot yet be sent.
### 3.4 processDownlink() function

View file

@ -571,6 +571,14 @@ void onEvent(ev_t ev)
// during join, but because slow data rates change
// max TX size, it is not used in this example.
LMIC_setLinkCheckMode(0);
// The doWork job has probably run already (while
// the node was still joining) and have rescheduled itself.
// Cancel the next scheduled doWork job and re-schedule
// for immediate execution to prevent that any uplink will
// have to wait until the current doWork interval ends.
os_clearCallback(&doWorkJob);
os_setCallback(&doWorkJob, doWorkCallback);
break;
case EV_TXCOMPLETE:

View file

@ -44,6 +44,7 @@ enum class InitType { Hardware, PostInitSerial };
enum class PrintTarget { All, Serial, Display };
// Forward declarations
static void doWorkCallback(osjob_t* job);
void processWork(ostime_t timestamp);
void processDownlink(ostime_t eventTimestamp, uint8_t fPort, uint8_t* data, uint8_t dataLength);
void onLmicEvent(void *pUserData, ev_t ev);