int main() { if (devaddr == 0x0) { printf("Set your LoRaWAN credentials first!\n"); return -1; } printf("Press BUTTON1 to send the current value of the temperature sensor!\n"); if (lorawan.initialize(&ev_queue) != LORAWAN_STATUS_OK) { printf("LoRa initialization failed!\n"); return -1; } // Enable trace output for this demo, so we can see what the LoRaWAN stack does mbed_trace_init(); // Fire a message when the button is pressed btn.fall(ev_queue.event(&send_message)); // prepare application callbacks callbacks.events = mbed::callback(lora_event_handler); lorawan.add_app_callbacks(&callbacks); // Disable adaptive data rating if (lorawan.disable_adaptive_datarate() != LORAWAN_STATUS_OK) { printf("disable_adaptive_datarate failed!\n"); return -1; } lorawan.set_datarate(5); // SF7BW125 lorawan_connect_t connect_params; connect_params.connect_type = LORAWAN_CONNECTION_ABP; connect_params.connection_u.abp.nwk_id = net_id; connect_params.connection_u.abp.dev_addr = devaddr; connect_params.connection_u.abp.nwk_skey = nwk_s_key; connect_params.connection_u.abp.app_skey = app_s_key; lorawan_status_t retcode = lorawan.connect(connect_params); if (retcode == LORAWAN_STATUS_OK || retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) { } else { printf("Connection error, code = %d\n", retcode); return -1; } printf("Connection - In Progress ...\r\n"); // make your event queue dispatching events forever ev_queue.dispatch_forever(); return 0; }