Browse Source

Added app parameters for available sensors and their configurations

nvstore
Anthony Hinsinger 8 years ago
parent
commit
a2c1bbffd4
  1. 24
      main.cpp
  2. 18
      mbed_app.json

24
main.cpp

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

18
mbed_app.json

@ -25,7 +25,14 @@
"lora-rxctl": { "value": "NC" }, "lora-rxctl": { "value": "NC" },
"lora-ant-switch": { "value": "NC" }, "lora-ant-switch": { "value": "NC" },
"lora-pwr-amp-ctl": { "value": "NC" }, "lora-pwr-amp-ctl": { "value": "NC" },
"lora-tcxo": { "value": "NC" } "lora-tcxo": { "value": "NC" },
"battery-enabled": { "value": "false" },
"battery-adc": { "value": "NC" },
"dht-enabled": { "value": "false" },
"dht-type": { "value": "DHT::DHT22" },
"dht-data": { "value": "NC" }
}, },
"target_overrides": { "target_overrides": {
"*": { "*": {
@ -251,7 +258,14 @@
"lora-rxctl": "ANT_CRX_RX", "lora-rxctl": "ANT_CRX_RX",
"lora-ant-switch": "NC", "lora-ant-switch": "NC",
"lora-pwr-amp-ctl": "NC", "lora-pwr-amp-ctl": "NC",
"lora-tcxo": "RF_TCXO_EN" "lora-tcxo": "RF_TCXO_EN",
"battery-enabled": true,
"battery-adc": "PA_2",
"dht-enabled": false,
"dht-data": "PA_1",
"dht-type": "DHT::DHT22"
} }
}, },
"macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_lora_config.h\""] "macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_lora_config.h\""]

Loading…
Cancel
Save