Bosch-Tronic-TR1000-4T Мanagement ESP8266

by nilnull in Workshop > Repair

583 Views, 0 Favorites, 0 Comments

Bosch-Tronic-TR1000-4T Мanagement ESP8266

IMG_20230222_181549.jpg
IMG_20230222_181611.jpg
IMG_20221230_160422.jpg
IMG_20221230_160410.jpg
IMG_20221230_154636.jpg
IMG_20221222_192455.jpg

The boiler is 3.5KW and is only suitable for washing hands. The control is via a mechanical diaphragm that presses a key. The pipe that carries the water to the diaphragm was blocked and the boiler never started. I decided to make a control system with an Arduino. First, I widened the inlet pipe of the boiler with a drill. There was some obstruction somewhere, and it no longer made sense to actuate the diaphragm and reduce the flow rate. I installed a water flow sensor at the outlet. I detect when the water triggers the sensor and monitor that at least 200 milliseconds have passed between two sensor activations. If ((currentMillis - lastEvent) < 200), then I close the relay (Solid State Relay). The values were achieved by trial and error. It is also possible to monitor the outgoing flow in the same way and regulate it. Protection: The boiler itself has thermal protection, but I could not get it to work even after my brutal tests.

1. I attached a temperature sensor to the heating element from the outside. Through experiments, I learned that it is good to stop the heater above 80 degrees. 

2. I installed a safety relief valve on the incoming pipe in case something goes wrong and the pipes don't burst. I decided to add it because it doesn't cost much. 

3. The Solid State Relay 20A generates a lot of heat, so it's a good idea to put a radiator on it. It occurred to me to report when the boiler is working. I already had a system for tracking how much each appliance works in the house and how much electricity it consumes, so I connected the boiler to it.

Supplies

IMG_20221222_192503.jpg
IMG_20221231_182930.jpg

Arduino Code

#include <ESP8266WiFi.h>
#include <Arduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <SPI.h>
#include <NTPClient.h>
#include <DNSServer.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
include <ESPAsyncTCP.h>
#endif
#include "ESPAsyncWebServer.h"
extern "C"
{
#include <osapi.h>
#include <os_type.h>
}

#include "config.h"
const int hallPin = D2;
const int switchPin = D5;
// Data wire is plugged into port D2 on the ESP8266
#define ONE_WIRE_BUS D4
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// variable to hold device addresses
DeviceAddress Thermometer;

const char *ssid = "ssid";
const char *password = "password";
const char *server_my = "your domain service";

float temperature = 0;
long currentMillis = 0;
long countPowerOn = 0;
long lastPowerOn = 0;
long lastEvent = 0;
int send_data = 0;
int state = 1;
int count = 0;
int lastCount = 0;
int period = 0;
long intervalTransmitWeather = 30;
int OnOff = 0;
unsigned long previousMillisWiFi = 0;
unsigned long intervalReconnect = 30000;
long ItervalReset = 240; // 4 hours = 240 minutes ;
int terminateTemperature = 80;
IPAddress ip;
String dns;
String gateway_ip;
int32_t dBm;

AsyncWebServer server(80);

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600 * 2, 60000);
const char *PARAM_MESSAGE = "message";

void reconnectWiFi()
{
 if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillisWiFi >= intervalReconnect))
 {
  Serial.print(millis());
  Serial.println("");
  Serial.println("Reconnecting to WiFi...");
  Serial.println("");
  WiFi.disconnect();
  WiFi.begin(ssid, password);
  previousMillisWiFi = currentMillis;
 }
}
void notFound(AsyncWebServerRequest *request)
{
 request->send(404, "text/plain", "Not found");
}

void setup()
{
 Serial.begin(9600);
 pinMode(switchPin, OUTPUT);
 pinMode(hallPin, INPUT_PULLUP);
 attachInterrupt(digitalPinToInterrupt(hallPin), isr, FALLING);
 Serial.print("\t OK ");
 sensors.begin();
 delay(10);
 WiFi.mode(WIFI_STA);
 WiFi.begin(ssid, password);
 if (WiFi.waitForConnectResult() != WL_CONNECTED)
 {
  Serial.println("WiFi Failed!");
  return;
 }
 Serial.println();
 Serial.print("IP Address: ");
 Serial.println(WiFi.localIP());
 ip = WiFi.localIP();
 dns = WiFi.dnsIP().toString();
 gateway_ip = WiFi.gatewayIP().toString();
 dBm = WiFi.RSSI();
 //------------ server ----------------------------
 server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
      {
   AsyncResponseStream *response = request->beginResponseStream("text/html");
   response->print("<!DOCTYPE html><html><head><title>Bosch Tronic TR1000 4T</title>");
   response->print("<link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css' integrity='sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z' crossorigin='anonymous'>");
   response->print("</head><body id='Bosch Tronic TR1000 4T'>");
   response->print("<script src='https://code.jquery.com/jquery-3.5.1.slim.min.js' integrity='sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj' crossorigin='anonymous'></script>");
   response->print("<script src='https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js' integrity='sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN' crossorigin='anonymous'></script>");
   response->print("<H1>Bosch Tronic TR1000 4T</H1>");
   response->print("<div class='container-fluid'>");
   response->print(getState().c_str());
   response->print("<hr>");
   response->print("<a href='getLastEvent'class='btn btn-outline-secondary'>get last event</a>");
   response->print("</p>");
   response->print("</div>");
   response->print("</body></html>");
   request->send(response); });
 server.on("/getLastEvent", HTTP_GET, [](AsyncWebServerRequest *request)
      { request->send_P(200, "text/plain", getLastEvent().c_str()); });
 server.on("/getWiFi", HTTP_GET, [](AsyncWebServerRequest *request)
      { request->send_P(200, "text/plain", getWiFi().c_str()); });
 server.onNotFound(notFound);
 server.begin();
 period = millis();
}
ICACHE_RAM_ATTR void isr()
{
 count++;
 lastEvent = currentMillis;
}


void loop()
{
 currentMillis = millis();
 timeClient.update();
 getTemperature();
 long targetResetTime = calcTimeStop(0, ItervalReset); // convert to milliseconds

 if ((currentMillis - lastEvent) < 200)
 {
  setStart();
  lastCount = count;
 }
 else
 {
  setStop();
 }

 if (temperature >= terminateTemperature)
 {
  setStop();
 }

 if (currentMillis >= targetResetTime)
 {
  Serial.println("RESTART");
  setStop();
  setRestart();
 }
}


String setStart()
{
 // Serial.println("START setStart");
 countPowerOn = (countPowerOn + (currentMillis - lastPowerOn));
 lastPowerOn = currentMillis;
 OnOff = 1;
 digitalWrite(switchPin, HIGH);
 return String(OnOff);
}


String setStop()
{
 // Serial.println("Stop setStop");
 OnOff = 0;
 digitalWrite(switchPin, LOW);
 return String(OnOff);
}

String setRestart()
{
 sendInput();
 Serial.println("::::::::::Restart::::::::::::");
 ESP.restart();
 return String('Restart');
}

String getState()
{
 String Switch = "off";
 if (OnOff == 1)
 {
  Switch = "on";
 }
 else
 {
  Switch = "off";
 }

 String mess = "";
 mess += "<p>Local Time: ";
 mess += String(getMayTime());
 mess += "</p>";
 mess += "<p>DNS IP: ";
 mess += dns;
 mess += "</p>";
 mess += "<p>Gateway IP: ";
 mess += gateway_ip;
 mess += "</p>";
 mess += "<p>Power WIFi: ";
 mess += dBm;
 mess += " dBm</p>";
 mess += "<p>The time of work: ";
 mess += Serial.println(countPowerOn / 1000);
 mess += "min</p>";
 mess += "<p>Switch: ";
 mess += Switch;
 mess += "</p>";
 mess += "<p>Temperature: ";
 mess += temperature;
 mess += "</p>";
return String(mess);
}

int calcTimeStop(long currentMillis, int periodMinute)
{
 const unsigned long oneSecond = 1000; // the value is a number of milliseconds, ie 1 second
 long rz = currentMillis + (oneSecond * (periodMinute * 60));
 return rz;
}

String getLastEvent()
{
 if (lastEvent != 0)
 {
  return String((currentMillis - lastEvent) / 1000);
 }
 return String("-");
}
int sendInput()
{
 WiFiClient client;
 if (client.connect(server_my, 80))
 {
  String log_endTime = getMayTime();
  String postStr = "device=8"; // 8 -Bosch Tronic TR1000 4T
  postStr += "&update=1";
  postStr += "&ip=";
  postStr += String(ip.toString());
  postStr += "&countPowerOnMS=";
  postStr += String(countPowerOn);
  postStr += "&log_endTime=";
  postStr += String(log_endTime);
  Serial.println(postStr);
  client.print(String("GET /update.php?" + postStr) + " HTTP/1.1\r\n" +
         "Host: " + server_my + "\r\n" +
         "Connection: close\r\n\r\n");
  delay(10);
 }
 countPowerOn = 0;
 client.stop();
 return true;
}

String getMayTime()
{
 timeClient.update();
 time_t epochTime = timeClient.getEpochTime();
 struct tm *ptm = gmtime((time_t *)&epochTime);

 String monthDay = ptm->tm_mday < 10 ? "0" + String(ptm->tm_mday) : String(ptm->tm_mday);
 String currentMonth = ptm->tm_mon + 1 < 10 ? "0" + String(ptm->tm_mon + 1) : String(ptm->tm_mon + 1);
 String currentYear = String(ptm->tm_year + 1900);
 String time = String(timeClient.getFormattedTime());
 String date = currentYear + "-" + currentMonth + "-" + monthDay + " " + time;
 Serial.print("Date: ");
 Serial.println(date);
 return date;
}

float getTemperature()
{
 sensors.requestTemperatures();
 temperature = sensors.getTempCByIndex(0);
 return temperature;
}

String getWiFi()
{
 return String(dBm);
}