![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Lora
Dependencies: Cayenne-LPP HTU21D
Diff: main.cpp
- Revision:
- 49:120e166cb735
- Parent:
- 47:b6d132f1079f
diff -r dfce67eca082 -r 120e166cb735 main.cpp --- a/main.cpp Wed Feb 13 18:37:07 2019 +0000 +++ b/main.cpp Fri Mar 01 23:54:58 2019 +0000 @@ -19,20 +19,21 @@ #include "lorawan/LoRaWANInterface.h" #include "lorawan/system/lorawan_data_structures.h" #include "events/EventQueue.h" - +#include "HTU21D.h" // Application helpers #include "DummySensor.h" #include "trace_helper.h" #include "lora_radio_helper.h" - +#include "CayenneLPP.h" +#define MAX_SIZE 20 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[30]; uint8_t rx_buffer[30]; - +CayenneLPP Payload(MAX_SIZE); /* * Sets up an application dependent transmission timer in ms. Used only when Duty Cycling is off for testing */ @@ -59,7 +60,7 @@ * Dummy sensor class object */ DS1820 ds1820(PC_9); - +HTU21D temphumid(PB_14, PB_13); //Temp humid sensor || SDA, SCL /** * This event queue is the global event queue for both the * application and stack. To conserve memory, the stack is designed to run @@ -150,26 +151,28 @@ */ static void send_message() { - uint16_t packet_len; + int16_t retcode; - float sensor_value; + int sensor_value; + int sensor_value_2; - if (ds1820.begin()) { - ds1820.startConversion(); - sensor_value = ds1820.read(); - printf("\r\n Dummy Sensor Value = %3.1f \r\n", sensor_value); - ds1820.startConversion(); - } else { - printf("\r\n No sensor found \r\n"); - return; - } + sensor_value = temphumid.sample_ctemp(); + sensor_value_2=temphumid.sample_humid(); + //uint16_t value=uint16_t(10*sensor_value); + // uint8_t tx_buffer[4]={0x01,0x67,uint8_t(value>>8),uint8_t(value%256)}; + //packet_len=sizeof(tx_buffer); + //retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len,MSG_UNCONFIRMED_FLAG); - packet_len = sprintf((char *) tx_buffer, "Dummy Sensor Value is %3.1f", - sensor_value); + + Payload.reset(); + Payload.addTemperature(1, float(sensor_value)); + Payload.addRelativeHumidity(0, float(sensor_value_2)); + retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, Payload.getBuffer(), Payload.getSize(),MSG_UNCONFIRMED_FLAG); + //lorawan.send(Payload.getBuffer(), Payload.getSize()); - retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len, - MSG_UNCONFIRMED_FLAG); - + + printf("Temperature: %d C\n\r", sensor_value); + printf("Humidite: %d \n\r", sensor_value_2); if (retcode < 0) { retcode == LORAWAN_STATUS_WOULD_BLOCK ? printf("send - WOULD BLOCK\r\n") : printf("\r\n send() - Error code %d \r\n", retcode); @@ -182,9 +185,10 @@ } return; } - + /* printf("\r\n %d bytes scheduled for transmission \r\n", retcode); memset(tx_buffer, 0, sizeof(tx_buffer)); + */ } /** @@ -206,7 +210,7 @@ printf("%02x ", rx_buffer[i]); } printf("\r\n"); - + memset(rx_buffer, 0, sizeof(rx_buffer)); }