ExtSens Sleep
This commit is contained in:
@@ -120,6 +120,8 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
float tempT(NAN), humT(NAN), pressT(NAN);
|
||||
static int gint = 1;
|
||||
static bool gdir = true;
|
||||
|
||||
ArduinoOTA.handle();
|
||||
|
||||
@@ -131,16 +133,23 @@ void loop() {
|
||||
}
|
||||
if((crun + 199) < millis()){
|
||||
crun = millis();
|
||||
minCount++;
|
||||
|
||||
if(gdir) gint += 25;
|
||||
else gint -= 25;
|
||||
if((gint > 499) || (gint < 2)) gdir = !gdir;
|
||||
analogWrite(GREEN, gint);
|
||||
|
||||
adc = analogRead(A0);
|
||||
mv = digitalRead(MOVE_S);
|
||||
if(mv != prMV){
|
||||
if(mv){
|
||||
//mv = true;
|
||||
mv = true;
|
||||
lcd.setBacklight(255);
|
||||
mqttClient.publish("/home/kuh/move", 1, false, "1");
|
||||
}
|
||||
else{
|
||||
//mv = false;
|
||||
mv = false;
|
||||
lcd.setBacklight(0);
|
||||
mqttClient.publish("/home/kuh/move", 1, false, "0");
|
||||
}
|
||||
@@ -155,22 +164,21 @@ void loop() {
|
||||
lightOn = true;
|
||||
}
|
||||
|
||||
//if(((minCount+5) % 10) == 0){ //Once in Second
|
||||
if(((minCount+5) % 10) == 0){ //Once in 2 Second
|
||||
bme.read(pressT, tempT, humT, tempUnit, presUnit);
|
||||
if(!isnan(pressT)){
|
||||
if(!isnan(press)) press += (pressT / 133.322f - press) / 600.0f;
|
||||
if(!isnan(press)) press += (pressT / 133.322f - press) / 30.0f;
|
||||
else press = pressT / 133.322f;
|
||||
}
|
||||
if(!isnan(tempT)){
|
||||
if(!isnan(tempIn)) tempIn += (tempT - tempIn) / 300.0f;
|
||||
if(!isnan(tempIn)) tempIn += (tempT - tempIn) / 30.0f;
|
||||
else tempIn = tempT;
|
||||
}
|
||||
if(!isnan(humT)){
|
||||
if(!isnan(hum)) hum += (humT - hum) / 300.0f;
|
||||
if(!isnan(hum)) hum += (humT - hum) / 30.0f;
|
||||
else hum = humT;
|
||||
}
|
||||
//}
|
||||
minCount++;
|
||||
}
|
||||
if (minCount == 300){ //Once in Minute
|
||||
lcd.begin(16, 2);
|
||||
publishMin();
|
||||
@@ -178,7 +186,8 @@ void loop() {
|
||||
}
|
||||
if((minCount % 5) == 0){ //Once in Second
|
||||
getTemp();
|
||||
publishSec();
|
||||
//digitalWrite(GREEN, !digitalRead(GREEN));
|
||||
//publishSec();
|
||||
showLCD(LCDpage, mv);
|
||||
}
|
||||
}
|
||||
@@ -221,7 +230,7 @@ void showLCD(int page, bool l_on)
|
||||
|
||||
void publishSec()
|
||||
{
|
||||
digitalWrite(GREEN, HIGH);
|
||||
/* digitalWrite(GREEN, HIGH);
|
||||
dtostrf(tempOut, 6, 1, strFVal);
|
||||
mqttClient.publish("/hometest/kuh1s/temp_out", 1, false, strFVal);
|
||||
dtostrf(tempIn, 6, 1, strFVal);
|
||||
@@ -240,8 +249,7 @@ void publishSec()
|
||||
mqttClient.publish("/hometest/kuh1s/moroz", 1, false, strFVal);
|
||||
itoa(crun, strFVal, 10);
|
||||
mqttClient.publish("/hometest/kuh1s/millis", 1, false, strFVal);
|
||||
digitalWrite(GREEN, LOW);
|
||||
//}
|
||||
digitalWrite(GREEN, LOW);*/
|
||||
}
|
||||
|
||||
void publishMin()
|
||||
@@ -263,10 +271,10 @@ void publishMin()
|
||||
dtostrf(press, 6, 1, strFVal);
|
||||
mqttClient.publish("/home/kuh/pressure", 1, false, strFVal);
|
||||
}
|
||||
itoa(lightSP, strFVal, 10);
|
||||
mqttClient.publish("/home/kuh/light_sp", 1, false, strFVal);
|
||||
itoa(lightDB, strFVal, 10);
|
||||
mqttClient.publish("/home/kuh/light_db", 1, false, strFVal);
|
||||
//itoa(lightSP, strFVal, 10);
|
||||
//mqttClient.publish("/home/kuh/light_sp", 1, false, strFVal);
|
||||
//itoa(lightDB, strFVal, 10);
|
||||
//mqttClient.publish("/home/kuh/light_db", 1, false, strFVal);
|
||||
itoa(adc, strFVal, 10);
|
||||
mqttClient.publish("/home/kuh/light_cur", 1, false, strFVal);
|
||||
if(!isnan(tempHol)){
|
||||
@@ -346,8 +354,10 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
|
||||
void onMqttConnect(bool sessionPresent) {
|
||||
char v[6];
|
||||
itoa(lightData.SP, v, 10);
|
||||
mqttClient.publish("/home/kuh/light_sp", 1, false, v);
|
||||
mqttClient.publish("/home/kuh/light_sp_set", 1, false, v);
|
||||
itoa(lightData.DB, v, 10);
|
||||
mqttClient.publish("/home/kuh/light_db", 1, false, v);
|
||||
mqttClient.publish("/home/kuh/light_db_set", 1, false, v);
|
||||
mqttClient.publish("/home/kuh/move", 1, false, mv == 1 ? "1" : "0");
|
||||
mqttClient.subscribe("/home/kuh/light_sp_set", 1);
|
||||
@@ -364,13 +374,18 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
|
||||
|
||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||
bool w = false;
|
||||
char v[6];
|
||||
if(strcmp(topic, "/home/kuh/light_sp_set") == 0){
|
||||
lightSP = atoi(payload);
|
||||
w = true;
|
||||
itoa(lightData.SP, v, 10);
|
||||
mqttClient.publish("/home/kuh/light_sp", 1, false, v);
|
||||
}
|
||||
if(strcmp(topic, "/home/kuh/light_db_set") == 0){
|
||||
lightDB = atoi(payload);
|
||||
w = true;
|
||||
itoa(lightData.DB, v, 10);
|
||||
mqttClient.publish("/home/kuh/light_db", 1, false, v);
|
||||
}
|
||||
if(w){
|
||||
lightData.SP = lightSP;
|
||||
|
||||
Reference in New Issue
Block a user