/* // // version nodemcu 2020 01 12 // https://randomnerdtutorials.com/esp8266-ds18b20-temperature-sensor-web-server-with-arduino-ide/ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! my nodeMCU use ESP8266 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ADDED * /home/luc/arduino-1.8.9/hardware/tools/avr/avr/include/avr/pgmspace.h * /home/luc/Dropbox/arduino_ino/libraries/OneWire/OneWire.h * * * * * warning: 'bool HTTPClient::begin(String)' is deprecated (declared at /home/luc/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/libraries/ ESP8266HTTPClient/src/ESP8266HTTPClient.h:155) [-Wdeprecated-declarations] * * https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/readme.html#enable-wi-fi-diagnostic https://makeradvisor.com/esp32-vs-esp8266/ * */ //______________________________________________________________________ const char FileName[]="=> V 147 DifferentialTemp_nodeMCU03-SRV.ino ======"; //______________________________________________________________________ #include #include #include //#include // // official arduino //https://randomnerdtutorials.com/esp32-esp8266-input-data-html-form/#more-88796 // // is Jonas Ekstrand. #include #ifdef ESP32 #include #include #include #else //my nodemcu with ESP8266 #include #include #include #include #endif #include // my nodemcu with ESP8266 //https://techtutorialsx.com/2017/12/01/esp32-arduino-asynchronous-http-webserver/ #include /////////////////////////////////////////////////////////// //set relay output wire #define RELAY_ON D5 // 14 // D5 GPIO14 relayboard in1 #define RELAY_FAST D6 // 12 // D6 GPIO12 relayboard in2 #define ENABLE LOW //relay is reverse logic: active on low #define DISABLED HIGH /////////////////////////////////////////////////////////// // led #define LED_ON 0 #define LED_OFF 1 //status led : ON if auto mode #define pinled LED_BUILTIN // D0 ; // GPIO16 ; /////////////////////////////////////////////////////////// // button // https://www.baldengineer.com/detect-short-long-button-press.html #define PRESSED LOW #define NOT_PRESSED HIGH const unsigned long shortPress = 50; const unsigned long longPress = 500; typedef struct Buttons { const byte pin = D1 ; // D1 =GPIO5 const int debounce = 20; unsigned long counter=0; bool prevState = NOT_PRESSED; bool currentState; } Button; Button button; // // https://randomnerdtutorials.com/esp32-esp8266-input-data-html-form/#more-88796 // #if defined(ESP8266) // my NodeMCU use this //ESP8266WebServer server(80); AsyncWebServer server(80); #endif #if defined(ESP32) WebServer server(80); #endif /////////////////////////////////////////////////////////// // temperature sensors #define TEMPERATURE_PRECISION 12 //9..12 #define ONE_WIRE_BUS 4 // D2 = GPIO4 Data wire ONE_WIRE_BUS // arrays to hold device addresses #define iMaxCntDev 2 //max devs expected. limit mem used real count will be in byte iCntDev ; //physical dev count DeviceAddress probes[iMaxCntDev]; // table holding dev adress float probeTemp[iMaxCntDev]; // table holding measures OneWire myOneWireDev(ONE_WIRE_BUS);// Setup a myOneWireDev instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature mySensors(&myOneWireDev);// Pass our myOneWireDev reference to Dallas Temperature. /////////////////////////////////////////////////////////// // wifi char ssid[] = "BRG-FLOOR0-2G"; // your network SSID (name) "BRG-FLOOR0-2G" "BRG-FLOOR0-TPLINK" char password[] = "0499185306"; // your network password const char* PARAM_idelayMeasures = "idelayMeasures"; const char* PARAM_idelayRelays = "idelayRelays"; const char* PARAM_idelaySendData = "idelaySendData"; const char* PARAM_idelayResetMaxDelta = "idelayResetMaxDelta"; const char* PARAM_TempFanSLOW = "TempFanSLOW"; const char* PARAM_TempFanFAST = "TempFanFAST"; const char* PARAM_mode = "mode"; const char* PARAM_state = "state"; String GETdata ; //will contains line send to server char sysinfo[255] ; // line with parameter, filled by prttomon() byte cntry ; /* * function submitMessage() { alert("Saved value to ESP SPIFFS"); setTimeout(function(){ document.location.reload(false); }, 500); * */ const char index_html[] PROGMEM = R"rawliteral( Vertical Circulator Parameters
Temp up
%temp01%
Temp down
%temp02%
Delta
%delta%

idelayMeasures (Current value= %idelayMeasures%):

idelayRelays (Current value= %idelayRelays%):

idelaySendData (Current value= %idelaySendData%):

idelayResetMaxDelta (Current value= %idelayResetMaxDelta%):

TempFanSLOW (Current value= %TempFanSLOW%):

TempFanFAST (Current value= %TempFanFAST%):

State (1:Auto) (Currentvalue= %state%):

Mode (0:AUTO, 1:FanSLOW, 2:FanFAST, 3:FanOFF) (Current value= %mode%):
)rawliteral"; // // 172
// http://192.168.0.22/get?TempFanFAST=6.6 // but page does not show all //______________________________________________________________________ bool bFastON; //set true if FastOn, lock to avoid useless switch bool Op_StateAUTO= true; // auto: true , man: false // 0 (nu), 1 FanSLOW, 2 FanFast, 3 FanOFF byte Op_Mode = 0 ; // 0 (nu), 1 FanSLOW, 2 FanFast, 3 FanOFF unsigned long previousCPdelayMeasures=0 ; // to avoid millis rollover unsigned long previousCPdelayRelays=0 ; // to avoid millis rollover unsigned long previousCPdelaySendData=0 ; // to avoid millis rollover unsigned long previousCPdelayResetMaxDelta=0 ; // to avoid millis rollover float TempDelta ; float maxDelta = 0; //______________________________________________________________________ //parameters .. //______________________________________________________________________ /* 0 ...........|.................|................ delta temp | | Limits TempFanSLOW TempFanFAST Fan: OFF | SLOW | FAST | | */ float TempFanSLOW_def = 5.01 ; //limit start delta fan normal (capacitor limited) speed float TempFanFAST_def = 7.01; //limit start fan fast long int idelayMeasures_def = 30000 ; // def val long int idelayRelays_def = 70000 ; // relays cntrl long int idelaySendData_def = 10000 ; // send data 10 sec long int idelayResetMaxDelta_def =300000 ; // 5 mins 1800000 ; // 30 mins // reset max delta bool Op_StateAUTO_def= true; // auto: true , man: false // 0 (nu), 1 FanSLOW, 2 FanFast, 3 FanOFF byte Op_Mode_def = 0 ; // 0 (nu), 1 FanSLOW, 2 FanFast, 3 FanOFF float TempFanSLOW ; float TempFanFAST ; long int idelayMeasures ; long int idelayRelays ; long int idelaySendData ; long int idelayResetMaxDelta; //========================== void notFound(AsyncWebServerRequest *request) { request->send(404, "text/plain", "Not found"); } //========================== //______________________________________________________________________ void setup(void) { byte i ; Serial.begin(115200); // start serial port pinMode(pinled, OUTPUT); pinMode(button.pin, INPUT_PULLUP); delay(1000); Serial.println(""); Serial.println(FileName); #ifdef ESP32 // Initialize SPIFFS if(!SPIFFS.begin(true)){ Serial.println("An Error has occurred while mounting SPIFFS"); return; } #else // ESP8266 if(!SPIFFS.begin()){ Serial.println("An Error has occurred while mounting SPIFFS"); return; } #endif Serial.println(">>>InitWifiCx"); InitWifiCx(); Serial.println(">>>InitParams"); InitParams(); Serial.println(">>>MonParams"); MonParams(); pinMode(RELAY_ON, OUTPUT); // set relays out pins pinMode(RELAY_FAST, OUTPUT); digitalWrite(RELAY_ON, DISABLED); // relay to off digitalWrite(RELAY_FAST, DISABLED); mySensors.begin(); // Start up the sensor library iCntDev=mySensors.getDeviceCount(); // locate devices on the bus Serial.print(F("Locating devices...")); Serial.print(F("Found ")); Serial.print(iCntDev, DEC); Serial.println(" devices."); Serial.print(F("Set to maximum "));Serial.print(iMaxCntDev, DEC); Serial.println(" devices ! (See iMaxCntDev)"); Serial.print(F("ONE_WIRE_BUS bus on pin "));Serial.print(ONE_WIRE_BUS, DEC); Serial.println(""); Serial.print(F("Parasite power is: "));// report parasite power requirements if (mySensors.isParasitePowerMode()) Serial.println("ON"); else Serial.println("OFF"); for( i = 0 ; i < iCntDev; i++){ // print infos for each device if (!mySensors.getAddress(probes[i], i)) Serial.println("Unable to find address for Device "); Serial.print(F("Device ")); Serial.print(i); Serial.print(F(", address: ")); printAddress(probes[i]); // set the resolution to 12 bit per device mySensors.setResolution(probes[i], TEMPERATURE_PRECISION); Serial.print(F(", resolution: ")); int res = mySensors.getResolution(probes[i]); Serial.print(res, DEC); Serial.println(); } GetTemps(); PrtDataToMon(); DriveRelays(); Serial.println(" ============ End setup()"); } //end setup(void) //______________________________________________________________________ void loop(void){ unsigned long CPdelayMeasures = millis(); unsigned long CPdelayRelays = millis(); unsigned long CPdelaySendData = millis(); unsigned long CPdelayResetMaxDelta = millis(); keysacn(); if ((unsigned long)(CPdelayMeasures - previousCPdelayMeasures) >= idelayMeasures) { Serial.print(F("1.Every ")); Serial.println(idelayMeasures/1000); GetTemps(); //get t° and fill maxDelta, TempDelta //PrtDataToMon(); previousCPdelayMeasures=CPdelayMeasures; } if ((unsigned long)(CPdelayRelays - previousCPdelayRelays) >= idelayRelays) { Serial.print(F("2.Every ")); Serial.println(idelayRelays/1000); DriveRelays(); SendData(); previousCPdelayRelays=CPdelayRelays; } if ((unsigned long)(CPdelaySendData - previousCPdelaySendData) >= idelaySendData) { Serial.print(F("3.Every ")); Serial.println(idelaySendData/1000); SendData(); PrtDataToMon(); previousCPdelaySendData=CPdelaySendData; } if ((unsigned long)(CPdelayResetMaxDelta - previousCPdelayResetMaxDelta) >= idelayResetMaxDelta) { Serial.print(F("4.Every ")); Serial.println(idelayResetMaxDelta/1000); maxDelta = 0; previousCPdelayResetMaxDelta=CPdelayResetMaxDelta; } } //______________________________________________________________________ void GetTemps(){ //get t° and fill maxDelta, TempDelta mySensors.requestTemperatures(); for(byte i = 0 ; i < iCntDev; i++){ //The loop that goes through the sensors float fMes ; //Serial.print(F("Device ")); Serial.print(i); //Serial.print(F(", ")); printAddress(probes[i]); //Serial.print(F(": ")); probeTemp[i] = printTemperature(probes[i]) ; //Serial.print(fMes); //Serial.println(" °C "); } //for loop if (probeTemp[0]>probeTemp[1]) {TempDelta=(probeTemp[0]-probeTemp[1]);}else{TempDelta=(probeTemp[1]-probeTemp[0]); } if (TempDelta>maxDelta ){ maxDelta=TempDelta;} } //______________________________________________________________________ void DriveRelays(){ //drive relays // replace call proc by mode and state ? if (Op_StateAUTO) { // 0 auto, 1 man // AUTO //if (Op_StateAUTO) { Serial.print(F(" MAN")); else { Serial.print(F(" AUTO")); } digitalWrite(pinled,LED_OFF); if (TempDelta > TempFanFAST){Op_Mode=2; FanFAST(); } else if (TempDelta > TempFanSLOW){ Op_Mode=1;FanSLOW(); } else if (TempDelta <= TempFanSLOW){Op_Mode=3 ; FanOFF(); } } else { // MAN digitalWrite(pinled,LED_ON); switch(Op_Mode) {// Op_StateAUTO 0 ignore 1 FanSLOW, 2 FanFast 3 FanOFF case 0 : break; case 1 : Op_Mode=1;FanSLOW();break; case 2 : Op_Mode=2;FanFAST();break; case 3 : Op_Mode=3;FanOFF(); break; } } } // DriveRelays //______________________________________________________________________ void SendData(){ //send data via index.php float fMes0,fMes1; String Link, getData ; HTTPClient http; //Declare object of class HTTPClient // build a HTTP request if (WiFi.status() == WL_CONNECTED) { fMes0=probeTemp[0] ; fMes1=probeTemp[1] ; // String GETdata="GET /esp8266/index.php/?t0=" + String(fMes0) GETdata="?t0=" + String(fMes0) + "&t1="+ fMes1 + "&TD="+ String(TempDelta) + "&mTD="+ String(maxDelta) + "&Md="+ String(Op_Mode ) //+ "&St="+ sState + "&St="+ String(Op_StateAUTO) + "&ti="+ millis(); + " HTTP/1.1"; //echo to sermon Link = "http://192.168.0.11/esp8266/index.php" + GETdata; Serial.print(F("===> GETdata: ")); Serial.println(Link); http.begin(Link); //Specify request destination int httpCode = http.GET(); //Send the request Serial.println("=response"); String payload = http.getString(); //Get the response payload Serial.println(httpCode); //Print HTTP return code Serial.println(payload); //Print request response payload Serial.println("=end response"); http.end(); //Close connection } else { Serial.println("WiFiStatus != WL_CONNECTED"); } } //______________________________________________________________________ void PrtDataToMon(){ // void PrtDataToMon(|sysinfo){ // Typical : // // (Limits: ON >5.10, FAST >6.30) Delta: 7.12 (max: 7.19), State AUTO, Mode 2 FAST // Device 0, 2888DA7997040306: 24.44 °C // Device 1, 286E6D4692020290: 17.31 °C // #include // #include // String PrtDataToMon(){ // write line to sysinfo ? // replace serial.print with output of strcat ? /* char* dtostrf (double __val, signed char __width, unsigned char __prec, char * __s) http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html __val : la valeur en flottant à convertir __width : taille totale de ton buffer en comptant le signe - et le point décimal, ici 1 (signe) + 3 + 1 (point) + 2 + 1 (\0 de fin de chaine) = 8 __prec : nombre de chiffre après la virgule, ici 2 __s : le buffer à utiliser */ //char s[25]; //temp buffer Serial.print(F("(Limits: ON >"));Serial.print(TempFanSLOW);Serial.print(F(", FAST >")); Serial.print(TempFanFAST);Serial.print(")"); Serial.print(F(" Delta: "));Serial.print(TempDelta);Serial.print(F(" (max: "));Serial.print(maxDelta);Serial.print(F(")")); /* strcpy(sysinfo," Delta: "); dtostrf(TempDelta, 5, 2, s); strcat(sysinfo, s); strcpy(sysinfo," (max: "); dtostrf(maxDelta, 5, 2, s); strcpy(sysinfo,")"); sprintf(" Delta: " ); */ Serial.print(F(", State ")); if (Op_StateAUTO) {Serial.print(F("AUTO"));} else {Serial.print(F("MAN"));} Serial.print(F(", Mode ")) ; Serial.print(Op_Mode); switch (Op_Mode) { //Op_Mode: 0 Auto, 1 FanSLOW, 2 FanFast, 3 FanOFF case 0: Serial.println(F(" -nu-")); break; case 1: Serial.println(F(" SLOW")); break; case 2: Serial.println(F(" FAST")); break; case 3: Serial.println(F(" OFF")); break; } //Serial.print(F("Last GETdata: ")); Serial.println(GETdata); for(byte i = 0 ; i < iCntDev; i++){ Serial.print(F("Device ")); Serial.print(i); Serial.print(F(", ")); printAddress(probes[i]); Serial.print(F(": ")); Serial.print(probeTemp[i]) ; Serial.println(" °C "); } // return full line ? } //______________________________________________________________________ void printAddress(DeviceAddress deviceAddress) { // function to print a device address for (uint8_t i = 0; i < 8; i++) { // zero pad the address if necessary if (deviceAddress[i] < 16) Serial.print(F("0")); Serial.print(deviceAddress[i], HEX); } } //______________________________________________________________________ float printTemperature(DeviceAddress deviceAddress) { // function to print the temperature for a device float tempC = mySensors.getTempC(deviceAddress); //Serial.print(tempC); //Serial.println(" °C "); return tempC; //Serial.print(" Temp F: "); //Serial.print(DallasTemperature::toFahrenheit(tempC)); } //______________________________________________________________________ void printResolution(DeviceAddress deviceAddress) { // function to print a device's resolution Serial.print("Resolution: "); Serial.print(mySensors.getResolution(deviceAddress)); Serial.println(); } //______________________________________________________________________ void printData(DeviceAddress deviceAddress) { // main function to print information about a device //Serial.print("Device Address: "); printAddress(deviceAddress); Serial.print(F(" ")); printTemperature(deviceAddress); Serial.println(); } //______________________________________________________________________ void keysacn(){ //https://www.baldengineer.com/detect-short-long-button-press.html // check the button button.currentState = digitalRead(button.pin); // has it changed? if (button.currentState != button.prevState) { delay(button.debounce); //Serial.println(F(" After debounce")); // update status in case of bounce button.currentState = digitalRead(button.pin); if (button.currentState == PRESSED) { // a new press event occured // record when button went down //Serial.println(F(" pressed")); button.counter = millis(); } if (button.currentState == NOT_PRESSED) { //Serial.println(F(" no longer pressed")); // but no longer pressed, how long was it down? unsigned long currentMillis = millis(); if ((currentMillis - button.counter >= shortPress) && !(currentMillis - button.counter >= longPress)) { // short press detected. handleShortPress(); } if ((currentMillis - button.counter >= longPress)) { // the long press was detected handleLongPress(); } } // used to detect when state changes button.prevState = button.currentState; } } //______________________________________________________________________ void handleShortPress() { // auto: false , man: true // 0 (nu), 1 FanSLOW, 2 FanFast, 3 FanOFF Serial.println(F(" >>> Short Press")); Op_Mode=Op_Mode+1; Serial.println(Op_Mode); if (Op_Mode==4) { // set AUTO Op_StateAUTO = true ; Op_Mode = 3; // off until measures } else { Op_StateAUTO = false ; } //GetTemps(); PrtDataToMon(); SendData(); DriveRelays(); } //______________________________________________________________________ void handleLongPress() { //set to auto, slow handleShortPress(); /* Serial.println(F(" >>> Long Press")); Op_StateAUTO=true ; Op_Mode = 1; PrtDataToMon(); SendData(); DriveRelays(); * */ } //______________________________________________________________________ void FanSLOW() {// relay is activated when DO is DISABLED LOW ! // fan low speed //Serial.println("FanSLOW"); bFastON=false; //Op_Mode =1 ; // when in auto: 0 ignore 1 FanSLOW, 2 FanFast 3 FanOFF digitalWrite(RELAY_ON, ENABLE); digitalWrite(RELAY_FAST, DISABLED); } //______________________________________________________________________ void FanFAST(){// relay is activated when DO is DISABLED ! // fan high speed //Serial.println("FanFAST"); if (!bFastON) { bFastON=true; //Op_Mode =2 ; // when in auto: 0 ignore 1 FanSLOW, 2 FanFast 3 FanOFF digitalWrite(RELAY_ON, DISABLED);//cut power delay(2000);//wait for discharge of limiting condo digitalWrite(RELAY_FAST, ENABLE);//bypass limiting condo digitalWrite(RELAY_ON, ENABLE);//power } } //______________________________________________________________________ void FanOFF() {// relay is activated when DO is DISABLED ! //fan off //Serial.println("FanOFF"); bFastON=false; //Op_Mode =3 ; // when in auto: 0 ignore 1 FanSLOW, 2 FanFast 3 FanOFF digitalWrite(RELAY_ON, DISABLED); delay(2000); //wait for discharge of limiting condo // TODO use millis ! digitalWrite(RELAY_FAST, DISABLED); } //______________________________________________________________________ void printWifiStatus(){ // print the SSID of the network you're attached to Serial.print(F("Connected to WiFi SSID: ")); Serial.print(WiFi.SSID()); Serial.print(F(", ip: ")); Serial.print(WiFi.localIP()); long rssi = WiFi.RSSI(); Serial.print(F(", signal (RSSI): ")); Serial.print(rssi); Serial.print(F(" dBm")); } //______________________________________________________________________ void InitWifiCx(){ WiFi.mode(WIFI_OFF); //Prevents reconnection issue (taking too long to connect) delay(1000); WiFi.mode(WIFI_STA); //This line hides the viewing of ESP as wifi hotspot WiFi.begin(ssid, password); Serial.println(""); // if (WiFi.waitForConnectResult() != WL_CONNECTED) { while(WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } // you're connected now, so print out the data Serial.println(""); printWifiStatus(); Serial.println(); // set server to response //code based on // https://techtutorialsx.com/2017/12/01/esp32-arduino-asynchronous-http-webserver/ // https://github.com/me-no-dev/ESPAsyncWebServer/blob/master/src/StringArray.h // // Send web page with input fields to client start server server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/html", index_html, processor); }); // Send a GET request to /get?inputString= server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) { String inputMessage; // GET inputInt value on /get?inputInt= // GET TempFanSLOW value on /get?TempFanSLOW= if (request->hasParam(PARAM_idelayMeasures)) { inputMessage = request->getParam(PARAM_idelayMeasures)->value(); writeFile(SPIFFS, "/idelayMeasures.txt", inputMessage.c_str()); idelayMeasures = atol(inputMessage.c_str()); } else if (request->hasParam(PARAM_idelayRelays)) { inputMessage = request->getParam(PARAM_idelayRelays)->value(); writeFile(SPIFFS, "/idelayRelays.txt", inputMessage.c_str()); idelayRelays = atol(inputMessage.c_str()); } else if (request->hasParam(PARAM_idelaySendData)) { inputMessage = request->getParam(PARAM_idelaySendData)->value(); writeFile(SPIFFS, "/idelaySendData.txt", inputMessage.c_str()); idelaySendData = atol(inputMessage.c_str()); } else if (request->hasParam(PARAM_idelayResetMaxDelta)) { inputMessage = request->getParam(PARAM_idelayResetMaxDelta)->value(); writeFile(SPIFFS, "/idelayResetMaxDelta.txt", inputMessage.c_str()); idelayResetMaxDelta= atol(inputMessage.c_str()); } else if (request->hasParam(PARAM_TempFanSLOW)) { inputMessage = request->getParam(PARAM_TempFanSLOW)->value(); writeFile(SPIFFS, "/TempFanSLOW.txt", inputMessage.c_str()); TempFanSLOW=(float)atof( inputMessage.c_str() ); } else if (request->hasParam(PARAM_TempFanFAST)) { inputMessage = request->getParam(PARAM_TempFanFAST)->value(); writeFile(SPIFFS, "/TempFanFAST.txt", inputMessage.c_str()); TempFanFAST=(float)atof( inputMessage.c_str() ); } //////// else if (request->hasParam(PARAM_state)) { // state is controlled by loop mode //inputMessage = request->getParam(PARAM_state)->value(); //writeFile(SPIFFS, "/state.txt", inputMessage.c_str()); //Op_StateAUTO=atol( inputMessage.c_str() ); } else if (request->hasParam(PARAM_mode)) { inputMessage = request->getParam(PARAM_mode)->value(); writeFile(SPIFFS, "/mode.txt", inputMessage.c_str()); //Op_Mode=atol( inputMessage.c_str() ); handleShortPress(); } else { inputMessage = "No message sent"; } Serial.println(inputMessage); request->send(200, "text/text", inputMessage); } ); // server.on( server.onNotFound(notFound); server.begin(); } //______________________________________________________________________ void printState(){ Serial.print("Op_StateAUTO=");Serial.println(Op_StateAUTO); Serial.print("Op_Mode=");Serial.println(Op_Mode); //Serial.println("loop but01_lock"); //Serial.print(F("ShortPress "));Serial.print(Op_Mode); //Serial.println(); } //______________________________________________________________________ String readFile(fs::FS &fs, const char * path){ //Serial.printf("readFile(): Reading file: %s\r\n", path); //Serial.printf("readFile(): Reading file: %s ", path); File file = fs.open(path, "r"); if(!file || file.isDirectory()){ //Serial.println("- empty file or failed to open file"); return String(); } //Serial.print("- read from file:"); String fileContent; while(file.available()){ fileContent+=String((char)file.read()); } //Serial.println(fileContent); return fileContent; } //______________________________________________________________________ void writeFile(fs::FS &fs, const char * path, const char * message){ Serial.printf("Writing file: %s\r\n", path); File file = fs.open(path, "w"); if(!file){ Serial.println("- failed to open file for writing"); return; } if(file.print(message)){ Serial.println("- file written"); } else { Serial.println("- write failed"); } } //______________________________________________________________________ String processor(const String& var){ // Replaces placeholder with stored values //pass param 'id' return value or null (?) Serial.println("==processor"); Serial.println(var); if(var == "idelayMeasures"){ return readFile(SPIFFS, "/idelayMeasures.txt"); } else if(var == "idelayRelays"){ return readFile(SPIFFS, "/idelayRelays.txt"); } else if(var == "idelaySendData"){ return readFile(SPIFFS, "/idelaySendData.txt"); } else if(var == "idelayResetMaxDelta"){ return readFile(SPIFFS, "/idelayResetMaxDelta.txt"); } else if(var == "TempFanSLOW"){ return readFile(SPIFFS, "/TempFanSLOW.txt"); } else if(var == "TempFanFAST"){ return readFile(SPIFFS, "/TempFanFAST.txt"); } else if(var == "temp01"){ return String((probeTemp[0])) ; } else if(var == "temp02"){ return String((probeTemp[1])) ; } else if(var == "state"){ //return readFile(SPIFFS, "/state.txt"); return String(Op_StateAUTO); } else if(var == "mode"){ //return readFile(SPIFFS, "/mode.txt"); return String(Op_Mode); } else if(var == "delta"){ //return readFile(SPIFFS, "/mode.txt"); return String(TempDelta); } /* else if(var == "sysinfos"){ // PrtDataToMon(); // return String(PrtDataToMon()); return String("To be done"); } * */ } //______________________________________________________________________ void InitParams(){ if (!readFile(SPIFFS, "/TempFanSLOW.txt").toFloat()){ TempFanSLOW = TempFanSLOW_def ; } else { TempFanSLOW = readFile(SPIFFS, "/TempFanSLOW.txt").toFloat(); } if (!readFile(SPIFFS, "/TempFanFAST.txt").toFloat()){ TempFanFAST = TempFanFAST_def ; } else { TempFanFAST = readFile(SPIFFS, "/TempFanFAST.txt").toFloat(); } if (readFile(SPIFFS, "/idelayMeasures.txt") == NULL) { idelayMeasures = idelayMeasures_def ; } else { idelayMeasures = readFile(SPIFFS, "/idelayMeasures.txt").toInt(); } if (!readFile(SPIFFS, "/idelayRelays.txt").toInt()){ idelayRelays = idelayRelays_def ; } else { idelayRelays = readFile(SPIFFS, "/idelayRelays.txt").toInt(); } if (!readFile(SPIFFS, "/idelaySendData.txt").toInt()){ idelaySendData = idelaySendData_def ; } else { idelaySendData = readFile(SPIFFS, "/idelaySendData.txt").toInt(); } if (!readFile(SPIFFS, "/idelayResetMaxDelta.txt").toInt()){ idelayResetMaxDelta = idelayResetMaxDelta_def ; } else { idelayResetMaxDelta = readFile(SPIFFS, "/idelayResetMaxDelta.txt").toInt(); } /* c'est le bordel .. * if (!readFile(SPIFFS, "/state.txt").toInt()){ state = Op_StateAUTO_def ; } else { state = readFile(SPIFFS, "/state.txt").toInt(); } if (!readFile(SPIFFS, "/mode.txt").toInt()){ mode = Op_Mode_def ; } else { mode = readFile(SPIFFS, "/mode.txt").toInt(); } */ } //______________________________________________________________________ void MonParams(){ Serial.println(" PARAMETERS :"); Serial.print(F("idelayMeasures ="));Serial.println(idelayMeasures/1000 ); Serial.print(F("idelayRelays ="));Serial.println( idelayRelays/1000 ); Serial.print(F("idelaySendData ="));Serial.println( idelaySendData/1000 ); Serial.print(F("idelayResetMaxDelta ="));Serial.println(idelayResetMaxDelta /1000 ); Serial.print(F("TempFanSLOW =")); Serial.println(TempFanSLOW) ; //limit start delta fan normal (capacitor limited) speed Serial.print(F("TempFanFAST =")); Serial.println(TempFanFAST) ; //limit start fan fast }