Modify limited to Portduino and RAK4631 only

This commit is contained in:
JaeHwan Jin
2025-11-14 16:41:05 +09:00
parent 52eb9c9f82
commit d88640a134
7 changed files with 39 additions and 35 deletions

View File

@@ -1,9 +1,11 @@
#include "configuration.h"
#ifndef BME680_HEADER
#if defined(ARCH_PORTDUINO)
#define BME680_HEADER <Adafruit_BME680.h>
#else
#if !defined(BME680_BSEC2_SUPPORTED)
#if defined(RAK_4631)
#define BME680_BSEC2_SUPPORTED 1
#define BME680_HEADER <bsec2.h>
#endif
#endif
#else
#define BME680_BSEC2_SUPPORTED 0
#define BME680_HEADER <Adafruit_BME680.h>
#endif // defined(RAK_4631)
#endif // !defined(BME680_BSEC2_SUPPORTED)

View File

@@ -12,7 +12,7 @@
BME680Sensor::BME680Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_BME680, "BME680") {}
#if !defined(ARCH_PORTDUINO)
#if BME680_BSEC2_SUPPORTED == 1
int32_t BME680Sensor::runOnce()
{
if (!bme680.run()) {
@@ -20,13 +20,13 @@ int32_t BME680Sensor::runOnce()
}
return 35;
}
#endif // !defined(ARCH_PORTDUINO)
#endif // defined(BME680_BSEC2_SUPPORTED)
bool BME680Sensor::initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev)
{
status = 0;
#if !defined(ARCH_PORTDUINO)
#if BME680_BSEC2_SUPPORTED == 1
if (!bme680.begin(dev->address.address, *bus))
checkStatus("begin");
@@ -58,7 +58,7 @@ bool BME680Sensor::initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev)
status = 1;
#endif // !defined(ARCH_PORTDUINO)
#endif // BME680_BSEC2_SUPPORTED
initI2CSensor();
return status;
@@ -66,7 +66,7 @@ bool BME680Sensor::initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev)
bool BME680Sensor::getMetrics(meshtastic_Telemetry *measurement)
{
#if !defined(ARCH_PORTDUINO)
#if BME680_BSEC2_SUPPORTED == 1
if (bme680.getData(BSEC_OUTPUT_RAW_PRESSURE).signal == 0)
return false;
@@ -100,11 +100,11 @@ bool BME680Sensor::getMetrics(meshtastic_Telemetry *measurement)
measurement->variant.environment_metrics.barometric_pressure = bme680->readPressure() / 100.0F;
measurement->variant.environment_metrics.gas_resistance = bme680->readGas() / 1000.0;
#endif
#endif // BME680_BSEC2_SUPPORTED
return true;
}
#if !defined(ARCH_PORTDUINO)
#if BME680_BSEC2_SUPPORTED == 1
void BME680Sensor::loadState()
{
#ifdef FSCom
@@ -181,6 +181,6 @@ void BME680Sensor::checkStatus(const char *functionName)
else if (bme680.sensor.status > BME68X_OK)
LOG_WARN("%s BME68X code: %d", functionName, bme680.sensor.status);
}
#endif // !defined(ARCH_PORTDUINO)
#endif // BME680_BSEC2_SUPPORTED
#endif

View File

@@ -7,37 +7,36 @@
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "TelemetrySensor.h"
#if defined(ARCH_PORTDUINO)
#include <Adafruit_BME680.h>
#include <memory>
#else // defined(ARCH_PORTDUINO)
#if BME680_BSEC2_SUPPORTED == 1
#include <bme68xLibrary.h>
#include <bsec2.h>
#endif // defined(ARCH_PORTDUINO)
#else
#include <Adafruit_BME680.h>
#include <memory>
#endif // BME680_BSEC2_SUPPORTED
#define STATE_SAVE_PERIOD UINT32_C(360 * 60 * 1000) // That's 6 hours worth of millis()
#if !defined(ARCH_PORTDUINO)
#if BME680_BSEC2_SUPPORTED == 1
const uint8_t bsec_config[] = {
#include "config/bme680/bme680_iaq_33v_3s_4d/bsec_iaq.txt"
};
#endif // !defined(ARCH_PORTDUINO)
#endif // BME680_BSEC2_SUPPORTED
class BME680Sensor : public TelemetrySensor
{
private:
#if defined(ARCH_PORTDUINO)
#if BME680_BSEC2_SUPPORTED == 1
Bsec2 bme680;
#else
using BME680Ptr = std::unique_ptr<Adafruit_BME680>;
static BME680Ptr makeBME680(TwoWire *bus) { return std::make_unique<Adafruit_BME680>(bus); }
BME680Ptr bme680;
#else
Bsec2 bme680;
#endif // defined(ARCH_PORTDUINO)
#endif // BME680_BSEC2_SUPPORTED
protected:
#if !defined(ARCH_PORTDUINO)
#if BME680_BSEC2_SUPPORTED == 1
const char *bsecConfigFileName = "/prefs/bsec.dat";
uint8_t bsecState[BSEC_MAX_STATE_BLOB_SIZE] = {0};
uint8_t accuracy = 0;
@@ -54,13 +53,13 @@ class BME680Sensor : public TelemetrySensor
void loadState();
void updateState();
void checkStatus(const char *functionName);
#endif // !defined(ARCH_PORTDUINO)
#endif // BME680_BSEC2_SUPPORTED
public:
BME680Sensor();
#if !defined(ARCH_PORTDUINO)
#if BME680_BSEC2_SUPPORTED == 1
virtual int32_t runOnce() override;
#endif // !defined(ARCH_PORTDUINO)
#endif // BME680_BSEC2_SUPPORTED
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
virtual bool initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev) override;
};

View File

@@ -487,8 +487,11 @@ bool MQTT::publish(const char *topic, const uint8_t *payload, size_t length, boo
{
if (moduleConfig.mqtt.proxy_to_client_enabled) {
meshtastic_MqttClientProxyMessage *msg = mqttClientProxyMessagePool.allocZeroed();
size_t topic_len = strlen(topic);
msg->which_payload_variant = meshtastic_MqttClientProxyMessage_data_tag;
strlcpy(msg->topic, topic, sizeof(msg->topic));
if (strncpy(msg->topic, topic, topic_len) == nullptr) {
msg->topic[sizeof(msg->topic) - 1] = 0;
}
if (length > sizeof(msg->payload_variant.data.bytes))
length = sizeof(msg->payload_variant.data.bytes);
msg->payload_variant.data.size = length;