mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-09-26 20:56:37 +00:00
Merge remote-tracking branch 'upstream/dev' into rak-ethernet
# Conflicts: # docs/faq.md # examples/companion_radio/main.cpp
This commit is contained in:
@@ -12,6 +12,31 @@
|
||||
// Sensor library includes and static driver instances
|
||||
// ============================================================
|
||||
|
||||
#if ENV_INCLUDE_BME680_BSEC
|
||||
#ifndef TELEM_BME680_ADDRESS
|
||||
#define TELEM_BME680_ADDRESS 0x76
|
||||
#endif
|
||||
#define TELEM_BME680_SEALEVELPRESSURE_HPA (1013.25)
|
||||
#include <bsec.h>
|
||||
#include <Adafruit_LittleFS.h>
|
||||
#include <InternalFileSystem.h>
|
||||
static const uint8_t bsec_config_iaq[] = {
|
||||
#include "config/generic_33v_3s_28d/bsec_iaq.txt" // 3.3v, LP, 28 day background calibration window
|
||||
};
|
||||
static Bsec bsec_iaq;
|
||||
static float bsec_temperature = 0;
|
||||
static float bsec_humidity = 0;
|
||||
static float bsec_pressure_hpa = 0;
|
||||
static float bsec_iaq_val = 0;
|
||||
static uint8_t bsec_accuracy = 0;
|
||||
static bool bsec_active = false;
|
||||
static bool bsec_data_ready = false;
|
||||
static bool bsec_first_save_done = false;
|
||||
static uint32_t bsec_last_save_ms = 0;
|
||||
#define BSEC_STATE_FILE "/bsec_state.bin"
|
||||
#define BSEC_SAVE_INTERVAL_MS (8UL * 60 * 60 * 1000) // 8 hour state-save interval
|
||||
#endif
|
||||
|
||||
#ifdef ENV_INCLUDE_BME680
|
||||
#ifndef TELEM_BME680_ADDRESS
|
||||
#define TELEM_BME680_ADDRESS 0x76
|
||||
@@ -28,7 +53,9 @@ static Adafruit_BMP085 BMP085;
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_AHTX0
|
||||
#ifndef TELEM_AHTX_ADDRESS
|
||||
#define TELEM_AHTX_ADDRESS 0x38 // AHT10, AHT20 temperature and humidity sensor I2C address
|
||||
#endif
|
||||
#include <Adafruit_AHTX0.h>
|
||||
static Adafruit_AHTX0 AHTX0;
|
||||
#endif
|
||||
@@ -57,7 +84,9 @@ static Adafruit_SHTC3 SHTC3;
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_SHT4X
|
||||
#ifndef TELEM_SHT4X_ADDRESS
|
||||
#define TELEM_SHT4X_ADDRESS 0x44
|
||||
#endif
|
||||
#include <SensirionI2cSht4x.h>
|
||||
static SensirionI2cSht4x SHT4X;
|
||||
#endif
|
||||
@@ -82,19 +111,25 @@ static Adafruit_INA3221 INA3221;
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_INA219
|
||||
#ifndef TELEM_INA219_ADDRESS
|
||||
#define TELEM_INA219_ADDRESS 0x40 // INA219 single channel current sensor I2C address
|
||||
#endif
|
||||
#include <Adafruit_INA219.h>
|
||||
static Adafruit_INA219 INA219(TELEM_INA219_ADDRESS);
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_INA260
|
||||
#ifndef TELEM_INA260_ADDRESS
|
||||
#define TELEM_INA260_ADDRESS 0x41 // INA260 single channel current sensor I2C address
|
||||
#endif
|
||||
#include <Adafruit_INA260.h>
|
||||
static Adafruit_INA260 INA260;
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_INA226
|
||||
#ifndef TELEM_INA226_ADDRESS
|
||||
#define TELEM_INA226_ADDRESS 0x44
|
||||
#endif
|
||||
#define TELEM_INA226_SHUNT_VALUE 0.100
|
||||
#define TELEM_INA226_MAX_AMP 0.8
|
||||
#include <INA226.h>
|
||||
@@ -102,19 +137,25 @@ static INA226 INA226(TELEM_INA226_ADDRESS, TELEM_WIRE);
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_MLX90614
|
||||
#ifndef TELEM_MLX90614_ADDRESS
|
||||
#define TELEM_MLX90614_ADDRESS 0x5A // MLX90614 IR temperature sensor I2C address
|
||||
#endif
|
||||
#include <Adafruit_MLX90614.h>
|
||||
static Adafruit_MLX90614 MLX90614;
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_VL53L0X
|
||||
#ifndef TELEM_VL53L0X_ADDRESS
|
||||
#define TELEM_VL53L0X_ADDRESS 0x29 // VL53L0X time-of-flight distance sensor I2C address
|
||||
#endif
|
||||
#include <Adafruit_VL53L0X.h>
|
||||
static Adafruit_VL53L0X VL53L0X;
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_RAK12035
|
||||
#ifndef TELEM_RAK12035_ADDRESS
|
||||
#define TELEM_RAK12035_ADDRESS 0x20 // RAK12035 Soil Moisture sensor I2C address
|
||||
#endif
|
||||
#include "RAK12035_SoilMoisture.h"
|
||||
static RAK12035_SoilMoisture RAK12035;
|
||||
#endif
|
||||
@@ -127,7 +168,9 @@ static RAK12035_SoilMoisture RAK12035;
|
||||
static uint32_t gpsResetPin = 0;
|
||||
static bool i2cGPSFlag = false;
|
||||
static bool serialGPSFlag = false;
|
||||
#ifndef TELEM_RAK12500_ADDRESS
|
||||
#define TELEM_RAK12500_ADDRESS 0x42 //RAK12500 Ublox GPS via i2c
|
||||
#endif
|
||||
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>
|
||||
static SFE_UBLOX_GNSS ublox_GNSS;
|
||||
|
||||
@@ -217,9 +260,10 @@ static void query_bme680(uint8_t ch, uint8_t, CayenneLPP& lpp) {
|
||||
if (BME680.performReading()) {
|
||||
lpp.addTemperature(ch, BME680.temperature);
|
||||
lpp.addRelativeHumidity(ch, BME680.humidity);
|
||||
lpp.addBarometricPressure(ch, BME680.pressure / 100);
|
||||
lpp.addAltitude(ch, 44330.0 * (1.0 - pow((BME680.pressure / 100) / TELEM_BME680_SEALEVELPRESSURE_HPA, 0.1903)));
|
||||
lpp.addAnalogInput(ch, BME680.gas_resistance);
|
||||
const float pressure_hpa = BME680.pressure / 100.0f;
|
||||
lpp.addBarometricPressure(ch, pressure_hpa);
|
||||
lpp.addAltitude(ch, 44330.0f * (1.0f - powf(pressure_hpa / (float)TELEM_BME680_SEALEVELPRESSURE_HPA, 0.1903f)));
|
||||
lpp.addGenericSensor(ch, BME680.gas_resistance);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -431,6 +475,62 @@ static void query_rak12035(uint8_t ch, uint8_t sub_ch, CayenneLPP& lpp) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENV_INCLUDE_BME680_BSEC
|
||||
static void bsec_load_state() {
|
||||
using namespace Adafruit_LittleFS_Namespace;
|
||||
File f = InternalFS.open(BSEC_STATE_FILE, FILE_O_READ);
|
||||
if (!f) return;
|
||||
uint8_t state[BSEC_MAX_STATE_BLOB_SIZE];
|
||||
f.read(state, BSEC_MAX_STATE_BLOB_SIZE);
|
||||
f.close();
|
||||
bsec_iaq.setState(state);
|
||||
}
|
||||
|
||||
static void bsec_save_state() {
|
||||
using namespace Adafruit_LittleFS_Namespace;
|
||||
uint8_t state[BSEC_MAX_STATE_BLOB_SIZE];
|
||||
bsec_iaq.getState(state);
|
||||
InternalFS.remove(BSEC_STATE_FILE);
|
||||
File f = InternalFS.open(BSEC_STATE_FILE, FILE_O_WRITE);
|
||||
if (!f) return;
|
||||
f.write(state, BSEC_MAX_STATE_BLOB_SIZE);
|
||||
f.close();
|
||||
}
|
||||
|
||||
static uint8_t init_bme680_bsec(TwoWire* wire, uint8_t addr) {
|
||||
bsec_iaq.begin(addr, *wire);
|
||||
if (bsec_iaq.bsecStatus != BSEC_OK) return 0;
|
||||
|
||||
bsec_iaq.setConfig(bsec_config_iaq);
|
||||
if (bsec_iaq.bsecStatus != BSEC_OK) return 0;
|
||||
|
||||
bsec_virtual_sensor_t outputs[] = {
|
||||
BSEC_OUTPUT_IAQ,
|
||||
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
|
||||
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
|
||||
BSEC_OUTPUT_RAW_PRESSURE,
|
||||
BSEC_OUTPUT_STABILIZATION_STATUS,
|
||||
BSEC_OUTPUT_RUN_IN_STATUS,
|
||||
};
|
||||
bsec_iaq.updateSubscription(outputs, 6, BSEC_SAMPLE_RATE_LP);
|
||||
if (bsec_iaq.bsecStatus != BSEC_OK) return 0;
|
||||
|
||||
bsec_load_state();
|
||||
bsec_active = true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void query_bme680_bsec(uint8_t ch, uint8_t, CayenneLPP& lpp) {
|
||||
if (!bsec_data_ready) return;
|
||||
lpp.addTemperature(ch, bsec_temperature);
|
||||
lpp.addRelativeHumidity(ch, bsec_humidity);
|
||||
lpp.addBarometricPressure(ch, bsec_pressure_hpa);
|
||||
lpp.addAltitude(ch, 44330.0f * (1.0f - powf(bsec_pressure_hpa / (float)TELEM_BME680_SEALEVELPRESSURE_HPA, 0.1903f)));
|
||||
lpp.addGenericSensor(ch, (uint16_t)bsec_iaq_val);
|
||||
lpp.addAnalogInput(ch, (float)bsec_accuracy);
|
||||
}
|
||||
#endif
|
||||
|
||||
// ============================================================
|
||||
// Sensor descriptor table
|
||||
//
|
||||
@@ -458,6 +558,9 @@ static const SensorDef SENSOR_TABLE[] = {
|
||||
#ifdef ENV_INCLUDE_BME680
|
||||
{ TELEM_BME680_ADDRESS, "BME680", init_bme680, query_bme680 },
|
||||
#endif
|
||||
#if ENV_INCLUDE_BME680_BSEC
|
||||
{ TELEM_BME680_ADDRESS, "BME680+BSEC", init_bme680_bsec, query_bme680_bsec },
|
||||
#endif
|
||||
#if ENV_INCLUDE_BME280
|
||||
{ TELEM_BME280_ADDRESS, "BME280", init_bme280, query_bme280 },
|
||||
#endif
|
||||
@@ -787,11 +890,13 @@ void EnvironmentSensorManager::stop_gps() {
|
||||
MESH_DEBUG_PRINTLN("Stop GPS is N/A on this board. Actual GPS state unchanged");
|
||||
#endif
|
||||
}
|
||||
#endif // ENV_INCLUDE_GPS
|
||||
|
||||
#if ENV_INCLUDE_GPS || defined(ENV_INCLUDE_BME680_BSEC)
|
||||
void EnvironmentSensorManager::loop() {
|
||||
static long next_gps_update = 0;
|
||||
|
||||
#if ENV_INCLUDE_GPS
|
||||
static long next_gps_update = 0;
|
||||
if (gps_active) {
|
||||
_location->loop();
|
||||
}
|
||||
@@ -819,5 +924,27 @@ void EnvironmentSensorManager::loop() {
|
||||
next_gps_update = millis() + (gps_update_interval_sec * 1000);
|
||||
}
|
||||
#endif
|
||||
#if ENV_INCLUDE_BME680_BSEC
|
||||
if (bsec_active && bsec_iaq.run()) {
|
||||
uint8_t prev_accuracy = bsec_accuracy;
|
||||
bsec_temperature = bsec_iaq.temperature;
|
||||
bsec_humidity = bsec_iaq.humidity;
|
||||
bsec_pressure_hpa = bsec_iaq.pressure / 100.0f;
|
||||
bsec_iaq_val = bsec_iaq.iaq;
|
||||
bsec_accuracy = bsec_iaq.iaqAccuracy;
|
||||
bsec_data_ready = true;
|
||||
|
||||
if (bsec_accuracy == 3) {
|
||||
if (!bsec_first_save_done) {
|
||||
bsec_save_state();
|
||||
bsec_last_save_ms = millis();
|
||||
bsec_first_save_done = true;
|
||||
} else if ((millis() - bsec_last_save_ms) >= BSEC_SAVE_INTERVAL_MS) {
|
||||
bsec_save_state();
|
||||
bsec_last_save_ms = millis();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // ENV_INCLUDE_BME680_BSEC
|
||||
}
|
||||
#endif
|
||||
#endif // ENV_INCLUDE_GPS || ENV_INCLUDE_BME680_BSEC
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
#endif
|
||||
bool begin() override;
|
||||
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override;
|
||||
#if ENV_INCLUDE_GPS
|
||||
#if ENV_INCLUDE_GPS || defined(ENV_INCLUDE_BME680_BSEC)
|
||||
void loop() override;
|
||||
#endif
|
||||
int getNumSettings() const override;
|
||||
|
||||
@@ -67,10 +67,10 @@ void RAK12035_SoilMoisture::setup(TwoWire &i2c)
|
||||
// setup() and that the bus has been initialized externally (Wire.begin()).
|
||||
// It uses the passed in I2C Address (default 0x20)
|
||||
//
|
||||
// *** This code does not supprt three sensors ***
|
||||
// *** This code does not support three sensors ***
|
||||
// The RAK12023 has three connectors, but each of the sensors attached must
|
||||
// all have a different I2C addresses.
|
||||
// This code has a function to set the I2C adress of a sensor
|
||||
// all have different I2C addresses.
|
||||
// This code has a function to set the I2C address of a sensor
|
||||
// and currently only supports one address 0x20 (the default).
|
||||
// To support three sensors, EnvironmentSensorManager would need to be modified
|
||||
// to support multiple instances of the RAK12035_SoilMoisture class,
|
||||
@@ -78,7 +78,7 @@ void RAK12035_SoilMoisture::setup(TwoWire &i2c)
|
||||
// The begin() function would need to be modified to loop through the three addresses
|
||||
//
|
||||
// DEBUG STATEMENTS: Can be enabled by uncommenting or adding:
|
||||
// File: varients/rak4631 platformio.ini
|
||||
// File: variants/rak4631 platformio.ini
|
||||
// Section example: [env:RAK_4631_companion_radio_ble]
|
||||
// Enable Debug statements: -D MESH_DEBUG=1
|
||||
//
|
||||
@@ -107,7 +107,7 @@ bool RAK12035_SoilMoisture::begin(uint8_t addr)
|
||||
* Change the value to 1 in the RAK12035_SoilMoisture.h file
|
||||
*
|
||||
* Calibration Procedure:
|
||||
* 1) Flash the the Calibration version of the firmware.
|
||||
* 1) Flash the Calibration version of the firmware.
|
||||
* 2) Leave the sensor dry, power up the device.
|
||||
* 3) After detecting the RAK12035 this firmware will display calibration data on Channel 3
|
||||
*
|
||||
@@ -242,7 +242,7 @@ bool RAK12035_SoilMoisture::sensor_sleep() //Command 06
|
||||
// Optional: turn off sensor power AFTER successful sleep command
|
||||
|
||||
// This has been commented out due to a pin name conflict with the Heltec v3
|
||||
// This will need to be resolved if this funstion is to be utilized in the future
|
||||
// This will need to be resolved if this function is to be utilized in the future
|
||||
/*
|
||||
digitalWrite(WB_IO2, LOW);
|
||||
*/
|
||||
@@ -376,7 +376,7 @@ uint16_t RAK12035_SoilMoisture::get_humidity_zero() //Command 0B
|
||||
* getEvent() - High-level function to read both moisture and temperature in one call. *
|
||||
*------------------------------------------------------------------------------------------*
|
||||
* This function reads the moisture percentage and temperature from the sensor and returns *
|
||||
* them via output parameters. This may be used for the telemerty delivery in the MeshCore *
|
||||
* them via output parameters. This may be used for the telemetry delivery in the MeshCore *
|
||||
* firmware, with a single function to get all sensor data. *
|
||||
* *
|
||||
* The function returns true if both readings were successfully obtained, or false if any *
|
||||
@@ -417,7 +417,7 @@ bool RAK12035_SoilMoisture::sensor_on()
|
||||
{
|
||||
uint8_t data;
|
||||
// This has been commented out due to a pin name conflict with the Heltec v3
|
||||
// This will need to be resolved if this funstion is to be utilized in the future
|
||||
// This will need to be resolved if this function is to be utilized in the future
|
||||
|
||||
/*
|
||||
pinMode(WB_IO2, OUTPUT);
|
||||
@@ -460,7 +460,7 @@ bool RAK12035_SoilMoisture::reset()
|
||||
// But might be needed if power is ever switched off. Here is tested code.
|
||||
|
||||
// This has been commented out due to a pin name conflict with the Heltec v3
|
||||
// This will need to be resolved if this funstion is to be utilized in the future
|
||||
// This will need to be resolved if this function is to be utilized in the future
|
||||
|
||||
/*
|
||||
pinMode(WB_IO4, OUTPUT); //Set IO4 Pin to Output (connected to *reset on sensor)
|
||||
|
||||
Reference in New Issue
Block a user