ESP Electro MCP, ExtSens smoothing
This commit is contained in:
@@ -16,3 +16,4 @@ monitor_speed = 115200
|
||||
lib_deps =
|
||||
enjoyneering/AHT10@^1.1.0
|
||||
mysensors/MySensors @ ^2.3.2
|
||||
robtillaart/RunningMedian @ ^0.3.3
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#define MY_DEFAULT_LED_BLINK_PERIOD 5
|
||||
#include <MySensors.h>
|
||||
#include <AHT10.h>
|
||||
#include "RunningMedian.h"
|
||||
|
||||
uint32_t cRun;
|
||||
int BATTERY_SENSE_PIN = A0;
|
||||
@@ -28,20 +29,27 @@ void sendData(MyMessage msg, bool status);
|
||||
void sendData(MyMessage msg, uint32_t status);
|
||||
|
||||
AHT10 myAHT10(AHT10_ADDRESS_0X38);
|
||||
#define TIME_SLEEP 300000
|
||||
|
||||
RunningMedian tempRM = RunningMedian(4);
|
||||
RunningMedian humRM = RunningMedian(4);
|
||||
|
||||
void setup() {
|
||||
analogReference(INTERNAL);
|
||||
sensorValue = analogRead(BATTERY_SENSE_PIN);
|
||||
v = sensorValue * 0.004659498;
|
||||
batteryPcnt = (v-3.0 * 100) / 1.2;
|
||||
float temp, hum;
|
||||
//analogReference(INTERNAL);
|
||||
//sensorValue = analogRead(BATTERY_SENSE_PIN);
|
||||
//v = sensorValue * 0.004659498;
|
||||
//batteryPcnt = (v-3.0 * 100) / 1.2;
|
||||
while (myAHT10.begin() != true)
|
||||
{
|
||||
Serial.println(F("AHT10 not connected or fail to load calibration coefficient")); //(F()) save string to flash & keeps dynamic memory free
|
||||
delay(5000);
|
||||
}
|
||||
Serial.println(F("AHT10 OK"));
|
||||
Serial.print(F("T: ")); Serial.print(myAHT10.readTemperature(AHT10_FORCE_READ_DATA));// Serial.println(F(" +-0.3C"));
|
||||
Serial.print(F("H: ")); Serial.print(myAHT10.readHumidity(AHT10_USE_READ_DATA));// Serial.println(F(" +-2%"));
|
||||
Serial.print(F("T: ")); Serial.print(temp = myAHT10.readTemperature(AHT10_FORCE_READ_DATA));// Serial.println(F(" +-0.3C"));
|
||||
Serial.print(F("H: ")); Serial.print(hum = myAHT10.readHumidity(AHT10_USE_READ_DATA));// Serial.println(F(" +-2%"));
|
||||
sendData(msgTemp, temp, 1);
|
||||
sendData(msgHum, hum, 1);
|
||||
|
||||
cRun = 0;
|
||||
sendData(msgMillis, cRun);
|
||||
@@ -49,28 +57,36 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
float temp, hum;
|
||||
unsigned long t = millis();
|
||||
temp = myAHT10.readTemperature(AHT10_FORCE_READ_DATA);
|
||||
hum = myAHT10.readHumidity(AHT10_USE_READ_DATA);
|
||||
Serial.print(F("T: ")); Serial.println(temp);// Serial.println(F(" +-0.3C"));
|
||||
Serial.print(F("H: ")); Serial.println(hum);// Serial.println(F(" +-2%"));
|
||||
if (temp < 200){
|
||||
sendData(msgTemp, temp, 1);
|
||||
sendData(msgHum, hum, 1);
|
||||
// send(msgTemp.set(temp, 1));
|
||||
// send(msgHum.set(hum, 1));
|
||||
}
|
||||
sensorValue = analogRead(BATTERY_SENSE_PIN);
|
||||
v = sensorValue * 0.004659498;
|
||||
//batteryPcnt = ((v-3.0) * 100) / 1.2;
|
||||
//sendBatteryLevel(batteryPcnt);
|
||||
float temp, hum;
|
||||
static uint8_t nRun = 0;
|
||||
unsigned long t = millis();
|
||||
|
||||
temp = myAHT10.readTemperature(AHT10_FORCE_READ_DATA);
|
||||
hum = myAHT10.readHumidity(AHT10_USE_READ_DATA);
|
||||
//Serial.print(F("T: ")); Serial.println(temp);// Serial.println(F(" +-0.3C"));
|
||||
//Serial.print(F("H: ")); Serial.println(hum);// Serial.println(F(" +-2%"));
|
||||
if (temp < 200){
|
||||
tempRM.add(temp);
|
||||
humRM.add(hum);
|
||||
// send(msgTemp.set(temp, 1));
|
||||
// send(msgHum.set(hum, 1));
|
||||
}
|
||||
unsigned long battMV = hwCPUVoltage();
|
||||
v = battMV / 1000.0;
|
||||
//sensorValue = analogRead(BATTERY_SENSE_PIN);
|
||||
//v = sensorValue * 0.004659498;
|
||||
//batteryPcnt = ((v-3.0) * 100) / 1.2;
|
||||
//sendBatteryLevel(batteryPcnt);
|
||||
if(nRun == 3){
|
||||
sendData(msgTemp, tempRM.getMedian(), 1);
|
||||
sendData(msgHum, humRM.getMedian(), 1);
|
||||
sendData(msgVolts, v, 2);
|
||||
//send(msgVolts.set(v, 2));
|
||||
Serial.println(F("Tm run")); Serial.println(millis() - t);
|
||||
sendData(msgMillis, cRun++);
|
||||
//send(msgMillis.set(cRun++));
|
||||
sleep(120000 - (millis() - t));
|
||||
//Serial.println(F("Tm run")); Serial.println(millis() - t);
|
||||
sendData(msgMillis, ++cRun * TIME_SLEEP / 60000);
|
||||
}
|
||||
//send(msgMillis.set(cRun++));
|
||||
sleep((TIME_SLEEP / 4) - (millis() - t));
|
||||
}
|
||||
|
||||
void presentation()
|
||||
|
||||
Reference in New Issue
Block a user