|
|
|
@ -37,6 +37,23 @@ static CayenneLPP cayenne(51); |
|
|
|
|
|
|
|
|
|
|
|
#if MBED_CONF_APP_BATTERY_ENABLED |
|
|
|
#if MBED_CONF_APP_BATTERY_ENABLED |
|
|
|
AnalogIn bat(MBED_CONF_APP_BATTERY_ADC); |
|
|
|
AnalogIn bat(MBED_CONF_APP_BATTERY_ADC); |
|
|
|
|
|
|
|
AnalogIn vrefint(ADC_VREF); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static float battery_voltage() { |
|
|
|
|
|
|
|
float vbat = bat.read(); |
|
|
|
|
|
|
|
double vdd = (1.224f) / vrefint.read(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return vbat * MBED_CONF_APP_BATTERY_RATIO * vdd; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t battery_level() { |
|
|
|
|
|
|
|
float vbat = battery_voltage(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double ratio = 253.0f / (4.2f - 3.3f); |
|
|
|
|
|
|
|
int value = ratio * (vbat - 3.4f) + 1.0f; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return value < 1 ? 1 : (value > 254 ? 254 : value); |
|
|
|
|
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#if MBED_CONF_APP_DHT_ENABLED |
|
|
|
#if MBED_CONF_APP_DHT_ENABLED |
|
|
|
@ -47,10 +64,7 @@ DHT dht(MBED_CONF_APP_DHT_DATA, MBED_CONF_APP_DHT_TYPE); |
|
|
|
HX711 loadcell(MBED_CONF_APP_HX711_CLK, MBED_CONF_APP_HX711_DATA); |
|
|
|
HX711 loadcell(MBED_CONF_APP_HX711_CLK, MBED_CONF_APP_HX711_DATA); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
//DigitalOut led(LED1, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(void) { |
|
|
|
int main(void) { |
|
|
|
|
|
|
|
|
|
|
|
lorawan_status_t retcode; |
|
|
|
lorawan_status_t retcode; |
|
|
|
|
|
|
|
|
|
|
|
#if MBED_CONF_APP_HX711_ENABLED |
|
|
|
#if MBED_CONF_APP_HX711_ENABLED |
|
|
|
@ -68,6 +82,9 @@ int main(void) { |
|
|
|
debug("\r\n Mbed LoRaWANStack initialized \r\n"); |
|
|
|
debug("\r\n Mbed LoRaWANStack initialized \r\n"); |
|
|
|
|
|
|
|
|
|
|
|
callbacks.events = mbed::callback(lora_event_handler); |
|
|
|
callbacks.events = mbed::callback(lora_event_handler); |
|
|
|
|
|
|
|
#if MBED_CONF_APP_BATTERY_ENABLED |
|
|
|
|
|
|
|
callbacks.battery_level = mbed::callback(battery_level); |
|
|
|
|
|
|
|
#endif |
|
|
|
lorawan.add_app_callbacks(&callbacks); |
|
|
|
lorawan.add_app_callbacks(&callbacks); |
|
|
|
|
|
|
|
|
|
|
|
// Set number of retries in case of CONFIRMED messages
|
|
|
|
// Set number of retries in case of CONFIRMED messages
|
|
|
|
@ -86,8 +103,6 @@ int main(void) { |
|
|
|
|
|
|
|
|
|
|
|
debug("\r\n Adaptive data rate (ADR) - Enabled \r\n"); |
|
|
|
debug("\r\n Adaptive data rate (ADR) - Enabled \r\n"); |
|
|
|
|
|
|
|
|
|
|
|
//led = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
retcode = lorawan.connect(); |
|
|
|
retcode = lorawan.connect(); |
|
|
|
|
|
|
|
|
|
|
|
if(retcode == LORAWAN_STATUS_OK || retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) { |
|
|
|
if(retcode == LORAWAN_STATUS_OK || retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) { |
|
|
|
@ -110,10 +125,8 @@ int main(void) { |
|
|
|
static void send_message() { |
|
|
|
static void send_message() { |
|
|
|
int16_t retcode; |
|
|
|
int16_t retcode; |
|
|
|
|
|
|
|
|
|
|
|
#if MBED_CONF_APP_BATTERY_ENABLED |
|
|
|
#if MBED_CONF_APP_BATTERY_ENABLED && MBED_CONF_APP_BATTERY_IN_LPP |
|
|
|
float vbat = bat.read(); |
|
|
|
cayenne.addAnalogInput(1, battery_voltage()); |
|
|
|
vbat = vbat * MBED_CONF_APP_BATTERY_RATIO * 3.3f; |
|
|
|
|
|
|
|
cayenne.addAnalogInput(1, vbat); |
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#if MBED_CONF_APP_DHT_ENABLED |
|
|
|
#if MBED_CONF_APP_DHT_ENABLED |
|
|
|
@ -128,7 +141,7 @@ static void send_message() { |
|
|
|
|
|
|
|
|
|
|
|
#if MBED_CONF_APP_HX711_ENABLED |
|
|
|
#if MBED_CONF_APP_HX711_ENABLED |
|
|
|
loadcell.powerUp(); |
|
|
|
loadcell.powerUp(); |
|
|
|
if (loadcell.waitReadyRetry(20, 100)) { |
|
|
|
if(loadcell.waitReadyRetry(20, 100)) { |
|
|
|
cayenne.addAnalogInput(2, loadcell.getUnits(5)); |
|
|
|
cayenne.addAnalogInput(2, loadcell.getUnits(5)); |
|
|
|
} |
|
|
|
} |
|
|
|
loadcell.powerDown(); |
|
|
|
loadcell.powerDown(); |
|
|
|
@ -179,7 +192,6 @@ static void receive_message() { |
|
|
|
static void lora_event_handler(lorawan_event_t event) { |
|
|
|
static void lora_event_handler(lorawan_event_t event) { |
|
|
|
switch(event) { |
|
|
|
switch(event) { |
|
|
|
case CONNECTED: |
|
|
|
case CONNECTED: |
|
|
|
//led = 1;
|
|
|
|
|
|
|
|
debug("\r\n Connection - Successful \r\n"); |
|
|
|
debug("\r\n Connection - Successful \r\n"); |
|
|
|
if(MBED_CONF_LORA_DUTY_CYCLE_ON) { |
|
|
|
if(MBED_CONF_LORA_DUTY_CYCLE_ON) { |
|
|
|
send_message(); |
|
|
|
send_message(); |
|
|
|
|