B-L072 ST Board BMP280 LoRaWAN end node
Dependencies: BME280
Temperature/Pressure LoRaWAN End Node
Diff: main.cpp
- Revision:
- 62:078d66d985f8
- Parent:
- 61:d220d51ae9d8
- Child:
- 63:7b4427c6bded
diff -r d220d51ae9d8 -r 078d66d985f8 main.cpp --- a/main.cpp Sat Jul 25 06:40:08 2020 +0000 +++ b/main.cpp Sat Jul 25 17:46:37 2020 +0000 @@ -5,18 +5,10 @@ #include "lorawan/system/lorawan_data_structures.h" #include "events/EventQueue.h" -//#include "trace_helper.h" #include "lora_radio_helper.h" using namespace events; -// Max payload size can be LORAMAC_PHY_MAXPAYLOAD. -// This example only communicates with much shorter messages (<30 bytes). -// If longer messages are used, these buffers must be changed accordingly. -//uint8_t tx_buffer[30]; -uint8_t tx_buffer[12]; -uint8_t rx_buffer[30]; - /* * Sets up an application dependent transmission timer in ms. Used only when Duty Cycling is off for testing */ @@ -37,8 +29,18 @@ #define DEBUG 1 #define BUFFER_SIZE 12 + +// Max payload size can be LORAMAC_PHY_MAXPAYLOAD. +// Use set_max_payload_length() function to change maximum payload capacity. + +uint8_t tx_buffer[BUFFER_SIZE]; + BME280 sensor(PB_9, PB_8, 0x77); +uint16_t packet_len = BUFFER_SIZE; +float sensor_values[3]; + + /** * This event queue is the global event queue for both the * application and stack. To conserve memory, the stack is designed to run @@ -46,6 +48,7 @@ * providing an event queue to the stack that will be used for ISR deferment as * well as application information event queuing. */ + static EventQueue ev_queue(MAX_NUMBER_OF_EVENTS *EVENTS_EVENT_SIZE); /** @@ -67,13 +70,9 @@ static lorawan_app_callbacks_t callbacks; static void send_message(); -/** - * Entry point for application - */ + int main(void) { - // setup tracing - //setup_trace(); // stores the status of a call to LoRaWAN protocol lorawan_status_t retcode; @@ -125,6 +124,7 @@ if(DEBUG) printf("\r\n Connection - In Progress ...\r\n"); + // make your event queue dispatching events forever ev_queue.dispatch_forever(); @@ -136,9 +136,7 @@ */ static void send_message() { - uint16_t packet_len = BUFFER_SIZE; int16_t retcode; - float sensor_values[3]; sensor.trigger(); sensor_values[0] = sensor.getTemperature(); @@ -147,10 +145,6 @@ memcpy(tx_buffer, sensor_values, packet_len); - //packet_len = sprintf((char *) tx_buffer, "Dummy Sensor Value is"); - - //retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len, MSG_UNCONFIRMED_FLAG); - retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len, MSG_UNCONFIRMED_FLAG); if (retcode < 0) { @@ -170,7 +164,9 @@ if(DEBUG) printf("\r\n %d bytes scheduled for transmission \r\n", retcode); - //memset(tx_buffer, 0, sizeof(tx_buffer)); + + //Check if radio wakes up automatically. If not, then call radio.TX(); + radio.sleep(); } /** @@ -178,22 +174,7 @@ */ static void receive_message() { - uint8_t port; - int flags; - int16_t retcode = lorawan.receive(rx_buffer, sizeof(rx_buffer), port, flags); - - if (retcode < 0) { - printf("\r\n receive() - Error code %d \r\n", retcode); - return; - } - - printf(" RX Data on port %u (%d bytes): ", port, retcode); - for (uint8_t i = 0; i < retcode; i++) { - printf("%02x ", rx_buffer[i]); - } - printf("\r\n"); - memset(rx_buffer, 0, sizeof(rx_buffer)); } /**