Enabled dutycycle and changed scheduling
This commit is contained in:
@@ -130,6 +130,24 @@ int main(void) {
|
|||||||
*/
|
*/
|
||||||
static void send_message() {
|
static void send_message() {
|
||||||
int16_t retcode;
|
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
|
#if MBED_CONF_APP_DHT_ENABLED
|
||||||
int err = dht.read();
|
int err = dht.read();
|
||||||
@@ -199,13 +217,7 @@ static void lora_event_handler(lorawan_event_t event) {
|
|||||||
switch(event) {
|
switch(event) {
|
||||||
case CONNECTED:
|
case CONNECTED:
|
||||||
debug("\r\n Connection - Successful \r\n");
|
debug("\r\n Connection - Successful \r\n");
|
||||||
if(MBED_CONF_LORA_DUTY_CYCLE_ON) {
|
send_message();
|
||||||
send_message();
|
|
||||||
} else {
|
|
||||||
send_message();
|
|
||||||
ev_queue.call_every(MBED_CONF_APP_TX_TIMER, send_message);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case DISCONNECTED:
|
case DISCONNECTED:
|
||||||
ev_queue.break_dispatch();
|
ev_queue.break_dispatch();
|
||||||
@@ -213,19 +225,12 @@ static void lora_event_handler(lorawan_event_t event) {
|
|||||||
break;
|
break;
|
||||||
case TX_DONE:
|
case TX_DONE:
|
||||||
debug("\r\n Message Sent to Network Server \r\n");
|
debug("\r\n Message Sent to Network Server \r\n");
|
||||||
if(MBED_CONF_LORA_DUTY_CYCLE_ON) {
|
|
||||||
send_message();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case TX_TIMEOUT:
|
case TX_TIMEOUT:
|
||||||
case TX_ERROR:
|
case TX_ERROR:
|
||||||
case TX_CRYPTO_ERROR:
|
case TX_CRYPTO_ERROR:
|
||||||
case TX_SCHEDULING_ERROR:
|
case TX_SCHEDULING_ERROR:
|
||||||
debug("\r\n Transmission Error - EventCode = %d \r\n", event);
|
debug("\r\n Transmission Error - EventCode = %d \r\n", event);
|
||||||
// try again
|
|
||||||
if(MBED_CONF_LORA_DUTY_CYCLE_ON) {
|
|
||||||
send_message();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case RX_DONE:
|
case RX_DONE:
|
||||||
debug("\r\n Received message from Network Server \r\n");
|
debug("\r\n Received message from Network Server \r\n");
|
||||||
|
|||||||
+1
-1
@@ -50,7 +50,7 @@
|
|||||||
"platform.default-serial-baud-rate": 115200,
|
"platform.default-serial-baud-rate": 115200,
|
||||||
"lora.app-port": 3,
|
"lora.app-port": 3,
|
||||||
"lora.over-the-air-activation": true,
|
"lora.over-the-air-activation": true,
|
||||||
"lora.duty-cycle-on": false,
|
"lora.duty-cycle-on": true,
|
||||||
"lora.phy": 0,
|
"lora.phy": 0,
|
||||||
"lora.device-eui": "{ 0xAB, 0xBA, 0xAB, 0xBA, 0xAB, 0xBA, 0xAB, 0xBA }",
|
"lora.device-eui": "{ 0xAB, 0xBA, 0xAB, 0xBA, 0xAB, 0xBA, 0xAB, 0xBA }",
|
||||||
"lora.application-eui": "{ 0xAC, 0xCA, 0xAC, 0xCA, 0xAC, 0xCA, 0xAC, 0xCA }",
|
"lora.application-eui": "{ 0xAC, 0xCA, 0xAC, 0xCA, 0xAC, 0xCA, 0xAC, 0xCA }",
|
||||||
|
|||||||
Reference in New Issue
Block a user