LoRaWAN demo.
Dependencies: modem_ref_helper DebouncedInterrupt
Diff: main.cpp
- Revision:
- 7:026f8c8bcdab
- Parent:
- 4:f83753357cdf
- Child:
- 8:544a04d2bf55
--- a/main.cpp Mon Mar 05 16:47:22 2018 +0000 +++ b/main.cpp Thu Sep 20 09:37:24 2018 +0000 @@ -33,14 +33,15 @@ // https://account.thethingsnetwork.org/register // https://console.thethingsnetwork.org/applications 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 .cfg.dev_class = LWAN_CLASS_A, .cfg.dev_address = 0x700006BF, // For ABP Mode (Big Endian) .cfg.app_id = {0x70, 0xB3, 0xD5, 0x7E, 0xF0, 0x00, 0x3A, 0xF1 }, - .cfg.app_key = {0x73, 0x90, 0x54, 0x78, 0xB5, 0x0B, 0xA8, 0x9A, 0x78, 0x23, 0xB7, 0x12, 0xD5, 0x5C, 0x70, 0x99 }, + .cfg.app_key = {0x73, 0x90, 0x54, 0x78, 0xB5, 0x0B, 0xA8, 0x9A, + 0x78, 0x23, 0xB7, 0x12, 0xD5, 0x5C, 0x70, 0x99 }, // State of adaptative Datarate .cfg.adr_enable = 0, .cfg.app_skey = {0}, // For ABP Mode @@ -67,34 +68,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; } } @@ -104,15 +86,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) @@ -128,19 +107,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; @@ -151,7 +130,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; @@ -162,7 +141,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); } @@ -283,7 +262,8 @@ .lqual = my_lqual, .ldown = my_ldown, .reset = my_reset, - .boot = my_boot + .boot = my_boot, + .busy = my_busy, }; /*** Main function ------------------------------------------------------------- ***/