readTemps.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "freertos/FreeRTOS.h"
  2. #include "freertos/task.h"
  3. #include "driver/gpio.h"
  4. #include "esp32/rom/ets_sys.h"
  5. #include "esp_log.h"
  6. #include "ds18b20.h"
  7. #include "config.h"
  8. #include "readTemps.h"
  9. #include "mqtt.h"
  10. #ifdef ENABLE_DS18B20
  11. /*
  12. #define MAX_NO_OF_SENSORS 1
  13. // This section is for finding out which address that the sensors on the bus has.
  14. DeviceAddress tempSensors[MAX_NO_OF_SENSORS];
  15. int getTempAddresses(DeviceAddress *tsa) {
  16. unsigned int i = 0;
  17. reset_search();
  18. while (search(tsa[i],true)) {
  19. ESP_LOGI("READ_TEMP", "Found a temp sensor. Address:");
  20. ESP_LOG_BUFFER_HEX_LEVEL("READ_TEMP", &tsa[i][0], 8, ESP_LOG_INFO);
  21. i++;
  22. }
  23. return i;
  24. }*/
  25. void readTemps() {
  26. char txt[10];
  27. static bool initDone = false;
  28. const uint8_t intTempAddressBytes[8]={0x28,0x41,0x2e,0x7b,0x0d,0x00,0x00,0x2a}; // Address of the internal
  29. DeviceAddress *intTempSensorAdr = (DeviceAddress *) intTempAddressBytes;
  30. if( initDone == false ) {
  31. ESP_LOGI("READ_TEMP", "Init of readTemps");
  32. ds18b20_init(ONE_WIRE_BUS_IO);
  33. //ESP_LOGI("READ_TEMP", "getTempAddresses()");
  34. //const int noOfSensors = getTempAddresses(tempSensors);
  35. //ds18b20_setResolution(tempSensors,noOfSensors,10);
  36. ds18b20_setResolution(intTempSensorAdr,1,10);
  37. initDone = true;
  38. }
  39. ds18b20_requestTemperatures();
  40. float int_temp = ds18b20_getTempC(intTempSensorAdr);
  41. ESP_LOGI("READ_TEMPS","Internal temp: %.1f",int_temp);
  42. #ifdef MQTT_ENABLED
  43. sprintf(txt,"%.1f",int_temp);
  44. sendMQTTMessage("basement/boiler/controllerTemp", txt);
  45. #endif
  46. }
  47. #endif