///////////////////// // Domoticz Classe ///////////////////// #include "Domoticz.h" Domoticz domo("192.168.1.3", "81", "Livebox-37cc", "8A6060920A8A86896F770F2C47"); IPAddress gateway(192, 168, 1, 1); IPAddress subnet(255, 255, 0, 0); IPAddress DNS(192, 168, 1, 1); // which analog pin to connect #define THERMISTORPIN A0 // resistance at 25 degrees C #define THERMISTORNOMINAL 9800 // temp. for nominal resistance (almost always 25 C) #define TEMPERATURENOMINAL 25 // how many samples to take and average, more takes longer // but is more 'smooth' #define NUMSAMPLES 5 // The beta coefficient of the thermistor (usually 3000-4000) #define BCOEFFICIENT 3950 // the value of the 'other' resistor #define SERIESRESISTOR 4800 uint16_t samples[NUMSAMPLES]; void setup() { Serial.begin(9600); //delay(200); String macId = domo.generateKey(); IPAddress ip = domo.getIP(macId); // Conversion d'objet en pointeur domo.initWifiStatic(ip, gateway, subnet, DNS); } void loop() { uint8_t i; float average; // take N samples in a row, with a slight delay for (i=0; i< NUMSAMPLES; i++) { samples[i] = analogRead(THERMISTORPIN); delay(10); } // average all the samples out average = 0; for (i=0; i< NUMSAMPLES; i++) { average += samples[i]; } average /= NUMSAMPLES; Serial.print("Average analog reading "); Serial.println(average); // convert the value to resistance average = 1023 / average - 1; average = SERIESRESISTOR / average; Serial.print("Thermistor resistance "); Serial.println(average); float steinhart; steinhart = average / THERMISTORNOMINAL; // (R/Ro) steinhart = log(steinhart); // ln(R/Ro) steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro) steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To) steinhart = 1.0 / steinhart; // Invert steinhart -= 273.15; // convert to C Serial.print("Temperature "); Serial.print(steinhart * 1.25); Serial.println(" *C"); printInfo(steinhart * 1.25); sleep(300); //delay(5000); } void sleep(int sleepTime) { Serial.print("Go to sleep "); Serial.println(sleepTime); delay(20); ESP.deepSleep(sleepTime * 1000000L); //sleepWifi(); delay(200); } void printInfo(double temperature) { // Domoticz format /json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT;BAR;BAR_FOR boolean connected = domo.connect(); if (connected) { Serial.println("Dans set temperature"); String svalue = String(temperature) ; Serial.println(svalue); domo.executeJson("/json.htm?type=command¶m=udevice&idx=1139", svalue, "0"); domo._client.stop(); delay(200); } Serial.print("Time = "); Serial.println(millis()); delay(200); }