|
|
|
|
@ -4,7 +4,10 @@
@@ -4,7 +4,10 @@
|
|
|
|
|
#include "events/EventQueue.h" |
|
|
|
|
#include "lora_radio_helper.h" |
|
|
|
|
#include "CayenneLPP.h" |
|
|
|
|
|
|
|
|
|
#if MBED_CONF_APP_DHT_ENABLED |
|
|
|
|
#include "DHT.h" |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
using namespace events; |
|
|
|
|
|
|
|
|
|
@ -32,9 +35,15 @@ static void lora_event_handler(lorawan_event_t event);
@@ -32,9 +35,15 @@ static void lora_event_handler(lorawan_event_t event);
|
|
|
|
|
static LoRaWANInterface lorawan(radio); |
|
|
|
|
static lorawan_app_callbacks_t callbacks; |
|
|
|
|
static CayenneLPP cayenne(51); |
|
|
|
|
DHT dht(PA_1, DHT::DHT22); |
|
|
|
|
|
|
|
|
|
AnalogIn bat(PA_2); |
|
|
|
|
#if MBED_CONF_APP_BATTERY_ENABLED |
|
|
|
|
AnalogIn bat(MBED_CONF_APP_BATTERY_ADC); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if MBED_CONF_APP_DHT_ENABLED |
|
|
|
|
DHT dht(MBED_CONF_APP_DHT_DATA, MBED_CONF_APP_DHT_TYPE); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
DigitalOut led(LED1); |
|
|
|
|
|
|
|
|
|
int main(void) { |
|
|
|
|
@ -93,12 +102,13 @@ static void send_message()
@@ -93,12 +102,13 @@ static void send_message()
|
|
|
|
|
{ |
|
|
|
|
int16_t retcode; |
|
|
|
|
|
|
|
|
|
// vbat
|
|
|
|
|
#if MBED_CONF_APP_BATTERY_ENABLED |
|
|
|
|
float vbat = bat.read(); |
|
|
|
|
vbat = vbat*5/3*3.3f; |
|
|
|
|
cayenne.addAnalogInput(1, vbat); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// dht
|
|
|
|
|
#if MBED_CONF_APP_DHT_ENABLED |
|
|
|
|
int err = dht.read(); |
|
|
|
|
if (err == DHT::SUCCESS) { |
|
|
|
|
cayenne.addTemperature(1, dht.getTemperature()); |
|
|
|
|
@ -106,6 +116,12 @@ static void send_message()
@@ -106,6 +116,12 @@ static void send_message()
|
|
|
|
|
} else { |
|
|
|
|
printf("Error code : %d\r\n", err); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// No data to send
|
|
|
|
|
if (cayenne.getSize() == 0) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, cayenne.getBuffer(), cayenne.getSize(), |
|
|
|
|
MSG_UNCONFIRMED_FLAG); |
|
|
|
|
|