LoRaWAN demo.
Dependencies: modem_ref_helper DebouncedInterrupt
Diff: main.cpp
- Revision:
- 8:544a04d2bf55
- Parent:
- 5:2d5d3124703a
- Parent:
- 7:026f8c8bcdab
- Child:
- 12:18ab0181d584
--- a/main.cpp Tue Mar 13 17:20:14 2018 +0000 +++ b/main.cpp Thu Sep 20 09:41:15 2018 +0000 @@ -47,11 +47,8 @@ #endif - - - lwan_itf_cfg_t lwan_itf_ttn = { - .type = ALP_ITF_TYPE_LWAN, + .type = ALP_ITF_TYPE_LWAN, // 0: NONE, 1: OTAA, 2: ABP .cfg.activation_mode = 1, // XXX Only OTAA // LoRaWAN device class @@ -85,34 +82,15 @@ } } -void print_status(int status) +void print_resp(uint8_t id, int status) { switch (status) { case ALP_ERR_NONE: - //PRINT("Status: OK\n"); - break; - case ALP_ERR_FILE_EXIST: - PRINT("Status: Already registered\n"); + PRINT("Resp[%d]: OK\n", id); break; default: - PRINT("Status: error %d\n", status); - break; - } -} - -void print_resp(int status) -{ - switch (status) - { - case ALP_ERR_NONE: - //PRINT("Resp: OK\n"); - break; - case ALP_ERR_FILE_EXIST: - PRINT("Resp: Already registered\n"); - break; - default: - PRINT("Resp: error %d\n", status); + PRINT("Resp[%d]: error %d\n", id, status); break; } } @@ -122,15 +100,12 @@ { (void)id; + print_resp(id, err); + if (terminal) { - print_status(err); modem_ready[id].release(); } - else - { - print_resp(err); - } } static bool report_ok(uint32_t last_report_time) @@ -146,19 +121,19 @@ } // Check parameters to see if data should be send -static bool report_needed(sensor_config_t* config, int32_t value, int32_t last_value, uint32_t last_report_time, uint8_t user_id) +static bool report_needed(sensor_config_t* config, int32_t value, int32_t last_value, uint32_t last_report_time, uint8_t id) { switch (config->report_type) { case REPORT_ALWAYS: // Send a report at each measure - PRINT("Report[%d] always\r\n", user_id); + PRINT("Report[%d] always\r\n", id); return report_ok(last_report_time); case REPORT_ON_DIFFERENCE: // Send a report when the difference between the last reported measure and the current mesure is greater than max_diff if (abs(last_value - value) >= config->max_diff && config->max_diff) { - PRINT("Report[%d] on difference (last:%d new:%d max_diff:%d)\r\n", user_id, last_value, value, config->max_diff); + PRINT("Report[%d] on difference (last:%d new:%d max_diff:%d)\r\n", id, last_value, value, config->max_diff); return report_ok(last_report_time); } break; @@ -169,7 +144,7 @@ || (value < config->threshold_high && last_value >= config->threshold_high) || (value > config->threshold_low && last_value <= config->threshold_low)) { - PRINT("Report[%d] on threshold (last:%d new:%d th:%d tl:%d)\r\n", user_id, last_value, value, config->threshold_high, config->threshold_low); + PRINT("Report[%d] on threshold (last:%d new:%d th:%d tl:%d)\r\n", id, last_value, value, config->threshold_high, config->threshold_low); return report_ok(last_report_time); } break; @@ -180,7 +155,7 @@ // Send a report if it's been more than max_period since the last report if (((last_report_time/1000) >= config->max_period) && config->max_period) { - PRINT("Report[%d] on period (max_period:%d time:%d)\r\n", user_id, config->max_period, last_report_time); + PRINT("Report[%d] on period (max_period:%d time:%d)\r\n", id, config->max_period, last_report_time); return report_ok(last_report_time); } @@ -301,7 +276,8 @@ .lqual = my_lqual, .ldown = my_ldown, .reset = my_reset, - .boot = my_boot + .boot = my_boot, + .busy = my_busy, }; /*** Main function ------------------------------------------------------------- ***/