Procházet zdrojové kódy

Added read of a ds18b20 temp sensor.

Thomas Chef před 2 roky
rodič
revize
20e169c19b
8 změnil soubory, kde provedl 633 přidání a 4 odebrání
  1. 2 0
      main/CMakeLists.txt
  2. 3 0
      main/config.h
  3. 451 0
      main/ds18b20.c
  4. 84 0
      main/ds18b20.h
  5. 2 2
      main/kWhCounter.c
  6. 11 2
      main/main.c
  7. 72 0
      main/readTemps.c
  8. 8 0
      main/readTemps.h

+ 2 - 0
main/CMakeLists.txt

@@ -3,6 +3,8 @@ idf_component_register(SRCS
 "main.c"
 "wifi.c" "mqtt.c"
 "kWhCounter.c"
+"ds18b20.c"
+"readTemps.c"
 
 
 

+ 3 - 0
main/config.h

@@ -10,11 +10,14 @@
 #define HTTP_ENABLED
 #define MQTT_ENABLED
 #define ENABLE_KWH_COUNTER
+#define ENABLE_DS18B20
 
 #define VVB_RELAY_OUTPUT_IO      GPIO_NUM_22   // Output GPIO of a relay control of VVB
 
 #define KWH_COUNTER_INPUT_IO      GPIO_NUM_16   // Input
 
+#define ONE_WIRE_BUS_IO           GPIO_NUM_26   // Temp sensors
+
 
 
 

+ 451 - 0
main/ds18b20.c

@@ -0,0 +1,451 @@
+/*
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+    You should have received a copy of the GNU General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "driver/gpio.h"
+#include "esp32/rom/ets_sys.h"
+#include "ds18b20.h"
+#include "config.h"
+
+#ifdef ENABLE_DS18B20
+
+// OneWire commands
+#define GETTEMP			0x44  // Tells device to take a temperature reading and put it on the scratchpad
+#define SKIPROM			0xCC  // Command to address all devices on the bus
+#define SELECTDEVICE	0x55  // Command to address all devices on the bus
+#define COPYSCRATCH     0x48  // Copy scratchpad to EEPROM
+#define READSCRATCH     0xBE  // Read from scratchpad
+#define WRITESCRATCH    0x4E  // Write to scratchpad
+#define RECALLSCRATCH   0xB8  // Recall from EEPROM to scratchpad
+#define READPOWERSUPPLY 0xB4  // Determine if device needs parasite power
+#define ALARMSEARCH     0xEC  // Query bus for devices with an alarm condition
+// Scratchpad locations
+#define TEMP_LSB        0
+#define TEMP_MSB        1
+#define HIGH_ALARM_TEMP 2
+#define LOW_ALARM_TEMP  3
+#define CONFIGURATION   4
+#define INTERNAL_BYTE   5
+#define COUNT_REMAIN    6
+#define COUNT_PER_C     7
+#define SCRATCHPAD_CRC  8
+// DSROM FIELDS
+#define DSROM_FAMILY    0
+#define DSROM_CRC       7
+// Device resolution
+#define TEMP_9_BIT  0x1F //  9 bit
+#define TEMP_10_BIT 0x3F // 10 bit
+#define TEMP_11_BIT 0x5F // 11 bit
+#define TEMP_12_BIT 0x7F // 12 bit
+
+uint8_t DS_GPIO;
+uint8_t init=0;
+uint8_t bitResolution=12;
+uint8_t devices=0;
+
+DeviceAddress ROM_NO;
+uint8_t LastDiscrepancy;
+uint8_t LastFamilyDiscrepancy;
+bool LastDeviceFlag;
+
+/// Sends one bit to bus
+void ds18b20_write(char bit){
+	if (bit & 1) {
+		gpio_set_direction(DS_GPIO, GPIO_MODE_OUTPUT);
+		noInterrupts();
+		gpio_set_level(DS_GPIO,0);
+		ets_delay_us(6);
+		gpio_set_direction(DS_GPIO, GPIO_MODE_INPUT);	// release bus
+		ets_delay_us(64);
+		interrupts();
+	} else {
+		gpio_set_direction(DS_GPIO, GPIO_MODE_OUTPUT);
+		noInterrupts();
+		gpio_set_level(DS_GPIO,0);
+		ets_delay_us(60);
+		gpio_set_direction(DS_GPIO, GPIO_MODE_INPUT);	// release bus
+		ets_delay_us(10);
+		interrupts();
+	}
+}
+
+// Reads one bit from bus
+unsigned char ds18b20_read(void){
+	unsigned char value = 0;
+	gpio_set_direction(DS_GPIO, GPIO_MODE_OUTPUT);
+	noInterrupts();
+	gpio_set_level(DS_GPIO, 0);
+	ets_delay_us(6);
+	gpio_set_direction(DS_GPIO, GPIO_MODE_INPUT);
+	ets_delay_us(9);
+	value = gpio_get_level(DS_GPIO);
+	ets_delay_us(55);
+	interrupts();
+	return (value);
+}
+// Sends one byte to bus
+void ds18b20_write_byte(char data){
+  unsigned char i;
+  unsigned char x;
+  for(i=0;i<8;i++){
+    x = data>>i;
+    x &= 0x01;
+    ds18b20_write(x);
+  }
+  ets_delay_us(100);
+}
+// Reads one byte from bus
+unsigned char ds18b20_read_byte(void){
+  unsigned char i;
+  unsigned char data = 0;
+  for (i=0;i<8;i++)
+  {
+    if(ds18b20_read()) data|=0x01<<i;
+    ets_delay_us(15);
+  }
+  return(data);
+}
+// Sends reset pulse
+unsigned char ds18b20_reset(void){
+	unsigned char presence;
+	gpio_set_direction(DS_GPIO, GPIO_MODE_OUTPUT);
+	noInterrupts();
+	gpio_set_level(DS_GPIO, 0);
+	ets_delay_us(480);
+	gpio_set_level(DS_GPIO, 1);
+	gpio_set_direction(DS_GPIO, GPIO_MODE_INPUT);
+	ets_delay_us(70);
+	presence = (gpio_get_level(DS_GPIO) == 0);
+	ets_delay_us(410);
+	interrupts();
+	return presence;
+}
+
+bool ds18b20_setResolution(const DeviceAddress tempSensorAddresses[], int numAddresses, uint8_t newResolution) {
+	bool success = false;
+	// handle the sensors with configuration register
+	newResolution = constrain(newResolution, 9, 12);
+	uint8_t newValue = 0;
+	ScratchPad scratchPad;
+	// loop through each address
+	for (int i = 0; i < numAddresses; i++){
+		// we can only update the sensor if it is connected
+		if (ds18b20_isConnected((DeviceAddress*) tempSensorAddresses[i], scratchPad)) {
+			switch (newResolution) {
+			case 12:
+				newValue = TEMP_12_BIT;
+				break;
+			case 11:
+				newValue = TEMP_11_BIT;
+				break;
+			case 10:
+				newValue = TEMP_10_BIT;
+				break;
+			case 9:
+			default:
+				newValue = TEMP_9_BIT;
+				break;
+			}
+			// if it needs to be updated we write the new value
+			if (scratchPad[CONFIGURATION] != newValue) {
+				scratchPad[CONFIGURATION] = newValue;
+				ds18b20_writeScratchPad((DeviceAddress*) tempSensorAddresses[i], scratchPad);
+			}
+			// done
+			success = true;
+		}
+	}
+	return success;
+}
+
+void ds18b20_writeScratchPad(const DeviceAddress *deviceAddress, const uint8_t *scratchPad) {
+	ds18b20_reset();
+	ds18b20_select(deviceAddress);
+	ds18b20_write_byte(WRITESCRATCH);
+	ds18b20_write_byte(scratchPad[HIGH_ALARM_TEMP]); // high alarm temp
+	ds18b20_write_byte(scratchPad[LOW_ALARM_TEMP]); // low alarm temp
+	ds18b20_write_byte(scratchPad[CONFIGURATION]);
+	ds18b20_reset();
+}
+
+bool ds18b20_readScratchPad(const DeviceAddress *deviceAddress, uint8_t* scratchPad) {
+	// send the reset command and fail fast
+	int b = ds18b20_reset();
+	if (b == 0) return false;
+	ds18b20_select(deviceAddress);
+	ds18b20_write_byte(READSCRATCH);
+	// Read all registers in a simple loop
+	// byte 0: temperature LSB
+	// byte 1: temperature MSB
+	// byte 2: high alarm temp
+	// byte 3: low alarm temp
+	// byte 4: DS18B20 & DS1822: configuration register
+	// byte 5: internal use & crc
+	// byte 6: DS18B20 & DS1822: store for crc
+	// byte 7: DS18B20 & DS1822: store for crc
+	// byte 8: SCRATCHPAD_CRC
+	for (uint8_t i = 0; i < 9; i++) {
+		scratchPad[i] = ds18b20_read_byte();
+	}
+	b = ds18b20_reset();
+	return (b == 1);
+}
+
+void ds18b20_select(const DeviceAddress *address){
+    uint8_t i;
+    ds18b20_write_byte(SELECTDEVICE);           // Choose ROM
+    for (i = 0; i < 8; i++) ds18b20_write_byte(((uint8_t *)address)[i]);
+}
+
+void ds18b20_requestTemperatures(){
+	ds18b20_reset();
+	ds18b20_write_byte(SKIPROM);
+	ds18b20_write_byte(GETTEMP);
+    unsigned long start = esp_timer_get_time() / 1000ULL;
+    while (!isConversionComplete() && ((esp_timer_get_time() / 1000ULL) - start < millisToWaitForConversion())) vPortYield();
+}
+
+bool isConversionComplete() {
+	uint8_t b = ds18b20_read();
+	return (b == 1);
+}
+
+uint16_t millisToWaitForConversion() {
+	switch (bitResolution) {
+	case 9:
+		return 94;
+	case 10:
+		return 188;
+	case 11:
+		return 375;
+	default:
+		return 750;
+	}
+}
+
+bool ds18b20_isConnected(const DeviceAddress *deviceAddress, uint8_t *scratchPad) {
+	bool b = ds18b20_readScratchPad(deviceAddress, scratchPad);
+	return b && !ds18b20_isAllZeros(scratchPad) && (ds18b20_crc8(scratchPad, 8) == scratchPad[SCRATCHPAD_CRC]);
+}
+
+uint8_t ds18b20_crc8(const uint8_t *addr, uint8_t len){
+	uint8_t crc = 0;
+	while (len--) {
+		crc = *addr++ ^ crc;  // just re-using crc as intermediate
+		crc = pgm_read_byte(dscrc2x16_table + (crc & 0x0f)) ^
+		pgm_read_byte(dscrc2x16_table + 16 + ((crc >> 4) & 0x0f));
+	}
+	return crc;
+}
+
+bool ds18b20_isAllZeros(const uint8_t * const scratchPad) {
+	for (size_t i = 0; i < 9; i++) {
+		if (scratchPad[i] != 0) {
+			return false;
+		}
+	}
+	return true;
+}
+
+float ds18b20_getTempC(const DeviceAddress *deviceAddress) {
+	ScratchPad scratchPad;
+	if (ds18b20_isConnected(deviceAddress, scratchPad)){
+		int16_t rawTemp = calculateTemperature(deviceAddress, scratchPad);
+		if (rawTemp <= DEVICE_DISCONNECTED_RAW)
+			return DEVICE_DISCONNECTED_C;
+		// C = RAW/128
+		// F = (C*1.8)+32 = (RAW/128*1.8)+32 = (RAW*0.0140625)+32
+		return (float) rawTemp/128.0f;
+	}
+	return DEVICE_DISCONNECTED_C;
+}
+
+// reads scratchpad and returns fixed-point temperature, scaling factor 2^-7
+int16_t calculateTemperature(const DeviceAddress *deviceAddress, uint8_t* scratchPad) {
+	int16_t fpTemperature = (((int16_t) scratchPad[TEMP_MSB]) << 11) | (((int16_t) scratchPad[TEMP_LSB]) << 3);
+	return fpTemperature;
+}
+
+// Returns temperature from sensor
+float ds18b20_get_temp(void) {
+  if(init==1){
+    unsigned char check;
+    char temp1=0, temp2=0;
+      check=ds18b20_RST_PULSE();
+      if(check==1)
+      {
+        ds18b20_send_byte(0xCC);
+        ds18b20_send_byte(0x44);
+        vTaskDelay(750 / portTICK_RATE_MS);
+        check=ds18b20_RST_PULSE();
+        ds18b20_send_byte(0xCC);
+        ds18b20_send_byte(0xBE);
+        temp1=ds18b20_read_byte();
+        temp2=ds18b20_read_byte();
+        check=ds18b20_RST_PULSE();
+        float temp=0;
+        temp=(float)(temp1+(temp2*256))/16;
+        return temp;
+      }
+      else{return 0;}
+
+  }
+  else{return 0;}
+}
+
+void ds18b20_init(int GPIO) {
+	DS_GPIO = GPIO;
+	gpio_pad_select_gpio(DS_GPIO);
+	init = 1;
+}
+
+//
+// You need to use this function to start a search again from the beginning.
+// You do not need to do it for the first search, though you could.
+//
+void reset_search() {
+	devices=0;
+	// reset the search state
+	LastDiscrepancy = 0;
+	LastDeviceFlag = false;
+	LastFamilyDiscrepancy = 0;
+	for (int i = 7; i >= 0; i--) {
+		ROM_NO[i] = 0;
+	}
+}
+// --- Replaced by the one from the Dallas Semiconductor web site ---
+//--------------------------------------------------------------------------
+// Perform the 1-Wire Search Algorithm on the 1-Wire bus using the existing
+// search state.
+// Return TRUE  : device found, ROM number in ROM_NO buffer
+//        FALSE : device not found, end of search
+
+bool search(uint8_t *newAddr, bool search_mode) {
+	uint8_t id_bit_number;
+	uint8_t last_zero, rom_byte_number;
+	bool search_result;
+	uint8_t id_bit, cmp_id_bit;
+
+	unsigned char rom_byte_mask, search_direction;
+
+	// initialize for search
+	id_bit_number = 1;
+	last_zero = 0;
+	rom_byte_number = 0;
+	rom_byte_mask = 1;
+	search_result = false;
+
+	// if the last call was not the last one
+	if (!LastDeviceFlag) {
+		// 1-Wire reset
+		if (!ds18b20_reset()) {
+			// reset the search
+			LastDiscrepancy = 0;
+			LastDeviceFlag = false;
+			LastFamilyDiscrepancy = 0;
+			return false;
+		}
+
+		// issue the search command
+		if (search_mode == true) {
+			ds18b20_write_byte(0xF0);   // NORMAL SEARCH
+		} else {
+			ds18b20_write_byte(0xEC);   // CONDITIONAL SEARCH
+		}
+
+		// loop to do the search
+		do {
+			// read a bit and its complement
+			id_bit = ds18b20_read();
+			cmp_id_bit = ds18b20_read();
+
+			// check for no devices on 1-wire
+			if ((id_bit == 1) && (cmp_id_bit == 1)) {
+				break;
+			} else {
+				// all devices coupled have 0 or 1
+				if (id_bit != cmp_id_bit) {
+					search_direction = id_bit;  // bit write value for search
+				} else {
+					// if this discrepancy if before the Last Discrepancy
+					// on a previous next then pick the same as last time
+					if (id_bit_number < LastDiscrepancy) {
+						search_direction = ((ROM_NO[rom_byte_number]
+								& rom_byte_mask) > 0);
+					} else {
+						// if equal to last pick 1, if not then pick 0
+						search_direction = (id_bit_number == LastDiscrepancy);
+					}
+					// if 0 was picked then record its position in LastZero
+					if (search_direction == 0) {
+						last_zero = id_bit_number;
+
+						// check for Last discrepancy in family
+						if (last_zero < 9)
+							LastFamilyDiscrepancy = last_zero;
+					}
+				}
+
+				// set or clear the bit in the ROM byte rom_byte_number
+				// with mask rom_byte_mask
+				if (search_direction == 1)
+					ROM_NO[rom_byte_number] |= rom_byte_mask;
+				else
+					ROM_NO[rom_byte_number] &= ~rom_byte_mask;
+
+				// serial number search direction write bit
+				ds18b20_write(search_direction);
+
+				// increment the byte counter id_bit_number
+				// and shift the mask rom_byte_mask
+				id_bit_number++;
+				rom_byte_mask <<= 1;
+
+				// if the mask is 0 then go to new SerialNum byte rom_byte_number and reset mask
+				if (rom_byte_mask == 0) {
+					rom_byte_number++;
+					rom_byte_mask = 1;
+				}
+			}
+		} while (rom_byte_number < 8);  // loop until through all ROM bytes 0-7
+
+		// if the search was successful then
+		if (!(id_bit_number < 65)) {
+			// search successful so set LastDiscrepancy,LastDeviceFlag,search_result
+			LastDiscrepancy = last_zero;
+
+			// check for last device
+			if (LastDiscrepancy == 0) {
+				LastDeviceFlag = true;
+			}
+			search_result = true;
+		}
+	}
+
+	// if no device found then reset counters so next 'search' will be like a first
+	if (!search_result || !ROM_NO[0]) {
+		devices=0;
+		LastDiscrepancy = 0;
+		LastDeviceFlag = false;
+		LastFamilyDiscrepancy = 0;
+		search_result = false;
+	} else {
+		for (int i = 0; i < 8; i++){
+			newAddr[i] = ROM_NO[i];
+		}
+		devices++;
+	}
+	return search_result;
+}
+
+#endif // ENABLE_DS18B20

+ 84 - 0
main/ds18b20.h

@@ -0,0 +1,84 @@
+/*
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include <esp_system.h>
+
+#ifndef DS18B20_H_  
+#define DS18B20_H_
+
+// warning: 'taskENTER_CRITICAL(mux)' is deprecated in ESP-IDF, consider using 'portENTER_CRITICAL(mux)'
+#define noInterrupts() portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;taskENTER_CRITICAL(&mux)
+#define interrupts() taskEXIT_CRITICAL(&mux)
+
+#define DEVICE_DISCONNECTED_C -127
+#define DEVICE_DISCONNECTED_F -196.6
+#define DEVICE_DISCONNECTED_RAW -7040
+#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
+#define pgm_read_byte(addr)   (*(const unsigned char *)(addr))
+
+typedef uint8_t DeviceAddress[8];
+typedef uint8_t ScratchPad[9];
+
+// Dow-CRC using polynomial X^8 + X^5 + X^4 + X^0
+// Tiny 2x16 entry CRC table created by Arjen Lentz
+// See http://lentz.com.au/blog/calculating-crc-with-a-tiny-32-entry-lookup-table
+static const uint8_t dscrc2x16_table[] = {
+	0x00, 0x5E, 0xBC, 0xE2, 0x61, 0x3F, 0xDD, 0x83,
+	0xC2, 0x9C, 0x7E, 0x20, 0xA3, 0xFD, 0x1F, 0x41,
+	0x00, 0x9D, 0x23, 0xBE, 0x46, 0xDB, 0x65, 0xF8,
+	0x8C, 0x11, 0xAF, 0x32, 0xCA, 0x57, 0xE9, 0x74
+};
+
+/* *INDENT-OFF* */
+#ifdef __cplusplus
+    extern "C" {
+#endif
+/* *INDENT-ON* */
+
+void ds18b20_init(int GPIO);
+
+#define ds18b20_send ds18b20_write
+#define ds18b20_send_byte ds18b20_write_byte
+#define ds18b20_RST_PULSE ds18b20_reset
+
+void ds18b20_write(char bit);
+unsigned char ds18b20_read(void);
+void ds18b20_write_byte(char data);
+unsigned char ds18b20_read_byte(void);
+unsigned char ds18b20_reset(void);
+
+bool ds18b20_setResolution(const DeviceAddress tempSensorAddresses[], int numAddresses, uint8_t newResolution);
+bool ds18b20_isConnected(const DeviceAddress *deviceAddress, uint8_t *scratchPad);
+void ds18b20_writeScratchPad(const DeviceAddress *deviceAddress, const uint8_t *scratchPad);
+bool ds18b20_readScratchPad(const DeviceAddress *deviceAddress, uint8_t *scratchPad);
+void ds18b20_select(const DeviceAddress *address);
+uint8_t ds18b20_crc8(const uint8_t *addr, uint8_t len);
+bool ds18b20_isAllZeros(const uint8_t * const scratchPad);
+bool isConversionComplete();
+uint16_t millisToWaitForConversion();
+
+void ds18b20_requestTemperatures();
+float ds18b20_getTempF(const DeviceAddress *deviceAddress);
+float ds18b20_getTempC(const DeviceAddress *deviceAddress);
+int16_t calculateTemperature(const DeviceAddress *deviceAddress, uint8_t* scratchPad);
+float ds18b20_get_temp(void);
+
+void reset_search();
+bool search(uint8_t *newAddr, bool search_mode);
+
+/* *INDENT-OFF* */
+#ifdef __cplusplus
+    }
+#endif
+/* *INDENT-ON* */
+
+#endif

+ 2 - 2
main/kWhCounter.c

@@ -8,10 +8,10 @@
 
 #include "kWhCounter.h"
 
-#ifdef ENABLE_KWH_COUNTER
-
 uint32_t kWh_cnt = 0;
 
+#ifdef ENABLE_KWH_COUNTER
+
 void counterControlTask(void *pvParameters) {
 
     ESP_LOGI("kWhCounter", "counterControlTask starting. Core:%d",xPortGetCoreID());

+ 11 - 2
main/main.c

@@ -6,6 +6,7 @@
 #include "mqtt.h"
 #include "kWhCounter.h"
 #include "http_client.h"
+#include "readTemps.h"
 
 
 // Chip info:
@@ -34,19 +35,27 @@ void app_main(void)
     mqtt_init();
 #endif
 
-
-
     const TickType_t xFreq = 30000 / portTICK_PERIOD_MS;
     TickType_t vLastWakeTime = xTaskGetTickCount();
 
+    // ---------------- MAIN WHILE -------------------
     while(1) {
 
         vTaskDelayUntil( &vLastWakeTime, xFreq );
+#ifdef HTTP_ENABLED
         http_rest_with_url();
+#endif
 
         vTaskDelayUntil( &vLastWakeTime, xFreq );
         sprintf(txt,"%u",kWh_cnt);
+#ifdef MQTT_ENABLED
         sendMQTTMessage("basement/boiler/onTime", txt);
+#endif
+
+
+#ifdef ENABLE_DS18B20
+        readTemps();
+#endif
     }
 
     vTaskDelete(NULL);

+ 72 - 0
main/readTemps.c

@@ -0,0 +1,72 @@
+#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

+ 8 - 0
main/readTemps.h

@@ -0,0 +1,8 @@
+#ifndef READ_TEMPS_H
+#define READ_TEMPS_H
+
+
+void readTemps();
+
+
+#endif