|
@@ -60,58 +60,71 @@ void initTempReadings() {
|
|
|
ds18b20_use_crc(ds18b20_info, true); // enable CRC check on all reads
|
|
|
ds18b20_set_resolution(ds18b20_info, DS18B20_RESOLUTION);
|
|
|
}
|
|
|
+
|
|
|
+ // Start the TEMPS task
|
|
|
+ xTaskCreatePinnedToCore(readAndSendTemps, "TEMPS-Task", 1024*10, NULL, 2, NULL,0);
|
|
|
}
|
|
|
|
|
|
void readAndSendTemps(void *pvParameters) {
|
|
|
|
|
|
ESP_LOGI("TEMPS", "Read temperature task. Core:%d",xPortGetCoreID());
|
|
|
|
|
|
- // Read temperatures more efficiently by starting conversions on all devices at the same time
|
|
|
- int errors_count[MAX_DEVICES] = {0};
|
|
|
- if (num_devices > 0)
|
|
|
+ while(true)
|
|
|
{
|
|
|
- ds18b20_convert_all(owb);
|
|
|
+
|
|
|
|
|
|
- // In this application all devices use the same resolution,
|
|
|
- // so use the first device to determine the delay
|
|
|
- const float sampleTime = ds18b20_wait_for_conversion(devices[0]);
|
|
|
+ // Read temperatures more efficiently by starting conversions on all devices at the same time
|
|
|
+ int errors_count[MAX_DEVICES] = {0};
|
|
|
+ if (num_devices > 0)
|
|
|
+ {
|
|
|
+ ds18b20_convert_all(owb);
|
|
|
|
|
|
- // Read the results immediately after conversion otherwise it may fail
|
|
|
- // (using printf before reading may take too long)
|
|
|
- float readings[MAX_DEVICES] = { 0 };
|
|
|
- DS18B20_ERROR errors[MAX_DEVICES] = { 0 };
|
|
|
+ // In this application all devices use the same resolution,
|
|
|
+ // so use the first device to determine the delay
|
|
|
+ const float sampleTime = ds18b20_wait_for_conversion(devices[0]);
|
|
|
|
|
|
- for (int i = 0; i < num_devices; ++i)
|
|
|
- {
|
|
|
- errors[i] = ds18b20_read_temp(devices[i], &readings[i]);
|
|
|
- }
|
|
|
+ vTaskDelay(500 / portTICK_PERIOD_MS);
|
|
|
|
|
|
- ESP_LOGI("TEMPS","Sample time:%.0fms",sampleTime);
|
|
|
+ // Read the results immediately after conversion otherwise it may fail
|
|
|
+ // (using printf before reading may take too long)
|
|
|
+ float readings[MAX_DEVICES] = { 0 };
|
|
|
+ DS18B20_ERROR errors[MAX_DEVICES] = { 0 };
|
|
|
|
|
|
- // Print results in a separate loop, after all have been read
|
|
|
- for (int i = 0; i < num_devices; ++i)
|
|
|
- {
|
|
|
- if (errors[i] != DS18B20_OK)
|
|
|
+ for (int i = 0; i < num_devices; ++i)
|
|
|
{
|
|
|
- ++errors_count[i];
|
|
|
+ errors[i] = ds18b20_read_temp(devices[i], &readings[i]);
|
|
|
}
|
|
|
-
|
|
|
- char rom_code_s[25];
|
|
|
- char mqtt_s[50];
|
|
|
- char value_s[10];
|
|
|
- owb_string_from_rom_code(devices[i]->rom_code, rom_code_s, sizeof(rom_code_s));
|
|
|
|
|
|
- sprintf(mqtt_s,"basement/boiler/temps/%s", rom_code_s);
|
|
|
- sprintf(value_s,"%.1f",readings[i]);
|
|
|
- ESP_LOGI("TEMPS","%s %s", mqtt_s, value_s);
|
|
|
+ ESP_LOGI("TEMPS","Sample time:%.0fms",sampleTime);
|
|
|
|
|
|
- sendMQTTMessage(mqtt_s, value_s);
|
|
|
+ // Print results in a separate loop, after all have been read
|
|
|
+ for (int i = 0; i < num_devices; ++i)
|
|
|
+ {
|
|
|
+ if (errors[i] != DS18B20_OK)
|
|
|
+ {
|
|
|
+ ++errors_count[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ char rom_code_s[25];
|
|
|
+ char mqtt_s[50];
|
|
|
+ char value_s[10];
|
|
|
+ owb_string_from_rom_code(devices[i]->rom_code, rom_code_s, sizeof(rom_code_s));
|
|
|
+
|
|
|
+ sprintf(mqtt_s,"garage/temps/%s", rom_code_s);
|
|
|
+ sprintf(value_s,"%.1f",readings[i]);
|
|
|
+ ESP_LOGI("TEMPS","%s %s", mqtt_s, value_s);
|
|
|
+
|
|
|
+ sendMQTTMessage(mqtt_s, value_s);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ESP_LOGE("TEMPS", "No DS18B20 devices detected!");
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ESP_LOGE("TEMPS", "No DS18B20 devices detected!");
|
|
|
+ vTaskDelay(10000 / portTICK_PERIOD_MS);
|
|
|
+
|
|
|
}
|
|
|
vTaskDelete(NULL);
|
|
|
}
|