Browse Source

Added battery level in lora stack and nano libc profile

nvstore
Anthony Hinsinger 7 years ago
parent
commit
e71159cd35
  1. 2
      README.md
  2. 32
      main.cpp
  3. 2
      mbed_app.json.sample
  4. 2
      profiles/release.json

2
README.md

@ -15,7 +15,7 @@ mbed target NUCLEO_L073RZ
mbed config -G GCC_ARM_PATH /opt/gcc-arm-none-eabi-7-2017-q4-major/bin mbed config -G GCC_ARM_PATH /opt/gcc-arm-none-eabi-7-2017-q4-major/bin
cp mbed_app.json.sample mbed_app.json cp mbed_app.json.sample mbed_app.json
# modify lora.device-eui, lora.application-eui and lora.application-key in mbed_app.json # modify lora.device-eui, lora.application-eui and lora.application-key in mbed_app.json
mbed compile --profile minimal-printf/profiles/release.json mbed compile --profile profiles/release.json
``` ```
Then you can use stm32flash or - may be better - a stlink interface to copy the generated .bin file onto the RAK811. Then you can use stm32flash or - may be better - a stlink interface to copy the generated .bin file onto the RAK811.

32
main.cpp

@ -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
@ -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();

2
mbed_app.json.sample

@ -25,6 +25,7 @@
"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-enabled": { "value": "false" },
"battery-in-lpp": { "value": "false" },
"battery-adc": { "value": "NC" }, "battery-adc": { "value": "NC" },
"battery-ratio": { "value": "2.0f" }, "battery-ratio": { "value": "2.0f" },
"dht-enabled": { "value": "false" }, "dht-enabled": { "value": "false" },
@ -280,6 +281,7 @@
"lora-pwr-amp-ctl": "NC", "lora-pwr-amp-ctl": "NC",
"lora-tcxo": "NC", "lora-tcxo": "NC",
"battery-enabled": true, "battery-enabled": true,
"battery-in-lpp": true,
"battery-adc": "A1", "battery-adc": "A1",
"battery-ratio": "2.0f", "battery-ratio": "2.0f",
"dht-enabled": true, "dht-enabled": true,

2
profiles/release.json

@ -12,7 +12,7 @@
"ld": ["-Wl,--gc-sections", "-Wl,--wrap,main", "-Wl,--wrap,_malloc_r", "ld": ["-Wl,--gc-sections", "-Wl,--wrap,main", "-Wl,--wrap,_malloc_r",
"-Wl,--wrap,_free_r", "-Wl,--wrap,_realloc_r", "-Wl,--wrap,_memalign_r", "-Wl,--wrap,_free_r", "-Wl,--wrap,_realloc_r", "-Wl,--wrap,_memalign_r",
"-Wl,--wrap,_calloc_r", "-Wl,--wrap,exit", "-Wl,--wrap,atexit", "-Wl,--wrap,_calloc_r", "-Wl,--wrap,exit", "-Wl,--wrap,atexit",
"-Wl,-n", "--specs=nano.specs"] "-Wl,-n", "--specs=nano.specs", "-u _printf_float"]
}, },
"ARMC6": { "ARMC6": {
"common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-Oz", "common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-Oz",

Loading…
Cancel
Save