diff --git a/.github/workflows/build_raspbian.yml b/.github/workflows/build_raspbian.yml
new file mode 100644
index 000000000..103f43a71
--- /dev/null
+++ b/.github/workflows/build_raspbian.yml
@@ -0,0 +1,45 @@
+name: Build Raspbian
+
+on: workflow_call
+
+permissions:
+ contents: write
+ packages: write
+
+jobs:
+ build-raspbian:
+ runs-on: [self-hosted, linux, ARM64]
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v3
+ with:
+ submodules: recursive
+ ref: ${{github.event.pull_request.head.ref}}
+ repository: ${{github.event.pull_request.head.repo.full_name}}
+
+ - name: Upgrade python tools
+ shell: bash
+ run: |
+ python -m pip install --upgrade pip
+ pip install -U platformio adafruit-nrfutil
+ pip install -U meshtastic --pre
+
+ - name: Upgrade platformio
+ shell: bash
+ run: |
+ pio upgrade
+
+ - name: Build Raspbian
+ run: bin/build-native.sh
+
+ - name: Get release version string
+ run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT
+ id: version
+
+ - name: Store binaries as an artifact
+ uses: actions/upload-artifact@v3
+ with:
+ name: firmware-raspbian-${{ steps.version.outputs.version }}.zip
+ path: |
+ release/meshtasticd_linux_arm64
+ bin/config-dist.yaml
diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml
index 145a75c2d..6b6ff1ad7 100644
--- a/.github/workflows/main_matrix.yml
+++ b/.github/workflows/main_matrix.yml
@@ -103,7 +103,6 @@ jobs:
build-nrf52:
strategy:
fail-fast: false
- max-parallel: 2
matrix:
include:
- board: rak4631
@@ -129,6 +128,15 @@ jobs:
with:
board: ${{ matrix.board }}
+ build-raspbian:
+ strategy:
+ fail-fast: false
+ max-parallel: 1
+ uses: ./.github/workflows/build_raspbian.yml
+
+ package-raspbian:
+ uses: ./.github/workflows/package_raspbian.yml
+
build-native:
runs-on: ubuntu-latest
steps:
@@ -204,7 +212,15 @@ jobs:
gather-artifacts:
runs-on: ubuntu-latest
needs:
- [build-esp32, build-esp32-s3, build-nrf52, build-native, build-rpi2040]
+ [
+ build-esp32,
+ build-esp32-s3,
+ build-nrf52,
+ build-raspbian,
+ build-native,
+ build-rpi2040,
+ package-raspbian,
+ ]
steps:
- name: Checkout code
uses: actions/checkout@v3
@@ -216,12 +232,15 @@ jobs:
with:
path: ./
+ - name: Display structure of downloaded files
+ run: ls -R
+
- name: Get release version string
run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT
id: version
- name: Move files up
- run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat
+ run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat ./firmware-raspbian-*/release/meshtasticd_linux_arm64 ./firmware-raspbian-*/bin/config-dist.yaml
- name: Repackage in single firmware zip
uses: actions/upload-artifact@v3
@@ -233,6 +252,8 @@ jobs:
./firmware-*-ota.zip
./device-*.sh
./device-*.bat
+ ./meshtasticd_linux_arm64
+ ./config-dist.yaml
retention-days: 90
- uses: actions/download-artifact@v3
@@ -294,6 +315,13 @@ jobs:
name: firmware-${{ steps.version.outputs.version }}
path: ./output
+ - uses: actions/download-artifact@v3
+ with:
+ name: artifact-deb
+
+ - name: Display structure of downloaded files
+ run: ls -R
+
- name: Device scripts permissions
run: |
chmod +x ./output/device-install.sh
@@ -347,6 +375,16 @@ jobs:
asset_name: debug-elfs-${{ steps.version.outputs.version }}.zip
asset_content_type: application/zip
+ - name: Add raspbian .deb
+ uses: actions/upload-release-asset@v1
+ env:
+ GITHUB_TOKEN: ${{ github.token }}
+ with:
+ upload_url: ${{ steps.create_release.outputs.upload_url }}
+ asset_path: ./meshtasticd_${{ steps.version.outputs.version }}_arm64.deb
+ asset_name: meshtasticd_${{ steps.version.outputs.version }}_arm64.deb
+ asset_content_type: application/vnd.debian.binary-package
+
- name: Bump version.properties
run: >-
bin/bump_version.py
diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml
new file mode 100644
index 000000000..61f82e9d7
--- /dev/null
+++ b/.github/workflows/package_raspbian.yml
@@ -0,0 +1,62 @@
+name: Package Raspbian
+
+on:
+ workflow_call:
+ workflow_dispatch:
+
+permissions:
+ contents: write
+ packages: write
+
+jobs:
+ build-raspbian:
+ uses: ./.github/workflows/build_raspbian.yml
+
+ package-raspbian:
+ runs-on: ubuntu-latest
+ needs: build-raspbian
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v3
+ with:
+ submodules: recursive
+ ref: ${{github.event.pull_request.head.ref}}
+ repository: ${{github.event.pull_request.head.repo.full_name}}
+
+ - name: Get release version string
+ run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT
+ id: version
+
+ - name: Download artifacts
+ uses: actions/download-artifact@v3
+ with:
+ name: firmware-raspbian-${{ steps.version.outputs.version }}.zip
+
+ - name: Display structure of downloaded files
+ run: ls -R
+
+ - name: build .debpkg
+ run: |
+ mkdir -p .debpkg/usr/sbin
+ mkdir -p .debpkg/etc/meshtasticd
+ mkdir -p .debpkg/usr/lib/systemd/system/
+ cp release/meshtasticd_linux_arm64 .debpkg/usr/sbin/meshtasticd
+ cp bin/config-dist.yaml .debpkg/etc/meshtasticd/config.yaml
+ chmod +x .debpkg/usr/sbin/meshtasticd
+ cp bin/meshtasticd.service .debpkg/usr/lib/systemd/system/meshtasticd.service
+
+ - uses: jiro4989/build-deb-action@v3
+ with:
+ package: meshtasticd
+ package_root: .debpkg
+ maintainer: Jonathan Bennett
+ version: ${{ steps.version.outputs.version }} # refs/tags/v*.*.*
+ arch: arm64
+ depends: libyaml-cpp0.7
+ desc: Native Linux Meshtastic binary.
+
+ - uses: actions/upload-artifact@v3
+ with:
+ name: artifact-deb
+ path: |
+ ./*.deb
diff --git a/.trunk/configs/.shellcheckrc b/.trunk/configs/.shellcheckrc
index 8c7b1ada8..b2e8a14cc 100644
--- a/.trunk/configs/.shellcheckrc
+++ b/.trunk/configs/.shellcheckrc
@@ -1,7 +1,10 @@
enable=all
source-path=SCRIPTDIR
disable=SC2154
+disable=SC2248
+disable=SC2250
# If you're having issues with shellcheck following source, disable the errors via:
# disable=SC1090
# disable=SC1091
+#
\ No newline at end of file
diff --git a/.trunk/configs/.yamllint.yaml b/.trunk/configs/.yamllint.yaml
index 4d444662d..790846156 100644
--- a/.trunk/configs/.yamllint.yaml
+++ b/.trunk/configs/.yamllint.yaml
@@ -3,7 +3,7 @@ rules:
required: only-when-needed
extra-allowed: ["{|}"]
empty-values:
- forbid-in-block-mappings: true
+ forbid-in-block-mappings: false
forbid-in-flow-mappings: true
key-duplicates: {}
octal-values:
diff --git a/arch/rp2040/rp2040.ini b/arch/rp2040/rp2040.ini
index b6ac4f171..495b52a86 100644
--- a/arch/rp2040/rp2040.ini
+++ b/arch/rp2040/rp2040.ini
@@ -21,4 +21,4 @@ lib_deps =
${arduino_base.lib_deps}
${environmental_base.lib_deps}
jgromes/RadioLib@^6.1.0
- https://github.com/kokke/tiny-AES-c.git#f06ac37fc31dfdaca2e0d9bec83f90d5663c319b
\ No newline at end of file
+ rweather/Crypto
\ No newline at end of file
diff --git a/bin/build-native.sh b/bin/build-native.sh
index 8bc262860..64c5adb50 100755
--- a/bin/build-native.sh
+++ b/bin/build-native.sh
@@ -2,8 +2,8 @@
set -e
-VERSION=`bin/buildinfo.py long`
-SHORT_VERSION=`bin/buildinfo.py short`
+VERSION=$(bin/buildinfo.py long)
+SHORT_VERSION=$(bin/buildinfo.py short)
OUTDIR=release/
@@ -13,11 +13,15 @@ mkdir -p $OUTDIR/
rm -r $OUTDIR/* || true
# Important to pull latest version of libs into all device flavors, otherwise some devices might be stale
-platformio pkg update
+platformio pkg update
-pio run --environment native
-cp .pio/build/native/program $OUTDIR/meshtasticd_linux_amd64
+if command -v raspi-config &>/dev/null; then
+ pio run --environment raspbian
+ cp .pio/build/raspbian/program $OUTDIR/meshtasticd_linux_arm64
+else
+ pio run --environment native
+ cp .pio/build/native/program $OUTDIR/meshtasticd_linux_amd64
+fi
cp bin/device-install.* $OUTDIR
cp bin/device-update.* $OUTDIR
-
diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml
new file mode 100644
index 000000000..6c8f1946f
--- /dev/null
+++ b/bin/config-dist.yaml
@@ -0,0 +1,26 @@
+# Define your devices here using Broadcom pin numbering
+# Uncomment the block that corresponds to your hardware
+---
+Lora:
+# Module: sx1262 # Waveshare SX126X XXXM
+# DIO2_AS_RF_SWITCH: true
+# CS: 21
+# IRQ: 16
+# Busy: 20
+# Reset: 18
+
+# Module: sx1262 # Waveshare SX1302 LISTEN ONLY AT THIS TIME!
+# CS: 7
+# IRQ: 17
+# Reset: 22
+
+# Module: RF95 # Adafruit RFM9x
+# Reset: 25
+# CS: 7
+# IRQ: 22
+# Busy: 23
+
+# Module: RF95 # Elecrow Lora RFM95 IOT https://www.elecrow.com/lora-rfm95-iot-board-for-rpi.html
+# Reset: 22
+# CS: 7
+# IRQ: 25
diff --git a/bin/meshtasticd.service b/bin/meshtasticd.service
new file mode 100644
index 000000000..4ed1bfd8f
--- /dev/null
+++ b/bin/meshtasticd.service
@@ -0,0 +1,9 @@
+[unit]
+description=Meshtastic Native Daemon
+
+[Service]
+Type=simple
+ExecStart=/usr/sbin/meshtasticd
+
+[Install]
+WantedBy=multi-user.target
diff --git a/bin/native-install.sh b/bin/native-install.sh
new file mode 100755
index 000000000..d1d0c8707
--- /dev/null
+++ b/bin/native-install.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+
+cp release/meshtasticd_linux_arm64 /usr/sbin/meshtasticd
+mkdir /etc/meshtasticd
+if [[ -f "/etc/meshtasticd/config.yaml" ]]; then
+ cp bin/config-dist.yaml /etc/meshtasticd/config-upgrade.yaml
+else
+ cp bin/config-dist.yaml /etc/meshtasticd/config.yaml
+fi
+cp bin/meshtasticd.service /usr/lib/systemd/system/meshtasticd.service
diff --git a/src/Power.cpp b/src/Power.cpp
index 72bb38181..0a56a1ba2 100644
--- a/src/Power.cpp
+++ b/src/Power.cpp
@@ -19,6 +19,11 @@
#include "meshUtils.h"
#include "sleep.h"
+// Working USB detection for powered/charging states on the RAK platform
+#ifdef NRF_APM
+#include "nrfx_power.h"
+#endif
+
#ifdef DEBUG_HEAP_MQTT
#include "mqtt/MQTT.h"
#include "target_specific.h"
@@ -52,6 +57,7 @@ static const adc_atten_t atten = ADC_ATTENUATION;
#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO)
INA260Sensor ina260Sensor;
INA219Sensor ina219Sensor;
+INA3221Sensor ina3221Sensor;
#endif
#ifdef HAS_PMU
@@ -286,6 +292,9 @@ class AnalogBatteryLevel : public HasBatteryLevel
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260].first ==
config.power.device_battery_ina_address) {
return ina260Sensor.getBusVoltageMv();
+ } else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA3221].first ==
+ config.power.device_battery_ina_address) {
+ return ina3221Sensor.getBusVoltageMv();
}
return 0;
}
@@ -456,10 +465,25 @@ void Power::readPowerStatus()
}
}
+ OptionalBool NRF_USB = OptFalse;
+
+#ifdef NRF_APM // Section of code detects USB power on the RAK4631 and updates the power states. Takes 20 seconds or so to detect
+ // changes.
+
+ nrfx_power_usb_state_t nrf_usb_state = nrfx_power_usbstatus_get();
+
+ if (nrf_usb_state == NRFX_POWER_USB_STATE_DISCONNECTED) {
+ powerFSM.trigger(EVENT_POWER_DISCONNECTED);
+ NRF_USB = OptFalse;
+ } else {
+ powerFSM.trigger(EVENT_POWER_CONNECTED);
+ NRF_USB = OptTrue;
+ }
+#endif
// Notify any status instances that are observing us
- const PowerStatus powerStatus2 =
- PowerStatus(hasBattery ? OptTrue : OptFalse, batteryLevel->isVbusIn() ? OptTrue : OptFalse,
- batteryLevel->isCharging() ? OptTrue : OptFalse, batteryVoltageMv, batteryChargePercent);
+ const PowerStatus powerStatus2 = PowerStatus(
+ hasBattery ? OptTrue : OptFalse, batteryLevel->isVbusIn() || NRF_USB == OptTrue ? OptTrue : OptFalse,
+ batteryLevel->isCharging() || NRF_USB == OptTrue ? OptTrue : OptFalse, batteryVoltageMv, batteryChargePercent);
LOG_DEBUG("Battery: usbPower=%d, isCharging=%d, batMv=%d, batPct=%d\n", powerStatus2.getHasUSB(),
powerStatus2.getIsCharging(), powerStatus2.getBatteryVoltageMv(), powerStatus2.getBatteryChargePercent());
newStatus.notifyObservers(&powerStatus2);
diff --git a/src/configuration.h b/src/configuration.h
index 199880c6b..cb7ee218b 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -57,8 +57,8 @@ along with this program. If not, see .
#define REQUIRE_RADIO true // If true, we will fail to start if the radio is not found
/// Convert a preprocessor name into a quoted string
-#define xstr(s) str(s)
-#define str(s) #s
+#define xstr(s) ystr(s)
+#define ystr(s) #s
/// Convert a preprocessor name into a quoted string and if that string is empty use "unset"
#define optstr(s) (xstr(s)[0] ? xstr(s) : "unset")
@@ -209,4 +209,4 @@ along with this program. If not, see .
#ifndef HW_VENDOR
#error HW_VENDOR must be defined
-#endif
+#endif
\ No newline at end of file
diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp
index 47ba067d2..af622e3d8 100644
--- a/src/gps/GPS.cpp
+++ b/src/gps/GPS.cpp
@@ -17,6 +17,9 @@
#if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(ARCH_ESP32)
HardwareSerial *GPS::_serial_gps = &Serial1;
+#elif defined(ARCH_RASPBERRY_PI)
+// need a translation layer to make _serial_gps work with pigpio https://abyz.me.uk/rpi/pigpio/cif.html#serOpen
+HardwareSerial *GPS::_serial_gps = NULL;
#else
HardwareSerial *GPS::_serial_gps = NULL;
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 6b84af084..60b38891b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -69,6 +69,7 @@ NRF52Bluetooth *nrf52Bluetooth;
#ifdef ARCH_RASPBERRY_PI
#include "platform/portduino/PiHal.h"
+#include "platform/portduino/PortduinoGlue.h"
#include
#include
#include
@@ -693,15 +694,32 @@ void setup()
#endif
#ifdef ARCH_RASPBERRY_PI
- PiHal *RadioLibHAL = new PiHal(1);
- if (!rIf) {
- rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, 21, 16, 18, 20);
- if (!rIf->init()) {
- LOG_WARN("Failed to find SX1262 radio\n");
- delete rIf;
- rIf = NULL;
- } else {
- LOG_INFO("SX1262 Radio init succeeded, using SX1262 radio\n");
+ if (settingsMap[use_sx1262]) {
+ if (!rIf) {
+ PiHal *RadioLibHAL = new PiHal(1);
+ rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset],
+ settingsMap[busy]);
+ if (!rIf->init()) {
+ LOG_ERROR("Failed to find SX1262 radio\n");
+ delete rIf;
+ exit(EXIT_FAILURE);
+ } else {
+ LOG_INFO("SX1262 Radio init succeeded, using SX1262 radio\n");
+ }
+ }
+ } else if (settingsMap[use_rf95]) {
+ if (!rIf) {
+ PiHal *RadioLibHAL = new PiHal(1);
+ rIf = new RF95Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset],
+ settingsMap[busy]);
+ if (!rIf->init()) {
+ LOG_ERROR("Failed to find RF95 radio\n");
+ delete rIf;
+ rIf = NULL;
+ exit(EXIT_FAILURE);
+ } else {
+ LOG_INFO("RF95 Radio init succeeded, using RF95 radio\n");
+ }
}
}
diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp
index fe38a9bfe..4fc2c7723 100644
--- a/src/mesh/NodeDB.cpp
+++ b/src/mesh/NodeDB.cpp
@@ -200,7 +200,7 @@ void NodeDB::installDefaultConfig()
config.position.position_flags =
(meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE | meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE_MSL |
meshtastic_Config_PositionConfig_PositionFlags_SPEED | meshtastic_Config_PositionConfig_PositionFlags_HEADING |
- meshtastic_Config_PositionConfig_PositionFlags_DOP);
+ meshtastic_Config_PositionConfig_PositionFlags_DOP | meshtastic_Config_PositionConfig_PositionFlags_SATINVIEW);
#ifdef T_WATCH_S3
config.display.screen_on_secs = 30;
@@ -316,8 +316,8 @@ void NodeDB::installDefaultChannels()
void NodeDB::resetNodes()
{
- devicestate.node_db_lite_count = 0;
- memset(devicestate.node_db_lite, 0, sizeof(devicestate.node_db_lite));
+ devicestate.node_db_lite_count = 1;
+ std::fill(&devicestate.node_db_lite[1], &devicestate.node_db_lite[MAX_NUM_NODES - 1], meshtastic_NodeInfoLite());
saveDeviceStateToDisk();
if (neighborInfoModule && moduleConfig.neighbor_info.enabled)
neighborInfoModule->resetNeighbors();
diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp
index 980107917..5083eeb53 100644
--- a/src/mesh/SX126xInterface.cpp
+++ b/src/mesh/SX126xInterface.cpp
@@ -2,6 +2,9 @@
#include "configuration.h"
#include "error.h"
#include "mesh/NodeDB.h"
+#ifdef ARCH_RASPBERRY_PI
+#include "PortduinoGlue.h"
+#endif
// Particular boards might define a different max power based on what their hardware can do, default to max power output if not
// specified (may be dangerous if using external PA and SX126x power config forgotten)
@@ -74,6 +77,12 @@ template bool SX126xInterface::init()
#ifdef SX126X_DIO2_AS_RF_SWITCH
LOG_DEBUG("Setting DIO2 as RF switch\n");
bool dio2AsRfSwitch = true;
+#elif defined(ARCH_RASPBERRY_PI)
+ bool dio2AsRfSwitch = false;
+ if (settingsMap[dio2_as_rf_switch]) {
+ LOG_DEBUG("Setting DIO2 as RF switch\n");
+ dio2AsRfSwitch = true;
+ }
#else
LOG_DEBUG("Setting DIO2 as not RF switch\n");
bool dio2AsRfSwitch = false;
@@ -318,4 +327,4 @@ template bool SX126xInterface::sleep()
#endif
return true;
-}
+}
\ No newline at end of file
diff --git a/src/modules/Telemetry/PowerTelemetry.cpp b/src/modules/Telemetry/PowerTelemetry.cpp
index 53e26ee6a..032d7fc27 100644
--- a/src/modules/Telemetry/PowerTelemetry.cpp
+++ b/src/modules/Telemetry/PowerTelemetry.cpp
@@ -11,11 +11,6 @@
#include "sleep.h"
#include "target_specific.h"
-#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO)
-#include "Sensor/INA3221Sensor.h"
-INA3221Sensor ina3221Sensor;
-#endif
-
#define FAILED_STATE_SENSOR_READ_MULTIPLIER 10
#define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true
diff --git a/src/modules/Telemetry/Sensor/INA3221Sensor.cpp b/src/modules/Telemetry/Sensor/INA3221Sensor.cpp
index 634f5a5c9..3269ba47a 100644
--- a/src/modules/Telemetry/Sensor/INA3221Sensor.cpp
+++ b/src/modules/Telemetry/Sensor/INA3221Sensor.cpp
@@ -13,8 +13,9 @@ int32_t INA3221Sensor::runOnce()
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
}
if (!status) {
- ina3221.setAddr(INA3221_ADDR42_SDA);
+ ina3221.setAddr(INA3221_ADDR42_SDA); // i2c address 0x42
ina3221.begin();
+ ina3221.setShuntRes(100, 100, 100); // 0.1 Ohm shunt resistors
status = true;
} else {
status = true;
diff --git a/src/modules/Telemetry/Sensor/INA3221Sensor.h b/src/modules/Telemetry/Sensor/INA3221Sensor.h
index a1c0fb2a7..4c82fc34d 100644
--- a/src/modules/Telemetry/Sensor/INA3221Sensor.h
+++ b/src/modules/Telemetry/Sensor/INA3221Sensor.h
@@ -1,16 +1,19 @@
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "TelemetrySensor.h"
+#include "VoltageSensor.h"
#include
-class INA3221Sensor : public TelemetrySensor
+class INA3221Sensor : public TelemetrySensor, VoltageSensor
{
+ private:
+ INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA);
+
+ protected:
+ void setup() override;
+
public:
INA3221Sensor();
int32_t runOnce() override;
- void setup() override;
bool getMetrics(meshtastic_Telemetry *measurement) override;
- virtual uint16_t getBusVoltageMv();
-
- private:
- INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA);
+ virtual uint16_t getBusVoltageMv() override;
};
\ No newline at end of file
diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp
index 1f06b25f2..3175e0f09 100644
--- a/src/nimble/NimbleBluetooth.cpp
+++ b/src/nimble/NimbleBluetooth.cpp
@@ -9,6 +9,7 @@
#include
NimBLECharacteristic *fromNumCharacteristic;
+NimBLECharacteristic *BatteryCharacteristic;
NimBLEServer *bleServer;
static bool passkeyShowing;
@@ -181,6 +182,18 @@ void NimbleBluetooth::setupService()
FromRadioCharacteristic->setCallbacks(fromRadioCallbacks);
bleService->start();
+
+ // Setup the battery service
+ NimBLEService *batteryService = bleServer->createService(NimBLEUUID((uint16_t)0x180f)); // 0x180F is the Battery Service
+ BatteryCharacteristic = batteryService->createCharacteristic( // 0x2A19 is the Battery Level characteristic)
+ (uint16_t)0x2a19, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY);
+
+ NimBLE2904 *batteryLevelDescriptor = (NimBLE2904 *)BatteryCharacteristic->createDescriptor((uint16_t)0x2904);
+ batteryLevelDescriptor->setFormat(NimBLE2904::FORMAT_UINT8);
+ batteryLevelDescriptor->setNamespace(1);
+ batteryLevelDescriptor->setUnit(0x27ad);
+
+ batteryService->start();
}
void NimbleBluetooth::startAdvertising()
@@ -188,13 +201,15 @@ void NimbleBluetooth::startAdvertising()
NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising();
pAdvertising->reset();
pAdvertising->addServiceUUID(MESH_SERVICE_UUID);
+ pAdvertising->addServiceUUID(NimBLEUUID((uint16_t)0x180f)); // 0x180F is the Battery Service
pAdvertising->start(0);
}
/// Given a level between 0-100, update the BLE attribute
void updateBatteryLevel(uint8_t level)
{
- // blebas.write(level);
+ BatteryCharacteristic->setValue(&level, 1);
+ BatteryCharacteristic->notify();
}
void NimbleBluetooth::clearBonds()
diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp
index fb71a429b..2e402c0a0 100644
--- a/src/platform/portduino/PortduinoGlue.cpp
+++ b/src/platform/portduino/PortduinoGlue.cpp
@@ -9,7 +9,14 @@
#include
#ifdef ARCH_RASPBERRY_PI
+#include "PortduinoGlue.h"
#include "pigpio.h"
+#include "yaml-cpp/yaml.h"
+#include
+#include