Good day everyone,
I have been successfully using two ESP32's to monitor my wife's fish pond. One ESP32 uses a BME280 sensor (outside temp, humidity, baro), the other uses a DS18B20 probe (for water temp). I have 3d printed a mount that holds both sensors side by side. Both correctly transmit data to InfluxDB Cloud2 service and I use Grafana to create a "FishPond" dashboard to display water temp, outside temp, humidity and baro.
My question or need for help is, how do I combine both sensors into a sketch to combine two esp32's into one? Both ESP32's report their sensor data correctly but I would like to add the DS18B20 probe into the working ESP32 BME280 sketch but have not been successful yet. I have spent (on and off) months trying to figure this out myself but I am definitely not a programmer and am in need of assistance. Maybe this cannot be done and I can continue using two ESP32's but wanted a tidier setup.
I have been able to create a sketch that shows both sensors data in serial monitor using ArduinoIDE but only the rssi wireless data is reported to influxdb so I feel I'm close.
Please tell me what I need to do to upload my sketch the proper way for review. Thank you to all that will reply.
Thank you,
Biigbyt
P.S. I did scour the forum for related topics but didnt see anything. If I missed related topics, please let me know.
Welcome to the forum
Your topic has been moved to the Programming Questions category of the forum
Please post the sketch that prints the values to the Serial monitor and please use code tags when you do
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
Thank you UKHeliBob. Looking forward for help and seeing the correct code should read!
some time back I implemented a river monitoring system using The Things UNO with a BMP280 temperature/pressure sensor, a SR04M ultrasonic transducer and a DS18B20 DallasTemperature sensor uploading data over LoRaWAN to the myDevices/cayenne desktop

I was reading the sensors and uploading data every 10 minutes
you can see the river is tidal – rise and fall of about 10cm
I used a Things UNO (which is based on the Arduino Leonardo) but an ESP32 should be quite capable of reading a BME280 sensor and a DS18B20 probe and upload results to your desktop
Horace, that is awesome. Hopefully one day I can get more educated in the LoRaWAN
the device was not in range of WiFi so I used LoRaWAN (much simpler to use WiFi and MQTT)
photo of setup (in normal use laptop is not used and the Things Uno is an a waterproof box)

UKHeliBob,
The code below works flawless and reports to InfluxDB correctly. Instead of rewriting everything, I need to add the DS18D20 into the code but just cant seem to figure it out.
Any help would be greatly appreciated.
I followed your guide for copy and paste so please let me know if it is not correct.
#include <WiFiMulti.h>
#include <InfluxDbClient.h>
#include <InfluxDbCloud.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
WiFiMulti wifiMulti;
Adafruit_BME280 bme;
float temperature;
float humidity;
float pressure;
#define DEVICE "ESP32"
#define WIFI_SSID "C://MyNetwork"
#define WIFI_PASSWORD "MyPassword"
#define INFLUXDB_URL ""
#define INFLUXDB_TOKEN ""
#define INFLUXDB_ORG ""
#define INFLUXDB_BUCKET "Fish Pond"
// Set timezone string according to https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
#define TZ_INFO "CST6CDT,M3.2.0,M11.1.0"
// InfluxDB client instance with preconfigured InfluxCloud certificate
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert);
// Data points
Point sensor1("temperature_status");
Point sensor2("humidity_status");
Point sensor3("pressure_status");
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to wifi");
while (wifiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
if (!bme.begin(0x76)) {
Serial.println("Could not detect a BME280 sensor, Fix wiring Connections!");
while (1)
;
}
// Add tags
sensor1.addTag("device", DEVICE);
sensor1.addTag("SSID", WiFi.SSID());
sensor2.addTag("device", DEVICE);
sensor2.addTag("SSID", WiFi.SSID());
sensor3.addTag("device", DEVICE);
sensor3.addTag("SSID", WiFi.SSID());
timeSync(TZ_INFO, "pool.ntp.org", "time.nis.gov");
if (client.validateConnection()) {
Serial.print("Connected to InfluxDB: ");
Serial.println(client.getServerUrl());
} else {
Serial.print("InfluxDB connection failed: ");
Serial.println(client.getLastErrorMessage());
}
}
void loop() {
// Store measured values into points
sensor1.clearFields();
sensor2.clearFields();
sensor3.clearFields();
temperature = bme.readTemperature();
humidity = bme.readHumidity();
pressure = bme.readPressure() / 100.0F;
sensor1.addField("Temperature", temperature);
sensor2.addField("Humidity", humidity);
sensor3.addField("Pressure", pressure);
Serial.print("Writing: ");
Serial.println(client.pointToLineProtocol(sensor1));
Serial.println(client.pointToLineProtocol(sensor2));
Serial.println(client.pointToLineProtocol(sensor3));
// If no Wifi signal, try to reconnect it
if (wifiMulti.run() != WL_CONNECTED) {
Serial.println("Wifi connection lost");
}
// Write point
if (!client.writePoint(sensor1)) {
Serial.print("InfluxDB write failed for temperature: ");
Serial.println(client.getLastErrorMessage());
}
if (!client.writePoint(sensor2)) {
Serial.print("InfluxDB write failed for humidity: ");
Serial.println(client.getLastErrorMessage());
}
if (!client.writePoint(sensor3)) {
Serial.print("InfluxDB write failed for pressure: ");
Serial.println(client.getLastErrorMessage());
}
Serial.println("");
Serial.println("Delay 60s");
delay(60000);
}
Please post your best effort at a sketch that incorporates the changes and describe the problems that you have encountered
Horace,
That is a cool setup and interesting using a SR04M sensor to measure the water level. What was the idea behind this?
the ultrasonic sensor is waterproof and gives distance to the water therefore can be used to detect floods etc
alternatives which I have used on indoor water tanks are TOF (time of flight) seensors, capacitive sensors, etc etc
Ok, this sketch does work in Serial Monitor using Arduino IDE. Shows correct sensor data and that it is connected to InfluxDB but only "rssi" is being transmitted to InfluxDB. My "writing" to seems incomplete.

#include <WiFiMulti.h>
#include <InfluxDbClient.h>
#include <InfluxDbCloud.h>
#include <Adafruit_BME280.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_Sensor.h>
#include <WiFi.h>
const char* ssid = "MyNetwork";
const char* password = "MyPassword";
WiFiMulti WiFiMulti;
#define DEVICE "ESP32"
#define WIFI_SSID ""
#define WIFI_PASSWORD ""
#define INFLUXDB_URL ""
#define INFLUXDB_TOKEN ""
#define INFLUXDB_ORG ""
#define INFLUXDB_BUCKET "Fish Pond Weather Station"
// Time zone info
#define TZ_INFO "UTC-5"
// Declare InfluxDB client instance with preconfigured InfluxCloud certificate
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert);
// Declare Data point
Point sensor("wifi_status");
// GPIO where the DS18B20 is connected to
const int oneWireBus = 17;
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(oneWireBus);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
// I2C address: 0x76 or 0x77 (0x77 is default)
#define BME_SDA 21
#define BME_SCL 22
Adafruit_BME280 bme; // I2C
void setup() {
Serial.begin(115200);
delay(1000);
// Connect to WiFi
WiFi.mode(WIFI_STA);
WiFiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
Serial.println("Connecting to WiFi");
while (WiFiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(100);
}
Serial.println("\nConnected to the WiFi network");
// Start the DS18B20 sensor
sensors.begin();
// Start the BME280 sensor
if (!bme.begin(0x76, &Wire)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1)
;
}
// Accurate time is necessary for certificate validation and writing in batches
// We use the NTP servers in your area as provided by: https://www.pool.ntp.org/zone/
// Syncing progress and the time will be printed to Serial.
timeSync(TZ_INFO, "pool.ntp.org", "time.nis.gov");
// Check server connection
if (client.validateConnection()) {
Serial.print("Connected to InfluxDB: ");
Serial.println(client.getServerUrl());
} else {
Serial.print("InfluxDB connection failed: ");
Serial.println(client.getLastErrorMessage());
}
{
// ... code in setup() from Initialize Client
// Add tags to the data point
sensor.addTag("device", DEVICE);
sensor.addTag("SSID", WiFi.SSID());
}
}
void loop() {
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
float temperatureF = sensors.getTempFByIndex(0);
Serial.print("DS18B20 Temperature: ");
Serial.print(temperatureF);
Serial.println("ºF");
Serial.print("BME280 Temperature: ");
Serial.print(bme.readTemperature());
Serial.println("ºC");
Serial.print("BME280 Pressure: ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("BME280 Humidity: ");
Serial.print(bme.readHumidity());
Serial.println("%");
{
// Clear fields for reusing the point. Tags will remain the same as set above.
sensor.clearFields();
// Store measured value into point
// Report RSSI of currently connected network
sensor.addField("rssi", WiFi.RSSI());
// Print what are we exactly writing
Serial.print("Writing: ");
Serial.println(sensor.toLineProtocol());
// Check WiFi connection and reconnect if needed
if (WiFiMulti.run() != WL_CONNECTED) {
Serial.println("Wifi connection lost");
}
// Write point
if (!client.writePoint(sensor)) {
Serial.print("InfluxDB write failed: ");
Serial.println(client.getLastErrorMessage());
}
Serial.println("Waiting 60 second");
delay(60000);
}
delay(60000);
}
I wouldn't mind adding that into my 150 gallon fish pond to monitor water loss.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.