Hello,
I have a ESP32S controlling a simple water heater. I have a cloud variable that is the setpoint for the water temperature. I assigned a slider to that variable and also have current water temperatures as cloud sensors. The Arduino is online and responds to my google home commands to turn the heater on and off. But the Dashboard does not auto update anymore. For example The slider current value is 50, I slide it to 35. but the value doesnt update. I refresh the desktop Dashboard and the slider returns to 50 even though the dashboard loads the latest temperature sensors. Also the mobile app dashboard is no longer loading. If i select the "Live" function on the charts it doesnt update. I know this code is a little messy right now so please bear with me.
#include "arduino_secrets.h"
#include "thingProperties.h"
#include <WiFi.h>
#include <WiFiAP.h>
#include <WiFiClient.h>
#include <WiFiGeneric.h>
#include <WiFiMulti.h>
#include <WiFiSTA.h>
#include <WiFiScan.h>
#include <WiFiServer.h>
#include <WiFiType.h>
#include <WiFiUdp.h>
#include <dummy.h>
#include "MovingAverageFloat.h"
//Constants
const int WaterinPin = 34;
const int WaterOutPin = 35;
const int EnableHeaterPin = 17;
const char* ssid = "Norman-ATT-home_EXT Garage";
const char* password = "Iceland2017!";
WiFiServer server(80);
//Variables
float Waterin = 0;
float WaterOut = 0;
float scaleinputadc;
float scaleinputadcout;
float WaterinR2;
float WaterOutR2;
float Celciuswaterin = 0;
float Celciuswaterout = 0;
//float tubsetpoint = 40;
bool heateron;
MovingAverageFloat <16> simple_moving_average_IN;
MovingAverageFloat <16> simple_moving_average_OUT;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(115200);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
//Pin modes
pinMode(EnableHeaterPin, OUTPUT);
// Begin Commmunications
ArduinoCloud.printDebugInfo();
Serial.begin(115200);
delay(1000);
WiFi.begin(ssid, password);
// while wifi not connected yet, print '.'
// then after it connected, get out of the loop
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
//print a new line, then print WiFi connected and the IP address
Serial.println("");
Serial.println("WiFi connected");
// Print the IP address
Serial.println(WiFi.localIP());
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
ArduinoCloud.update();
// Your code here
// Scale and convert Pin 34 to Celcius. Logarithmic function based on experimental data.l
Waterin = analogRead(WaterinPin);
scaleinputadc = (Waterin / 4095)*3.30; //Inputvoltage on Water in pin
WaterinR2 = (scaleinputadc*10000)/(3.3-scaleinputadc);
Celciuswaterin = 678.6*pow(WaterinR2,-0.1257) - 185.8; //Changed to 185.8 on 12/2/24 from 165.8
WaterOut = analogRead(WaterOutPin);
scaleinputadcout = (WaterOut/4095)*3.30; //Inputvoltage on Water in pin
WaterOutR2 = (scaleinputadcout*10000)/(3.3-scaleinputadcout);
Celciuswaterout = 678.6*pow(WaterOutR2,-0.1257) - 185.8; //Changed to 185.8 on 12/2/24 from 165.8
simple_moving_average_IN.add(Celciuswaterin);
simple_moving_average_OUT.add(Celciuswaterout);
heater_WaterIn = simple_moving_average_IN.get();
heater_WaterOut = simple_moving_average_OUT.get();
delay(1000);
/*
Serial.print("Heater State ");
Serial.println(heater_Status);
Serial.print("Setpoint");
Serial.println(hotTubSetpoint);
Serial.print("Heater request ");
Serial.println(heater_Switch);
Serial.println(hotTubSetpoint-heater_WaterOut);
*/
hotTubSetpoint = hottubeSetpointRemote;
if((heater_Switch)&&(heater_WaterIn<hotTubSetpoint)&&((hotTubSetpoint-heater_WaterIn)>1)){
digitalWrite(EnableHeaterPin, HIGH);
}
else {
digitalWrite(EnableHeaterPin, LOW);
}
}
/*
Since HeaterSwitch is READ_WRITE variable, onHeaterSwitchChange() is
executed every time a new value is received from IoT Cloud.
*/
void onHeaterSwitchChange() {
if(heater_Switch){
digitalWrite(EnableHeaterPin, HIGH);
}
else {
digitalWrite(EnableHeaterPin, LOW);
}
heater_Status = digitalRead(EnableHeaterPin);
Serial.print("Heater request ");
Serial.println(heater_Switch);
Serial.print("Heater State ");
Serial.println(heater_Status);
}
/*
Since HotTubSetpoint is READ_WRITE variable, onHotTubSetpointChange() is
executed every time a new value is received from IoT Cloud.
*/
void onHotTubSetpointChange() {
// Add your code here to act upon HotTubSetpoint change
//tubsetpoint = hotTubSetpoint;
//hotTubSetpoint = tubsetpoint;
}
void onHeaterStatusChange() {
// Add your code here to act upon HeaterStatus change
}
void controlSetpoint(){
Serial.println("Low");
}
/*
Since HottubeSetpointRemote is READ_WRITE variable, onHottubeSetpointRemoteChange() is
executed every time a new value is received from IoT Cloud.
*/
void onHottubeSetpointRemoteChange() {
// Add your code here to act upon HottubeSetpointRemote change
hotTubSetpoint = hottubeSetpointRemote;
Serial.println("Delta");
Serial.println(hotTubSetpoint-heater_WaterOut);
Serial.println("Setpoint");
Serial.println(hotTubSetpoint);
Serial.println("water In");
Serial.println(heater_WaterIn);
Serial.println("water Out");
Serial.println(heater_WaterOut);
}