source/main.cpp
// Send a message over LoRaWAN - todo, check for duty cycle
Send a message over LoRaWAN - todo, check for duty cycle
Send a message over LoRaWAN - todo check for duty cycle
static void send_message() {
    if (in_class_c_mode) return;
#if MBED_CONF_LORAWAN_UPDATE_CLIENT_INTEROP_TESTING
    if (interop_crc32 != 0x0) {
        uint8_t buffer[6] = {
            DATA_BLOCK_AUTH_REQ, 0 ,
            interop_crc32 & 0xff, interop_crc32 >> 8 & 0xff, interop_crc32 >> 16 & 0xff, interop_crc32 >> 24 & 0xff
        };
        int16_t retcode = lorawan.send(201, buffer, sizeof(buffer), MSG_UNCONFIRMED_FLAG);
        if (retcode < 0) {
            printf("send_message for DATA_BLOCK_AUTH_REQ on port %d failed (%d)\n", 201, retcode);
            queue_next_send_message();
        }
        else {
            printf("%d bytes scheduled for transmission on port %d\n", sizeof(buffer), 201);
        }
        return;
    }
#endif
    if (queued_message_waiting) {
        if (queued_message.port == MCCONTROL_PORT && queued_message.length == MC_CLASSC_SESSION_ANS_LENGTH
                && queued_message.data[0] == MC_CLASSC_SESSION_ANS) {
            uc.updateClassCSessionAns(&queued_message);
        }
        int16_t retcode = lorawan.send(
            queued_message.port,
            queued_message.data,
            queued_message.length,
            queued_message.confirmed ? MSG_CONFIRMED_FLAG : MSG_UNCONFIRMED_FLAG);
        if (retcode < 0) {
            printf("send_message for queued_message on port %d failed (%d)\n", queued_message.port, retcode);
            queue_next_send_message();
        }
        else {
            free(queued_message.data);
            queued_message_waiting = false;
            printf("%d bytes scheduled for transmission on port %d\n", queued_message.length, queued_message.port);
        }
        return;
    }
    if (!clock_is_synced) {
        uc.requestClockSync(true);
        queue_next_send_message();
        return;
    }
    int r = rand();
    int16_t retcode = lorawan.send(15, (uint8_t*)(&r), sizeof(r), MSG_UNCONFIRMED_FLAG);
    if (retcode < 0) {
        printf("send_message for normal message on port %d failed (%d)\n", 15, retcode);
        queue_next_send_message();
    }
    else {
        printf("%d bytes scheduled for transmission on port %d\n", sizeof(r), 15);
    }
}
static void send_message ( ) { if ( in_class_c_mode ) return ; #if MBED_CONF_LORAWAN_UPDATE_CLIENT_INTEROP_TESTING if ( interop_crc32 != 0x0 ) { uint8_t buffer [ 6 ] = { DATA_BLOCK_AUTH_REQ , 0 , interop_crc32 & 0xff , interop_crc32 >> 8 & 0xff , interop_crc32 >> 16 & 0xff , interop_crc32 >> 24 & 0xff } ; int16_t retcode = lorawan . send ( 201 , buffer , sizeof ( buffer ) , MSG_UNCONFIRMED_FLAG ) ; if ( retcode < 0 ) { printf ( " \n " , 201 , retcode ) ; queue_next_send_message ( ) ; } else { printf ( " \n " , sizeof ( buffer ) , 201 ) ; } return ; } #endif if ( queued_message_waiting ) { if ( queued_message . port == MCCONTROL_PORT && queued_message . length == MC_CLASSC_SESSION_ANS_LENGTH && queued_message . data [ 0 ] == MC_CLASSC_SESSION_ANS ) { uc . updateClassCSessionAns ( & queued_message ) ; } int16_t retcode = lorawan . send ( queued_message . port , queued_message . data , queued_message . length , queued_message . confirmed ? MSG_CONFIRMED_FLAG : MSG_UNCONFIRMED_FLAG ) ; if ( retcode < 0 ) { printf ( " \n " , queued_message . port , retcode ) ; queue_next_send_message ( ) ; } else { free ( queued_message . data ) ; queued_message_waiting = false ; printf ( " \n " , queued_message . length , queued_message . port ) ; } return ; } if ( ! clock_is_synced ) { uc . requestClockSync ( true ) ; queue_next_send_message ( ) ; return ; } int r = rand ( ) ; int16_t retcode = lorawan . send ( 15 , ( uint8_t * ) ( & r ) , sizeof ( r ) , MSG_UNCONFIRMED_FLAG ) ; if ( retcode < 0 ) { printf ( " \n " , 15 , retcode ) ; queue_next_send_message ( ) ; } else { printf ( " \n " , sizeof ( r ) , 15 ) ; } }
Send a message over LoRaWAN - todo, check for duty cycle
Send a message over LoRaWAN - todo check for duty cycle
// after calculating the crc32, that's the only thing we'll send /* fragIndex, always 0 */ // @todo: implement retries allowed // detect if this is class c session start message // because if so, we should change the timeToStart to the current moment as we don't send immediately // this will trigger a lora_uc_send command // in the next command we'll actually send it // otherwise just send a random message (this is where you'd put your sensor data)