Browse Source

Enabled dutycycle and changed scheduling

master
Anthony Hinsinger 7 years ago
parent
commit
e73b620ef4
  1. 33
      main.cpp
  2. 2
      mbed_app.json

33
main.cpp

@ -130,6 +130,24 @@ int main(void) { @@ -130,6 +130,24 @@ int main(void) {
*/
static void send_message() {
int16_t retcode;
int eid;
// setup next transmission
eid = ev_queue.call_in(MBED_CONF_APP_TX_TIMER, send_message);
// check backoff time before sending new frame
if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
lorawan_status_t status;
int backoff;
status = lorawan.get_backoff_metadata(backoff);
if (status == LORAWAN_STATUS_OK && backoff > 0) {
debug("\r\n %d ms backoff, delay next send \r\n", backoff);
ev_queue.cancel(eid);
ev_queue.call_in(backoff+MBED_CONF_APP_TX_TIMER, send_message);
return;
}
}
#if MBED_CONF_APP_DHT_ENABLED
int err = dht.read();
@ -199,13 +217,7 @@ static void lora_event_handler(lorawan_event_t event) { @@ -199,13 +217,7 @@ static void lora_event_handler(lorawan_event_t event) {
switch(event) {
case CONNECTED:
debug("\r\n Connection - Successful \r\n");
if(MBED_CONF_LORA_DUTY_CYCLE_ON) {
send_message();
} else {
send_message();
ev_queue.call_every(MBED_CONF_APP_TX_TIMER, send_message);
}
send_message();
break;
case DISCONNECTED:
ev_queue.break_dispatch();
@ -213,19 +225,12 @@ static void lora_event_handler(lorawan_event_t event) { @@ -213,19 +225,12 @@ static void lora_event_handler(lorawan_event_t event) {
break;
case TX_DONE:
debug("\r\n Message Sent to Network Server \r\n");
if(MBED_CONF_LORA_DUTY_CYCLE_ON) {
send_message();
}
break;
case TX_TIMEOUT:
case TX_ERROR:
case TX_CRYPTO_ERROR:
case TX_SCHEDULING_ERROR:
debug("\r\n Transmission Error - EventCode = %d \r\n", event);
// try again
if(MBED_CONF_LORA_DUTY_CYCLE_ON) {
send_message();
}
break;
case RX_DONE:
debug("\r\n Received message from Network Server \r\n");

2
mbed_app.json

@ -50,7 +50,7 @@ @@ -50,7 +50,7 @@
"platform.default-serial-baud-rate": 115200,
"lora.app-port": 3,
"lora.over-the-air-activation": true,
"lora.duty-cycle-on": false,
"lora.duty-cycle-on": true,
"lora.phy": 0,
"lora.device-eui": "{ 0xAB, 0xBA, 0xAB, 0xBA, 0xAB, 0xBA, 0xAB, 0xBA }",
"lora.application-eui": "{ 0xAC, 0xCA, 0xAC, 0xCA, 0xAC, 0xCA, 0xAC, 0xCA }",

Loading…
Cancel
Save