Example #1
0
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;
}
Example #2
0
void worker_loop_start(void (*test_step_cb_fnc)(void), int timeout)
{
    int test_step_cb_timer = worker_loop_event_queue.call_every(timeout, test_step_cb_fnc);
    int timeout_outgoing_msg_timer = worker_loop_event_queue.call_every(1000, emac_if_timeout_outgoing_msg);

#if MBED_CONF_APP_ECHO_SERVER
    worker_loop_event_queue.dispatch_forever();
#else
    worker_loop_event_queue.dispatch(600 * SECOND_TO_MS);
#endif

    worker_loop_event_queue.cancel(test_step_cb_timer);
    worker_loop_event_queue.cancel(timeout_outgoing_msg_timer);

    worker_loop_event_queue.dispatch(5);
}