Projeto teste do Programa de integracao com biblioteca SGAM_MDW !! Aqui visa um usuario que usa o projeto implementado para a placa NUCLEO F429ZI
Dependencies: sgam_mdw sgam_mdw_NUCLEOF429ZI_impl Cayenne-LPP
Diff: main.cpp
- Revision:
- 26:8c55aac7887f
- Parent:
- 23:6869d0465b03
- Child:
- 28:18a54c786ba9
--- a/main.cpp Fri Jul 12 01:50:10 2019 +0000 +++ b/main.cpp Sat Jul 13 11:18:35 2019 -0300 @@ -7,6 +7,8 @@ #include "LoRaWANInterface.h" #include "lora_radio_helper.h" +#include "CayenneLPP.h" + ControlImpl ctrl; #define D_LOG(args...) printf(args) @@ -55,8 +57,7 @@ data->prepareCallBack(callbacks); // Flags de leitura !! - data->read_port = MBED_CONF_LORA_APP_PORT; - data->read_flags = MSG_CONFIRMED_FLAG|MSG_UNCONFIRMED_FLAG; + data->lora_port = MBED_CONF_LORA_APP_PORT; ///////////////////////////////////////////////////////////////////////////////////////////// // 2 - INICIALIZA A CONEXAO @@ -90,6 +91,9 @@ { printf("receive_message()\n"); + LoraData* data = (LoraData*) comm->getData(); + data->read_write_flags = MSG_CONFIRMED_FLAG|MSG_UNCONFIRMED_FLAG; + uint8_t rx_buffer[50] = { 0 }; int16_t retcode = comm->read( rx_buffer, sizeof(rx_buffer) ); if (retcode < 0) { @@ -112,36 +116,39 @@ printf("send_message()\n"); // YOUR CODE HERE - // int16_t temperature = 10; - // printf("temperature = (%d)\n", temperature); + int16_t temperature = 10; + printf("temperature = (%d)\n", temperature); - // CayenneLPP payload(50); - // payload.addTemperature(1, temperature); + CayenneLPP payload(50); + payload.addTemperature(1, temperature); - // int16_t retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, payload.getBuffer(), payload.getSize(), MSG_UNCONFIRMED_FLAG); - // printf("lorawan.send = retcode [%d]\n",retcode); + LoraData* data = (LoraData*) comm->getData(); + data->read_write_flags = MSG_UNCONFIRMED_FLAG; - // if (retcode < 0) { - // retcode == LORAWAN_STATUS_WOULD_BLOCK - // ? printf("send - Duty cycle violation\r\n") - // : printf("send() - Error code %d \r\n", retcode); + int16_t retcode = comm->write(payload.getBuffer(), payload.getSize()); + printf("lorawan.send = retcode [%d]\n",retcode); + + if (retcode < 0) { + retcode == LORAWAN_STATUS_WOULD_BLOCK + ? printf("send - Duty cycle violation\r\n") + : printf("send() - Error code %d \r\n", retcode); - // if (retcode == LORAWAN_STATUS_NO_ACTIVE_SESSIONS) - // printf("\r\n|-1017 - LORAWAN_STATUS_NO_ACTIVE_SESSIONS"); + if (retcode == LORAWAN_STATUS_NO_ACTIVE_SESSIONS) + printf("\r\n|-1017 - LORAWAN_STATUS_NO_ACTIVE_SESSIONS"); - // if (retcode == LORAWAN_STATUS_WOULD_BLOCK) { //retry in 3 seconds - // ev_queue.call_in(3000, send_message); - // } else { - // ev_queue.call_in(TX_INTERVAL, send_message); - // } + if (retcode == LORAWAN_STATUS_WOULD_BLOCK) { //retry in 3 seconds + ev_queue.call_in(3000, send_message); + } else { + ev_queue.call_in(TX_INTERVAL, send_message); + } - // return; - // } + return; + } - // ev_queue.call_in(TX_INTERVAL, send_message); + ev_queue.call_in(TX_INTERVAL, send_message); - // receive_message(); - // printf("%d bytes scheduled for transmission \r\n", retcode); + receive_message(); + printf("%d bytes scheduled for transmission \r\n", retcode); } /**