#include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/gpio.h" #include "esp32/rom/ets_sys.h" #include "esp_log.h" #include "ds18b20.h" #include "config.h" #include "readTemps.h" #include "mqtt.h" #ifdef ENABLE_DS18B20 /* #define MAX_NO_OF_SENSORS 1 // This section is for finding out which address that the sensors on the bus has. DeviceAddress tempSensors[MAX_NO_OF_SENSORS]; int getTempAddresses(DeviceAddress *tsa) { unsigned int i = 0; reset_search(); while (search(tsa[i],true)) { ESP_LOGI("READ_TEMP", "Found a temp sensor. Address:"); ESP_LOG_BUFFER_HEX_LEVEL("READ_TEMP", &tsa[i][0], 8, ESP_LOG_INFO); i++; } return i; }*/ void readTemps() { char txt[10]; static bool initDone = false; const uint8_t intTempAddressBytes[8]={0x28,0x41,0x2e,0x7b,0x0d,0x00,0x00,0x2a}; // Address of the internal DeviceAddress *intTempSensorAdr = (DeviceAddress *) intTempAddressBytes; if( initDone == false ) { ESP_LOGI("READ_TEMP", "Init of readTemps"); ds18b20_init(ONE_WIRE_BUS_IO); //ESP_LOGI("READ_TEMP", "getTempAddresses()"); //const int noOfSensors = getTempAddresses(tempSensors); //ds18b20_setResolution(tempSensors,noOfSensors,10); ds18b20_setResolution(intTempSensorAdr,1,10); initDone = true; } ds18b20_requestTemperatures(); float int_temp = ds18b20_getTempC(intTempSensorAdr); ESP_LOGI("READ_TEMPS","Internal temp: %.1f",int_temp); #ifdef MQTT_ENABLED sprintf(txt,"%.1f",int_temp); sendMQTTMessage("basement/boiler/controllerTemp", txt); #endif } #endif