sforkowany z mirror/meshtastic-firmware
rodzic
e4fe2c159a
commit
66413d8b7f
2
proto
2
proto
|
@ -1 +1 @@
|
|||
Subproject commit 07ed86d8b44f53091fafd007f729a67f4785e270
|
||||
Subproject commit 6c39b5bf472677122b3ebf77b434af09038ff0dc
|
|
@ -6,19 +6,20 @@
|
|||
#include "Router.h"
|
||||
#include "configuration.h"
|
||||
#include "main.h"
|
||||
#include <DHT.h>
|
||||
#include <DS18B20.h>
|
||||
#include <OLEDDisplay.h>
|
||||
#include <OLEDDisplayUi.h>
|
||||
#include <OneWire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_BME280.h>
|
||||
#include <Adafruit_BME680.h>
|
||||
|
||||
#define DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
|
||||
#define DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
|
||||
#define DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
|
||||
#define BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
|
||||
// Sensors
|
||||
#include "Sensor/BME280Sensor.h"
|
||||
#include "Sensor/BME680Sensor.h"
|
||||
#include "Sensor/DHTSensor.h"
|
||||
#include "Sensor/DallasSensor.h"
|
||||
|
||||
BME280Sensor bme280Sensor;
|
||||
BME680Sensor bme680Sensor;
|
||||
DHTSensor dhtSensor;
|
||||
DallasSensor dallasSensor;
|
||||
|
||||
#define FAILED_STATE_SENSOR_READ_MULTIPLIER 10
|
||||
#define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true
|
||||
|
||||
|
@ -38,6 +39,7 @@
|
|||
#define FONT_HEIGHT_SMALL fontHeight(FONT_SMALL)
|
||||
#define FONT_HEIGHT_MEDIUM fontHeight(FONT_MEDIUM)
|
||||
|
||||
|
||||
int32_t EnvironmentalMeasurementPlugin::runOnce()
|
||||
{
|
||||
#ifndef PORTDUINO
|
||||
|
@ -45,8 +47,8 @@ int32_t EnvironmentalMeasurementPlugin::runOnce()
|
|||
Uncomment the preferences below if you want to use the plugin
|
||||
without having to configure it from the PythonAPI or WebUI.
|
||||
*/
|
||||
|
||||
/*radioConfig.preferences.environmental_measurement_plugin_measurement_enabled = 1;
|
||||
/*
|
||||
radioConfig.preferences.environmental_measurement_plugin_measurement_enabled = 1;
|
||||
radioConfig.preferences.environmental_measurement_plugin_screen_enabled = 1;
|
||||
radioConfig.preferences.environmental_measurement_plugin_read_error_count_threshold = 5;
|
||||
radioConfig.preferences.environmental_measurement_plugin_update_interval = 600;
|
||||
|
@ -75,72 +77,28 @@ int32_t EnvironmentalMeasurementPlugin::runOnce()
|
|||
// therefore, we should only enable the sensor loop if measurement is also enabled
|
||||
switch (radioConfig.preferences.environmental_measurement_plugin_sensor_type) {
|
||||
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT12:
|
||||
dht = new DHT(radioConfig.preferences.environmental_measurement_plugin_sensor_pin, DHT11);
|
||||
this->dht->begin();
|
||||
this->dht->read();
|
||||
DEBUG_MSG("EnvironmentalMeasurement: Opened DHT11/DHT12 on pin: %d\n",
|
||||
radioConfig.preferences.environmental_measurement_plugin_sensor_pin);
|
||||
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DS18B20:
|
||||
oneWire = new OneWire(radioConfig.preferences.environmental_measurement_plugin_sensor_pin);
|
||||
ds18b20 = new DS18B20(oneWire);
|
||||
this->ds18b20->begin();
|
||||
this->ds18b20->setResolution(12);
|
||||
this->ds18b20->requestTemperatures();
|
||||
DEBUG_MSG("EnvironmentalMeasurement: Opened DS18B20 on pin: %d\n",
|
||||
radioConfig.preferences.environmental_measurement_plugin_sensor_pin);
|
||||
return (DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT21:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT22:
|
||||
dht = new DHT(radioConfig.preferences.environmental_measurement_plugin_sensor_pin, DHT22);
|
||||
this->dht->begin();
|
||||
this->dht->read();
|
||||
DEBUG_MSG("EnvironmentalMeasurement: Opened DHT21/DHT22 on pin: %d\n",
|
||||
radioConfig.preferences.environmental_measurement_plugin_sensor_pin);
|
||||
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME280:
|
||||
unsigned bme280Status;
|
||||
// Default i2c address for BME280
|
||||
bme280Status = bme280.begin(0x76);
|
||||
if (!bme280Status) {
|
||||
DEBUG_MSG("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
|
||||
// TODO more verbose diagnostics
|
||||
} else {
|
||||
DEBUG_MSG("EnvironmentalMeasurement: Opened BME280 on default i2c bus");
|
||||
}
|
||||
return (BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680:
|
||||
unsigned bme680Status;
|
||||
// Default i2c address for BME280
|
||||
bme680Status = bme680.begin(0x76);
|
||||
if (!bme680Status) {
|
||||
DEBUG_MSG("Could not find a valid BME680 sensor, check wiring, address, sensor ID!");
|
||||
// TODO more verbose diagnostics
|
||||
} else {
|
||||
DEBUG_MSG("EnvironmentalMeasurement: Opened BME680 on default i2c bus");
|
||||
// Set up oversampling and filter initialization
|
||||
bme680.setTemperatureOversampling(BME680_OS_8X);
|
||||
bme680.setHumidityOversampling(BME680_OS_2X);
|
||||
bme680.setPressureOversampling(BME680_OS_4X);
|
||||
bme680.setIIRFilterSize(BME680_FILTER_SIZE_3);
|
||||
bme680.setGasHeater(320, 150); // 320*C for 150 ms
|
||||
}
|
||||
return (BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
default:
|
||||
DEBUG_MSG("EnvironmentalMeasurement: Invalid sensor type selected; Disabling plugin");
|
||||
return (INT32_MAX);
|
||||
break;
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT12:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT21:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT22:
|
||||
return dhtSensor.runOnce();
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DS18B20:
|
||||
return dallasSensor.runOnce();
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME280:
|
||||
return bme280Sensor.runOnce();
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680:
|
||||
return bme680Sensor.runOnce();
|
||||
default:
|
||||
DEBUG_MSG("EnvironmentalMeasurement: Invalid sensor type selected; Disabling plugin");
|
||||
return (INT32_MAX);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (INT32_MAX);
|
||||
} else {
|
||||
if (!radioConfig.preferences.environmental_measurement_plugin_measurement_enabled) {
|
||||
// if we somehow got to a second run of this plugin with measurement disabled, then just wait forever
|
||||
// I can't imagine we'd ever get here though.
|
||||
// if we somehow got to a second run of this plugin with measurement disabled, then just wait forever
|
||||
if (!radioConfig.preferences.environmental_measurement_plugin_measurement_enabled)
|
||||
return (INT32_MAX);
|
||||
}
|
||||
// this is not the first time OSThread library has called this function
|
||||
// so just do what we intend to do on the interval
|
||||
if (sensor_read_error_count > radioConfig.preferences.environmental_measurement_plugin_read_error_count_threshold) {
|
||||
|
@ -167,22 +125,20 @@ int32_t EnvironmentalMeasurementPlugin::runOnce()
|
|||
if (!sendOurEnvironmentalMeasurement()) {
|
||||
// if we failed to read the sensor, then try again
|
||||
// as soon as we can according to the maximum polling frequency
|
||||
// return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
|
||||
switch (radioConfig.preferences.environmental_measurement_plugin_sensor_type) {
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT12:
|
||||
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DS18B20:
|
||||
return (DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT21:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT22:
|
||||
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME280:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680:
|
||||
return (BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
default:
|
||||
return (DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT12:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT21:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT22:
|
||||
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DS18B20:
|
||||
return (DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME280:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680:
|
||||
return (BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
default:
|
||||
return (DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +212,6 @@ void EnvironmentalMeasurementPlugin::drawFrame(OLEDDisplay *display, OLEDDisplay
|
|||
String last_temp = String(lastMeasurement.temperature, 0) + "°C";
|
||||
if (radioConfig.preferences.environmental_measurement_plugin_display_farenheit) {
|
||||
last_temp = String(CelsiusToFarenheit(lastMeasurement.temperature), 0) + "°F";
|
||||
;
|
||||
}
|
||||
display->drawString(x, y += fontHeight(FONT_MEDIUM) - 2, "From: " + lastSender + "(" + String(agoSecs) + "s)");
|
||||
display->drawString(x, y += fontHeight(FONT_SMALL) - 2,"Temp/Hum: " + last_temp + " / " + String(lastMeasurement.relative_humidity, 0) + "%");
|
||||
|
@ -278,6 +233,7 @@ bool EnvironmentalMeasurementPlugin::handleReceivedProtobuf(const MeshPacket &mp
|
|||
DEBUG_MSG("EnvironmentalMeasurement->relative_humidity: %f\n", p->relative_humidity);
|
||||
DEBUG_MSG("EnvironmentalMeasurement->temperature: %f\n", p->temperature);
|
||||
DEBUG_MSG("EnvironmentalMeasurement->barometric_pressure: %f\n", p->barometric_pressure);
|
||||
DEBUG_MSG("EnvironmentalMeasurement->gas_resistance: %f\n", p->gas_resistance);
|
||||
|
||||
lastMeasurementPacket = packetPool.allocCopy(mp);
|
||||
|
||||
|
@ -287,62 +243,39 @@ bool EnvironmentalMeasurementPlugin::handleReceivedProtobuf(const MeshPacket &mp
|
|||
bool EnvironmentalMeasurementPlugin::sendOurEnvironmentalMeasurement(NodeNum dest, bool wantReplies)
|
||||
{
|
||||
EnvironmentalMeasurement m;
|
||||
|
||||
m.barometric_pressure = 0; // TODO: Add support for barometric sensors
|
||||
m.barometric_pressure = 0;
|
||||
m.gas_resistance = 0;
|
||||
DEBUG_MSG("-----------------------------------------\n");
|
||||
|
||||
DEBUG_MSG("EnvironmentalMeasurement: Read data\n");
|
||||
|
||||
switch (radioConfig.preferences.environmental_measurement_plugin_sensor_type) {
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT12:
|
||||
if (!this->dht->read(true)) {
|
||||
sensor_read_error_count++;
|
||||
DEBUG_MSG("EnvironmentalMeasurement: FAILED TO READ DATA\n");
|
||||
return false;
|
||||
}
|
||||
m.relative_humidity = this->dht->readHumidity();
|
||||
m.temperature = this->dht->readTemperature();
|
||||
break;
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DS18B20:
|
||||
if (this->ds18b20->isConversionComplete()) {
|
||||
m.temperature = this->ds18b20->getTempC();
|
||||
m.relative_humidity = 0; // This sensor is temperature only
|
||||
this->ds18b20->requestTemperatures();
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DS18B20:
|
||||
if (!dallasSensor.getMeasurement(&m))
|
||||
sensor_read_error_count++;
|
||||
break;
|
||||
} else {
|
||||
sensor_read_error_count++;
|
||||
DEBUG_MSG("EnvironmentalMeasurement: FAILED TO READ DATA\n");
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT12:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT21:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT22:
|
||||
if (!dhtSensor.getMeasurement(&m))
|
||||
sensor_read_error_count++;
|
||||
break;
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME280:
|
||||
bme280Sensor.getMeasurement(&m);
|
||||
break;
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680:
|
||||
bme680Sensor.getMeasurement(&m);
|
||||
break;
|
||||
default:
|
||||
DEBUG_MSG("EnvironmentalMeasurement: Invalid sensor type selected; Disabling plugin");
|
||||
return false;
|
||||
}
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT21:
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT22:
|
||||
if (!this->dht->read(true)) {
|
||||
sensor_read_error_count++;
|
||||
DEBUG_MSG("EnvironmentalMeasurement: FAILED TO READ DATA\n");
|
||||
return false;
|
||||
}
|
||||
m.relative_humidity = this->dht->readHumidity();
|
||||
m.temperature = this->dht->readTemperature();
|
||||
break;
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME280:
|
||||
m.temperature = bme280.readTemperature();
|
||||
m.relative_humidity = bme280.readHumidity();
|
||||
m.barometric_pressure = bme280.readPressure() / 100.0F;
|
||||
break;
|
||||
case RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_BME680:
|
||||
m.temperature = bme680.readTemperature();
|
||||
m.relative_humidity = bme680.readHumidity();
|
||||
m.barometric_pressure = bme680.readPressure() / 100.0F;
|
||||
break;
|
||||
default:
|
||||
DEBUG_MSG("EnvironmentalMeasurement: Invalid sensor type selected; Disabling plugin");
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_MSG("EnvironmentalMeasurement->relative_humidity: %f\n", m.relative_humidity);
|
||||
DEBUG_MSG("EnvironmentalMeasurement->temperature: %f\n", m.temperature);
|
||||
DEBUG_MSG("EnvironmentalMeasurement->barometric_pressure: %f\n", m.barometric_pressure);
|
||||
DEBUG_MSG("EnvironmentalMeasurement->gas_resistance: %f\n", m.gas_resistance);
|
||||
|
||||
sensor_read_error_count = 0;
|
||||
|
|
@ -1,14 +1,8 @@
|
|||
#pragma once
|
||||
#include "../mesh/generated/environmental_measurement.pb.h"
|
||||
#include "ProtobufPlugin.h"
|
||||
#include <DHT.h>
|
||||
#include <DS18B20.h>
|
||||
#include <OLEDDisplay.h>
|
||||
#include <OLEDDisplayUi.h>
|
||||
#include <OneWire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_BME280.h>
|
||||
#include <Adafruit_BME680.h>
|
||||
|
||||
class EnvironmentalMeasurementPlugin : private concurrency::OSThread, public ProtobufPlugin<EnvironmentalMeasurement>
|
||||
{
|
||||
|
@ -36,11 +30,6 @@ class EnvironmentalMeasurementPlugin : private concurrency::OSThread, public Pro
|
|||
private:
|
||||
float CelsiusToFarenheit(float c);
|
||||
bool firstTime = 1;
|
||||
DHT *dht = NULL;
|
||||
OneWire *oneWire = NULL;
|
||||
DS18B20 *ds18b20 = NULL;
|
||||
Adafruit_BME280 bme280;
|
||||
Adafruit_BME680 bme680;
|
||||
const MeshPacket *lastMeasurementPacket;
|
||||
uint32_t sensor_read_error_count = 0;
|
||||
};
|
|
@ -0,0 +1,29 @@
|
|||
#include "../mesh/generated/environmental_measurement.pb.h"
|
||||
#include "configuration.h"
|
||||
#include "EnvironmentalMeasurementSensor.h"
|
||||
#include "BME280Sensor.h"
|
||||
#include <Adafruit_BME280.h>
|
||||
|
||||
BME280Sensor::BME280Sensor() : EnvironmentalMeasurementSensor {} {
|
||||
}
|
||||
|
||||
int32_t BME280Sensor::runOnce() {
|
||||
unsigned bme280Status;
|
||||
// Default i2c address for BME280
|
||||
bme280Status = bme280.begin(0x76);
|
||||
if (!bme280Status) {
|
||||
DEBUG_MSG("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
|
||||
// TODO more verbose diagnostics
|
||||
} else {
|
||||
DEBUG_MSG("EnvironmentalMeasurement: Opened BME280 on default i2c bus");
|
||||
}
|
||||
return BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
|
||||
bool BME280Sensor::getMeasurement(EnvironmentalMeasurement *measurement) {
|
||||
measurement->temperature = bme280.readTemperature();
|
||||
measurement->relative_humidity = bme280.readHumidity();
|
||||
measurement->barometric_pressure = bme280.readPressure() / 100.0F;
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#include "../mesh/generated/environmental_measurement.pb.h"
|
||||
#include "EnvironmentalMeasurementSensor.h"
|
||||
#include <Adafruit_BME280.h>
|
||||
|
||||
#define BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
|
||||
|
||||
class BME280Sensor : virtual public EnvironmentalMeasurementSensor {
|
||||
private:
|
||||
Adafruit_BME280 bme280;
|
||||
|
||||
public:
|
||||
BME280Sensor();
|
||||
virtual int32_t runOnce() override;
|
||||
virtual bool getMeasurement(EnvironmentalMeasurement *measurement) override;
|
||||
};
|
|
@ -0,0 +1,36 @@
|
|||
#include "../mesh/generated/environmental_measurement.pb.h"
|
||||
#include "configuration.h"
|
||||
#include "EnvironmentalMeasurementSensor.h"
|
||||
#include "BME680Sensor.h"
|
||||
#include <Adafruit_BME680.h>
|
||||
|
||||
BME680Sensor::BME680Sensor() : EnvironmentalMeasurementSensor {} {
|
||||
}
|
||||
|
||||
int32_t BME680Sensor::runOnce() {
|
||||
unsigned bme680Status;
|
||||
// Default i2c address for BME680
|
||||
bme680Status = bme680.begin(0x76);
|
||||
if (!bme680Status) {
|
||||
DEBUG_MSG("Could not find a valid BME680 sensor, check wiring, address, sensor ID!");
|
||||
// TODO more verbose diagnosticsEnvironmentalMeasurementSensor
|
||||
} else {
|
||||
DEBUG_MSG("EnvironmentalMeasurement: Opened BME680 on default i2c bus");
|
||||
// Set up oversampling and filter initialization
|
||||
bme680.setTemperatureOversampling(BME680_OS_8X);
|
||||
bme680.setHumidityOversampling(BME680_OS_2X);
|
||||
bme680.setPressureOversampling(BME680_OS_4X);
|
||||
bme680.setIIRFilterSize(BME680_FILTER_SIZE_3);
|
||||
bme680.setGasHeater(320, 150); // 320*C for 150 ms
|
||||
}
|
||||
return (BME_680_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
}
|
||||
|
||||
bool BME680Sensor::getMeasurement(EnvironmentalMeasurement *measurement) {
|
||||
measurement->temperature = bme680.readTemperature();
|
||||
measurement->relative_humidity = bme680.readHumidity();
|
||||
measurement->barometric_pressure = bme680.readPressure() / 100.0F;
|
||||
measurement->gas_resistance = bme680.readGas() / 1000.0;
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#include "../mesh/generated/environmental_measurement.pb.h"
|
||||
#include "EnvironmentalMeasurementSensor.h"
|
||||
#include <Adafruit_BME680.h>
|
||||
|
||||
#define BME_680_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
|
||||
|
||||
class BME680Sensor : virtual public EnvironmentalMeasurementSensor {
|
||||
private:
|
||||
Adafruit_BME680 bme680;
|
||||
|
||||
public:
|
||||
BME680Sensor();
|
||||
virtual int32_t runOnce() override;
|
||||
virtual bool getMeasurement(EnvironmentalMeasurement *measurement) override;
|
||||
};
|
|
@ -0,0 +1,36 @@
|
|||
#include "../mesh/generated/environmental_measurement.pb.h"
|
||||
#include "configuration.h"
|
||||
#include "MeshService.h"
|
||||
#include "EnvironmentalMeasurementSensor.h"
|
||||
#include "DHTSensor.h"
|
||||
#include <DHT.h>
|
||||
|
||||
DHTSensor::DHTSensor() : EnvironmentalMeasurementSensor {} {
|
||||
}
|
||||
|
||||
int32_t DHTSensor::runOnce() {
|
||||
if (RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11 ||
|
||||
RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT12) {
|
||||
dht = new DHT(radioConfig.preferences.environmental_measurement_plugin_sensor_pin, DHT11);
|
||||
}
|
||||
else {
|
||||
dht = new DHT(radioConfig.preferences.environmental_measurement_plugin_sensor_pin, DHT22);
|
||||
}
|
||||
|
||||
dht->begin();
|
||||
dht->read();
|
||||
DEBUG_MSG("EnvironmentalMeasurement: Opened DHT11/DHT12 on pin: %d\n",
|
||||
radioConfig.preferences.environmental_measurement_plugin_sensor_pin);
|
||||
|
||||
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
}
|
||||
|
||||
bool DHTSensor::getMeasurement(EnvironmentalMeasurement *measurement) {
|
||||
if (!dht->read(true)) {
|
||||
DEBUG_MSG("EnvironmentalMeasurement: FAILED TO READ DATA\n");
|
||||
return false;
|
||||
}
|
||||
measurement->relative_humidity = dht->readHumidity();
|
||||
measurement->temperature = dht->readTemperature();
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#include "../mesh/generated/environmental_measurement.pb.h"
|
||||
#include "EnvironmentalMeasurementSensor.h"
|
||||
#include <DHT.h>
|
||||
|
||||
#define DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
|
||||
|
||||
class DHTSensor : virtual public EnvironmentalMeasurementSensor {
|
||||
private:
|
||||
DHT *dht = NULL;
|
||||
|
||||
public:
|
||||
DHTSensor();
|
||||
virtual int32_t runOnce() override;
|
||||
virtual bool getMeasurement(EnvironmentalMeasurement *measurement) override;
|
||||
};
|
|
@ -0,0 +1,31 @@
|
|||
#include "../mesh/generated/environmental_measurement.pb.h"
|
||||
#include "configuration.h"
|
||||
#include "MeshService.h"
|
||||
#include "EnvironmentalMeasurementSensor.h"
|
||||
#include "DallasSensor.h"
|
||||
#include <DS18B20.h>
|
||||
#include <OneWire.h>
|
||||
|
||||
DallasSensor::DallasSensor() : EnvironmentalMeasurementSensor {} {
|
||||
}
|
||||
|
||||
int32_t DallasSensor::runOnce() {
|
||||
oneWire = new OneWire(radioConfig.preferences.environmental_measurement_plugin_sensor_pin);
|
||||
ds18b20 = new DS18B20(oneWire);
|
||||
ds18b20->begin();
|
||||
ds18b20->setResolution(12);
|
||||
ds18b20->requestTemperatures();
|
||||
DEBUG_MSG("EnvironmentalMeasurement: Opened DS18B20 on pin: %d\n",
|
||||
radioConfig.preferences.environmental_measurement_plugin_sensor_pin);
|
||||
return (DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
}
|
||||
|
||||
bool DallasSensor::getMeasurement(EnvironmentalMeasurement *measurement) {
|
||||
if (ds18b20->isConversionComplete()) {
|
||||
measurement->temperature = ds18b20->getTempC();
|
||||
measurement->relative_humidity = 0;
|
||||
ds18b20->requestTemperatures();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#include "../mesh/generated/environmental_measurement.pb.h"
|
||||
#include "EnvironmentalMeasurementSensor.h"
|
||||
#include <DS18B20.h>
|
||||
#include <OneWire.h>
|
||||
|
||||
#define DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
|
||||
|
||||
class DallasSensor : virtual public EnvironmentalMeasurementSensor {
|
||||
private:
|
||||
OneWire *oneWire = NULL;
|
||||
DS18B20 *ds18b20 = NULL;
|
||||
|
||||
public:
|
||||
DallasSensor();
|
||||
virtual int32_t runOnce() override;
|
||||
virtual bool getMeasurement(EnvironmentalMeasurement *measurement) override;
|
||||
};
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
#include "../mesh/generated/environmental_measurement.pb.h"
|
||||
#define DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
|
||||
|
||||
class EnvironmentalMeasurementSensor {
|
||||
protected:
|
||||
EnvironmentalMeasurementSensor() { }
|
||||
|
||||
public:
|
||||
virtual int32_t runOnce() = 0;
|
||||
virtual bool getMeasurement(EnvironmentalMeasurement *measurement) = 0;
|
||||
};
|
|
@ -12,7 +12,7 @@
|
|||
#include "plugins/AdminPlugin.h"
|
||||
#include "plugins/CannedMessagePlugin.h"
|
||||
#ifndef PORTDUINO
|
||||
#include "plugins/EnvironmentalMeasurementPlugin.h"
|
||||
#include "plugins/EnvironmentalMeasurement/EnvironmentalMeasurementPlugin.h"
|
||||
#endif
|
||||
#ifndef NO_ESP32
|
||||
#include "plugins/esp32/SerialPlugin.h"
|
||||
|
|
|
@ -8,7 +8,7 @@ src_filter =
|
|||
-<nrf52/>
|
||||
-<mesh/http/>
|
||||
-<plugins/esp32>
|
||||
-<plugins/EnvironmentalMeasurementPlugin.cpp*>
|
||||
-<plugins/EnvironmentalMeasurement>
|
||||
+<../variants/portduino>
|
||||
build_flags = ${arduino_base.build_flags} -O0 -I variants/portduino
|
||||
framework = arduino
|
||||
|
@ -27,7 +27,7 @@ src_filter =
|
|||
-<nrf52/>
|
||||
-<mesh/http/>
|
||||
-<plugins/esp32>
|
||||
-<plugins/EnvironmentalMeasurementPlugin.cpp*>
|
||||
-<plugins/EnvironmentalMeasurement>
|
||||
+<../variants/portduino>
|
||||
build_flags = ${arduino_base.build_flags} -O0 -lgpiod -I variants/portduino
|
||||
framework = arduino
|
||||
|
|
Ładowanie…
Reference in New Issue