From c5851a4a0cc99354ec56a543cd05b490c6082ba7 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 22 Jun 2020 09:36:19 -0700 Subject: [PATCH] Report battery level to other nodes in mesh (and apps). Also today I'll turn back on the the standard "has a battery" BLE device profile, so the locally connected radio should show up in the phone's bluetooth popup of battery levels (similar to how a BLE headphone battery level appears) cc @lgoix - using code from @professr ``` meshtastic --info Connected to radio... my_node_num: 2883444536 has_gps: true num_channels: 13 region: "unset" hw_model: "tbeam" firmware_version: "unset" packet_id_bits: 32 current_packet_id: 91018534 node_num_bits: 32 message_timeout_msec: 300000 min_app_version: 172 preferences { position_broadcast_secs: 900 send_owner_interval: 4 wait_bluetooth_secs: 120 screen_on_secs: 300 phone_timeout_secs: 900 phone_sds_timeout_sec: 7200 mesh_sds_timeout_secs: 7200 sds_secs: 31536000 ls_secs: 3600 } channel_settings { tx_power: 23 modem_config: Bw125Cr48Sf4096 psk: "\324\361\273: )\007Y\360\274\377\253\317Ni\277" name: "Default" } Nodes in mesh: {'num': 2883444536, 'user': {'id': '!2462abdddf38', 'longName': 'Unknown df38', 'shortName': '?38', 'macaddr': 'JGKr3d84'}, 'position': {'altitude': 96, 'batteryLevel': 100, 'latitudeI': 375210641, 'longitudeI': -1223090398, 'time': 1592843564, 'latitude': 37.5210641, 'longitude': -122.3090398}} ``` --- docs/software/TODO.md | 1 + src/mesh/MeshService.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index a33d090bc..3b75aca29 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -2,6 +2,7 @@ You probably don't care about this section - skip to the next one. +- report battery level to android app - @feh123 Sony Xperia Z1 C6903 running Android 5.1.1 - don't stop advertising BLE - first message sent is still doubled for some people diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index eebfb227e..59da36389 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -11,6 +11,7 @@ #include "PowerFSM.h" #include "main.h" #include "mesh-pb-constants.h" +#include "power.h" /* receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone. @@ -298,6 +299,9 @@ int MeshService::onGPSChanged(void *unused) pos.time = getValidTime(); } + // Include our current battery voltage in our position announcement + pos.battery_level = powerStatus.batteryChargePercent; + // We limit our GPS broadcasts to a max rate static uint32_t lastGpsSend; uint32_t now = millis();