I'm trying to use an ESP32 and some ds18b20 temperature sensors to read temperatures around the house and visualize the data using Grafana and Influxdb. I am attempting to use some sensors parasitically powered on pin 18 and others powered normally on pin 4 . The rationale being that some locations already have 2 wire thermostats that I can easily remove and replace with a flush mount temp sensor. My problem is that now with three sensors connected (2 parasitically powered and 1 normal) I am getting temperature readings of 75.2F, 77F, and 78.8. or 24, 25 and 25 in celsius. Wondering if anyone else has ever had this problem. Any help would be appreciated! I have been struggling with these things for a while now.
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <WiFiMulti.h>
WiFiMulti wifiMulti;
#include <InfluxDbClient.h>
#include <InfluxDbCloud.h>
#define DEVICE "ESP32"
// Data wire is plugged into digital pins 4 and 18 on the ESP32
#define ONE_WIRE_BUS 4
#define ONE_WIRE_BUS2 18
#define TEMPERATURE_PRECISION 9
#define WIFI_SSID "*********" //Network Name
#define WIFI_PASSWORD "*********" //Network Password
#define INFLUXDB_URL "***********"
#define INFLUXDB_TOKEN "***********"
#define INFLUXDB_ORG "***********"
#define INFLUXDB_BUCKET "***********"
#define TZ_INFO "***********"
// Setup a oneWire instance to communicate with any OneWire device
OneWire oneWire(ONE_WIRE_BUS);
OneWire oneWire2(ONE_WIRE_BUS2);
// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);
DallasTemperature sensorspara(&oneWire2);
DeviceAddress second_fl_temp_address = { 0x28, 0x5A, 0x32, 0xDB, 0x0A, 0x00, 0x00, 0x07 };
DeviceAddress basement_temp_address = { 0x28, 0x69, 0x9F, 0xDC, 0x0A, 0x00, 0x00, 0xEA};
DeviceAddress first_fl_temp_address = { 0x28, 0x35, 0xB0, 0xDC, 0x0A, 0x00, 0x00, 0x2E};
DeviceAddress boiler_outlet_address= { 0x28, 0x90, 0x40, 0x57, 0x04, 0xE1, 0x3C, 0x2A };
//int deviceCount = 0;
int16_t second_fl_temp_raw;
int16_t first_fl_temp_raw;
int16_t basement_temp_raw;
int16_t boiler_outlet_raw;
float second_fl_temp;
float first_fl_temp;
float basement_temp;
float boiler_outlet_temp;
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert);
Point sensor("Temperature Readings"); //Data points
void setup(void)
{
Serial.begin(9600);
WiFi.mode(WIFI_STA); //Setup wifi connection
wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to wifi"); //Connect to WiFi
while (wifiMulti.run() != WL_CONNECTED)
{
Serial.print(".");
delay(100);
}
Serial.println();
sensor.addTag("device", DEVICE); //Add tag(s) - repeat as required
sensor.addTag("SSID", WIFI_SSID);
timeSync(TZ_INFO, "pool.ntp.org", "time.nis.gov"); //Accurate time is necessary for certificate validation and writing in batches
if (client.validateConnection()) //Check server connection
{
Serial.print("Connected to InfluxDB: ");
Serial.println(client.getServerUrl());
}
else
{
Serial.print("InfluxDB connection failed: ");
Serial.println(client.getLastErrorMessage());
}
sensors.begin();
sensorspara.begin();
}
// locate devices on the bus
//deviceCount = sensors.getDeviceCount();
//deviceCount = sensorspara.getDeviceCount();
//}
void loop(void)
{
// Send command to all the sensors for temperature conversion
sensors.requestTemperatures();
sensorspara.requestTemperatures();
// Display temperature from each sensor
{
//Normally Powered Sensors
Serial.print("Boiler Outlet ");
Serial.print(" : ");
boiler_outlet_raw = sensors.getTemp(boiler_outlet_address);
//first_fl_temp = (DallasTemperature::toFahrenheit(first_fl_temp));
boiler_outlet_temp = (boiler_outlet_raw / 128);
boiler_outlet_temp = ((boiler_outlet_temp)*(1.8)+(32));
Serial.print(boiler_outlet_temp);
Serial.println("F");
//Parasitically Powered Sensors
Serial.print("First floor ");
Serial.print(" : ");
//second_fl_temp = sensorspara.getTempCByIndex(0);
first_fl_temp_raw = sensorspara.getTemp(first_fl_temp_address);
//second_fl_temp = (DallasTemperature::toFahrenheit(second_fl_temp));
first_fl_temp = (first_fl_temp_raw / 128);
first_fl_temp = ((first_fl_temp)*(1.8)+(32));
//Serial.print(second_fl_temp_raw);
Serial.print(first_fl_temp);
Serial.println("F");
Serial.print("Second Floor ");
Serial.print(" : ");
//second_fl_temp = sensorspara.getTempCByIndex(0);
second_fl_temp_raw = sensorspara.getTemp(second_fl_temp_address);
//second_fl_temp = (DallasTemperature::toFahrenheit(second_fl_temp));
second_fl_temp = (second_fl_temp_raw / 128);
second_fl_temp = ((second_fl_temp)*(1.8)+(32));
//Serial.print(second_fl_temp_raw);
Serial.print(second_fl_temp);
Serial.println("F");
//Serial.print("Basement ");
//Serial.print(" : ");
//basement_temp = sensorspara.getTempCByIndex(1);
// second_fl_temp = (DallasTemperature::toFahrenheit(second_fl_temp));
//basement_temp = ((basement_temp)*(1.8)+(32));
//Serial.print(basement_temp);
//Serial.println("F");
}
sensor.clearFields(); //Clear fields for reusing the point. Tags will remain untouched
sensor.addField("Boiler outlet temp", boiler_outlet_temp);
sensor.addField("First floor temp", first_fl_temp); // Store measured value into point
sensor.addField("Second floor temp", second_fl_temp); // Store measured value into point
//sensor.addField("Basement temp", basement_temp);
if (wifiMulti.run() != WL_CONNECTED) //Check WiFi connection and reconnect if needed
Serial.println("Wifi connection lost");
if (!client.writePoint(sensor)) //Write data point
{
Serial.print("InfluxDB write failed: ");
Serial.println(client.getLastErrorMessage());
}
Serial.println("");
delay(1000);
}