Merge branch 'master' into nomad-gemini

This commit is contained in:
Thomas Göttgens
2025-06-05 14:30:38 +02:00
committed by GitHub
68 changed files with 1230 additions and 162 deletions

View File

@@ -669,6 +669,24 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c)
config.lora = c.payload_variant.lora;
// If we're setting region for the first time, init the region
if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) {
if (!owner.is_licensed) {
bool keygenSuccess = false;
if (config.security.private_key.size == 32) {
if (crypto->regeneratePublicKey(config.security.public_key.bytes, config.security.private_key.bytes)) {
keygenSuccess = true;
}
} else {
LOG_INFO("Generate new PKI keys");
crypto->generateKeyPair(config.security.public_key.bytes, config.security.private_key.bytes);
keygenSuccess = true;
}
if (keygenSuccess) {
config.security.public_key.size = 32;
config.security.private_key.size = 32;
owner.public_key.size = 32;
memcpy(owner.public_key.bytes, config.security.public_key.bytes, 32);
}
}
config.lora.tx_enabled = true;
initRegion();
if (myRegion->dutyCycle < 100) {

View File

@@ -14,6 +14,9 @@ bool NodeInfoModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes
{
auto p = *pptr;
// Coerce user.id to be derived from the node number
snprintf(p.id, sizeof(p.id), "!%08x", getFrom(&mp));
bool hasChanged = nodeDB->updateUser(getFrom(&mp), p, mp.channel);
bool wasBroadcast = isBroadcast(mp.to);

View File

@@ -9,6 +9,7 @@
#include "Router.h"
#include "configuration.h"
#include "main.h"
#include "memGet.h"
#include <OLEDDisplay.h>
#include <OLEDDisplayUi.h>
#include <meshUtils.h>
@@ -133,6 +134,9 @@ meshtastic_Telemetry DeviceTelemetryModule::getLocalStatsTelemetry()
telemetry.variant.local_stats.num_packets_rx_bad = SimRadio::instance->rxBad;
telemetry.variant.local_stats.num_tx_relay = SimRadio::instance->txRelay;
}
#else
telemetry.variant.local_stats.heap_total_bytes = memGet.getHeapSize();
telemetry.variant.local_stats.heap_free_bytes = memGet.getFreeHeap();
#endif
if (router) {
telemetry.variant.local_stats.num_rx_dupe = router->rxDupe;

View File

@@ -52,6 +52,13 @@ BMP280Sensor bmp280Sensor;
NullSensor bme280Sensor;
#endif
#if __has_include(<Adafruit_LTR390.h>)
#include "Sensor/LTR390UVSensor.h"
LTR390UVSensor ltr390uvSensor;
#else
NullSensor ltr390uvSensor;
#endif
#if __has_include(<bsec2.h>)
#include "Sensor/BME680Sensor.h"
BME680Sensor bme680Sensor;
@@ -157,6 +164,13 @@ BMP3XXSensor bmp3xxSensor;
NullSensor bmp3xxSensor;
#endif
#if __has_include(<Adafruit_PCT2075.h>)
#include "Sensor/PCT2075Sensor.h"
PCT2075Sensor pct2075Sensor;
#else
NullSensor pct2075Sensor;
#endif
RCWL9620Sensor rcwl9620Sensor;
CGRadSensSensor cgRadSens;
#endif
@@ -224,6 +238,8 @@ int32_t EnvironmentTelemetryModule::runOnce()
#endif
if (bme280Sensor.hasSensor())
result = bme280Sensor.runOnce();
if (ltr390uvSensor.hasSensor())
result = ltr390uvSensor.runOnce();
if (bmp3xxSensor.hasSensor())
result = bmp3xxSensor.runOnce();
if (bme680Sensor.hasSensor())
@@ -264,6 +280,8 @@ int32_t EnvironmentTelemetryModule::runOnce()
result = max17048Sensor.runOnce();
if (cgRadSens.hasSensor())
result = cgRadSens.runOnce();
if (pct2075Sensor.hasSensor())
result = pct2075Sensor.runOnce();
// this only works on the wismesh hub with the solar option. This is not an I2C sensor, so we don't need the
// sensormap here.
#ifdef HAS_RAKPROT
@@ -515,6 +533,10 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m
valid = valid && bme280Sensor.getMetrics(m);
hasSensor = true;
}
if (ltr390uvSensor.hasSensor()) {
valid = valid && ltr390uvSensor.getMetrics(m);
hasSensor = true;
}
if (bmp3xxSensor.hasSensor()) {
valid = valid && bmp3xxSensor.getMetrics(m);
hasSensor = true;
@@ -595,6 +617,10 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m
valid = valid && cgRadSens.getMetrics(m);
hasSensor = true;
}
if (pct2075Sensor.hasSensor()) {
valid = valid && pct2075Sensor.getMetrics(m);
hasSensor = true;
}
#ifdef HAS_RAKPROT
valid = valid && rak9154Sensor.getMetrics(m);
hasSensor = true;
@@ -739,6 +765,11 @@ AdminMessageHandleResult EnvironmentTelemetryModule::handleAdminMessageForModule
if (result != AdminMessageHandleResult::NOT_HANDLED)
return result;
}
if (ltr390uvSensor.hasSensor()) {
result = ltr390uvSensor.handleAdminMessage(mp, request, response);
if (result != AdminMessageHandleResult::NOT_HANDLED)
return result;
}
if (bmp3xxSensor.hasSensor()) {
result = bmp3xxSensor.handleAdminMessage(mp, request, response);
if (result != AdminMessageHandleResult::NOT_HANDLED)

View File

@@ -34,7 +34,8 @@ bool HostMetricsModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp,
sender, t->variant.host_metrics.uptime_seconds, t->variant.host_metrics.diskfree1_bytes,
t->variant.host_metrics.freemem_bytes, static_cast<float>(t->variant.host_metrics.load1) / 100,
static_cast<float>(t->variant.host_metrics.load5) / 100,
static_cast<float>(t->variant.host_metrics.load15) / 100, t->variant.host_metrics.user_string);
static_cast<float>(t->variant.host_metrics.load15) / 100,
t->variant.host_metrics.has_user_string ? t->variant.host_metrics.user_string : "");
#endif
}
return false; // Let others look at this message also if they want
@@ -124,7 +125,8 @@ bool HostMetricsModule::sendMetrics()
telemetry.variant.host_metrics.uptime_seconds, telemetry.variant.host_metrics.diskfree1_bytes,
telemetry.variant.host_metrics.freemem_bytes, static_cast<float>(telemetry.variant.host_metrics.load1) / 100,
static_cast<float>(telemetry.variant.host_metrics.load5) / 100,
static_cast<float>(telemetry.variant.host_metrics.load15) / 100, telemetry.variant.host_metrics.user_string);
static_cast<float>(telemetry.variant.host_metrics.load15) / 100,
telemetry.variant.host_metrics.has_user_string ? telemetry.variant.host_metrics.user_string : "");
meshtastic_MeshPacket *p = allocDataProtobuf(telemetry);
p->to = NODENUM_BROADCAST;

View File

@@ -0,0 +1,73 @@
#include "configuration.h"
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include(<Adafruit_LTR390.h>)
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "LTR390UVSensor.h"
#include "TelemetrySensor.h"
#include <Adafruit_LTR390.h>
LTR390UVSensor::LTR390UVSensor() : TelemetrySensor(meshtastic_TelemetrySensorType_LTR390UV, "LTR390UV") {}
int32_t LTR390UVSensor::runOnce()
{
LOG_INFO("Init sensor: %s", sensorName);
if (!hasSensor()) {
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
}
status = ltr390uv.begin(nodeTelemetrySensorsMap[sensorType].second);
ltr390uv.setMode(LTR390_MODE_UVS);
ltr390uv.setGain(LTR390_GAIN_18); // Datasheet default
ltr390uv.setResolution(LTR390_RESOLUTION_20BIT); // Datasheet default
return initI2CSensor();
}
void LTR390UVSensor::setup() {}
bool LTR390UVSensor::getMetrics(meshtastic_Telemetry *measurement)
{
LOG_DEBUG("LTR390UV getMetrics");
// Because the sensor does not measure Lux and UV at the same time, we need to read them in two passes.
if (ltr390uv.newDataAvailable()) {
measurement->variant.environment_metrics.has_lux = true;
measurement->variant.environment_metrics.has_uv_lux = true;
if (ltr390uv.getMode() == LTR390_MODE_ALS) {
lastLuxReading = 0.6 * ltr390uv.readALS() / (1 * 4); // Datasheet page 23 for gain x1 and 20bit resolution
LOG_DEBUG("LTR390UV Lux reading: %f", lastLuxReading);
measurement->variant.environment_metrics.lux = lastLuxReading;
measurement->variant.environment_metrics.uv_lux = lastUVReading;
ltr390uv.setGain(
LTR390_GAIN_18); // Recommended for UVI - x18. Do not change, 2300 UV Sensitivity only specified for x18 gain
ltr390uv.setMode(LTR390_MODE_UVS);
return true;
} else if (ltr390uv.getMode() == LTR390_MODE_UVS) {
lastUVReading = ltr390uv.readUVS() /
2300.f; // Datasheet page 23 and page 6, only characterisation for gain x18 and 20bit resolution
LOG_DEBUG("LTR390UV UV reading: %f", lastUVReading);
measurement->variant.environment_metrics.lux = lastLuxReading;
measurement->variant.environment_metrics.uv_lux = lastUVReading;
ltr390uv.setGain(
LTR390_GAIN_1); // x1 gain will already max out the sensor at direct sunlight, so no need to increase it
ltr390uv.setMode(LTR390_MODE_ALS);
return true;
}
}
// In case we fail to read the sensor mode, set the has_lux and has_uv_lux back to false
measurement->variant.environment_metrics.has_lux = false;
measurement->variant.environment_metrics.has_uv_lux = false;
return false;
}
#endif

View File

@@ -0,0 +1,25 @@
#include "configuration.h"
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include(<Adafruit_LTR390.h>)
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "TelemetrySensor.h"
#include <Adafruit_LTR390.h>
class LTR390UVSensor : public TelemetrySensor
{
private:
Adafruit_LTR390 ltr390uv = Adafruit_LTR390();
float lastLuxReading = 0;
float lastUVReading = 0;
protected:
virtual void setup() override;
public:
LTR390UVSensor();
virtual int32_t runOnce() override;
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
};
#endif

View File

@@ -0,0 +1,35 @@
#include "configuration.h"
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include(<Adafruit_PCT2075.h>)
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "PCT2075Sensor.h"
#include "TelemetrySensor.h"
#include <Adafruit_PCT2075.h>
PCT2075Sensor::PCT2075Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_PCT2075, "PCT2075") {}
int32_t PCT2075Sensor::runOnce()
{
LOG_INFO("Init sensor: %s", sensorName);
if (!hasSensor()) {
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
}
status = pct2075.begin(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second);
return initI2CSensor();
}
void PCT2075Sensor::setup() {}
bool PCT2075Sensor::getMetrics(meshtastic_Telemetry *measurement)
{
measurement->variant.environment_metrics.has_temperature = true;
measurement->variant.environment_metrics.temperature = pct2075.getTemperature();
return true;
}
#endif

View File

@@ -0,0 +1,24 @@
#pragma once
#include "configuration.h"
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include(<Adafruit_PCT2075.h>)
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "TelemetrySensor.h"
#include <Adafruit_PCT2075.h>
class PCT2075Sensor : public TelemetrySensor
{
private:
Adafruit_PCT2075 pct2075;
protected:
virtual void setup() override;
public:
PCT2075Sensor();
virtual int32_t runOnce() override;
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
};
#endif

View File

@@ -23,8 +23,8 @@ int32_t TSL2591Sensor::runOnce()
void TSL2591Sensor::setup()
{
tsl.setGain(TSL2591_GAIN_MED); // 25x gain
tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
tsl.setGain(TSL2591_GAIN_LOW); // 1x gain
tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS);
}
bool TSL2591Sensor::getMetrics(meshtastic_Telemetry *measurement)
@@ -41,4 +41,4 @@ bool TSL2591Sensor::getMetrics(meshtastic_Telemetry *measurement)
return true;
}
#endif
#endif