Using Zentser with DS18B20 sensors

I am currently attempting to build a prototype proof of concept for a 24hour fish tank monitor that would send alerts to the owner if temperatures got too hot or too cold - the zentser app works really well for this so the challenging part is building a compatible sensor that will communicate with the app.

I am using an ESP8266 board (NodeMCU v3) and a DS18b20 submersible temperature sensor.

I have the example code for the ESP board using a DHT sensor

#include <Zentser_ESP_SDK.h>
/*#include <YOUR_SENSORS_LIBRARY> */
#include <DHT.h>

char const *ssid = "YOUR_WIFI";
char const *wiFiPassword = "YOUR_WIFI_PASSWORD";

// Replace on generated code from Zentser Application
// --- START ---
static const char caCert[] PROGMEM = R"EOF(
/* CA CERTIFICATE */
)EOF";
 
static const char cert[] PROGMEM = R"KEY(
/* CERTIFICATE */
)KEY";
 
static const char privateKey[] PROGMEM = R"KEY(
/* PRIVATE_KEY */
)KEY";
 
String deviceId = "YOUR_DEVICE_ID"; // Zentser Device ID
Sensor sensors[] {
  Sensor("YOUR_SENSOR_ID_0", "Temperature (F)"),
  Sensor("YOUR_SENSOR_ID_1", "Humidity (%)"),
  Sensor("YOUR_SENSOR_ID_2", "Heat Index (F)"),
}; 

// --- END ---

AWSConfig aws = AWSConfig(deviceId, sensors); // init AWS function

// Initialize Your sensor
// Digital pin connected to the DHT sensor
uint8_t DHTPIN = 14; //D5

// Uncomment whatever DHT sensor type you're using
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Initialize DHT sensor
DHT dht(DHTPIN, DHTTYPE);

// Function to connect to WiFi
void connectToWiFi() {
  Serial.print("\nConnecting to AP ...");

  WiFi.begin(ssid, wiFiPassword);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nConnected to AP");
}

// initial function at starting your microcontroller (ESP, Arduino, etc)
void setup() {
  Serial.begin(115200); // init serial for logging

  connectToWiFi(); // call function to start WiFi connection

  //get AWS certificates to authenticate sending sensor data
  aws.setupAWSCertificates(cert, privateKey, caCert);

  // connect and start your sensor
  pinMode(DHTPIN, INPUT);
  dht.begin();

  delay(500);
}

// main loop for microcontroller where you will collect and send sensor data
void loop() {

  // Check Wifi connection is still active
  if (WiFi.status() != WL_CONNECTED) {
    connectToWiFi();
  }

  // MODIFY to get sensor readings from hardware connected to your microcontroller
  float t = dht.readTemperature(true);
  float h = dht.readHumidity();
  float hIdx = dht.computeHeatIndex(t, h);
  Serial.printf("t = %6.2f; h = %6.2f; heatIndex = %6.2f\n", t, h, hIdx);

  sensors[0].value = t;
  sensors[1].value = h;
  sensors[2].value = hIdx;

  aws.sendSensorsTelemetry();
  
  // check that we're not bombarding Zentser with too much data
  // don't want to bring the system down in unintended DDoS attack
  aws.delayNextRead();
}

and for the DS18B20 sensor from the DallasTemperatures Library

// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

/*
 * The setup function. We only start the sensors here
 */
void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();
}

/*
 * Main function, get and show the temperature
 */
void loop(void)
{ 
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  // After we got the temperatures, we can print them here.
  // We use the function ByIndex, and as an example get the temperature from the first sensor only.
  float tempC = sensors.getTempCByIndex(0);

  // Check if reading was successful
  if(tempC != DEVICE_DISCONNECTED_C) 
  {
    Serial.print("Temperature for the device 1 (index 0) is: ");
    Serial.println(tempC);
  } 
  else
  {
    Serial.println("Error: Could not read temperature data");
  }
}

However in trying to combine the two I cannot find where the ESP board decides what to send to the app or where the DS18B20 decides what to send to the serial monitor so I cannot find a way to make these two parts match up

Anyone have any experience with this?

It looks like this bit sends to the app:

  sensors[0].value = t;
  sensors[1].value = h;
  sensors[2].value = hIdx;

  aws.sendSensorsTelemetry();

I don't understand how the was object knows how many sensors there are though.

On the DS18B20 side, You already have the temperature being read into tempC and printed to serial. You should be able to replace the temperature value from the dht with this value.

Thanks
This was one of my thoughts too but when attempting this as below

 `// initial function at starting your microcontroller (ESP, Arduino, etc)
void setup() {
  Serial.begin(115200); // init serial for logging

  connectToWiFi(); // call function to start WiFi connection

  //get AWS certificates to authenticate sending sensor data
  aws.setupAWSCertificates(cert, privateKey, caCert);

  // connect and start your sensor
 // start serial port 
 Serial.begin(9600); 
 Serial.println("Dallas Temperature IC Control Library Demo"); 
 // Start up the library 
 sensor.begin(); 
  delay(500);
}

// main loop for microcontroller where you will collect and send sensor data
void loop() {

  // Check Wifi connection is still active
  if (WiFi.status() != WL_CONNECTED) {
    connectToWiFi();
  }

  // MODIFY to get sensor readings from hardware connected to your microcontroller
 Serial.print(" Requesting temperatures..."); 
 sensor.requestTemperatures(); // Send the command to get temperature readings 
 Serial.println("DONE");

 Serial.print("Temperature is: "); 
 Serial.print(sensor.getTempCByIndex(0)); // Why "byIndex"?  
   // You can have more than one DS18B20 on the same bus.  
   // 0 refers to the first IC on the wire

  sensors[0].value = tempC;
  aws.sendSensorsTelemetry();
  
  // check that we're not bombarding Zentser with too much data
  // don't want to bring the system down in unintended DDoS attack
  aws.delayNextRead();
}`

I get the error message

C:\Users\euan_\OneDrive\Documents\Arduino\Temp_Monitor\Temp_Monitor.ino: In function 'void loop()':
Temp_Monitor:158:22: error: 'tempC' was not declared in this scope
  158 |   sensors[0].value = tempC;
      |                      ^~~~~
exit status 1
'tempC' was not declared in this scope

Am I missing something

Did you only post part of the code?
All the DS18B20 declarations you had before void setup() of the second sketch of post#1 are missing. And if you're going to read the temperature in a tempC variable, you need to declare that up too.
float tempC;

Study the examples that come with the DS18B20 library you're using, and see what is needed.
Leo..

Its been a while since I have been able to look at this project properly I feel like I am close to a working device the reading on the app from the temperature probe has changed from reading NA but now is constantly reading 0 and I will be dammed if I can work out why

full code attached below

#include <Zentser_ESP_SDK.h>
/*#include <YOUR_SENSORS_LIBRARY> */
#include <OneWire.h> 
#include <DallasTemperature.h>

char const *ssid = "BT-HSAJ86";
char const *wiFiPassword = "XrpGXTDPAUFd4u";

// Replace on generated code from Zentser Application
// --- START ---
static const char caCert[] PROGMEM = R"EOF(
-----BEGIN CERTIFICATE-----
MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF
ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6
b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL
MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv
b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj
ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM
9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw
IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6
VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L
93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm
jgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC
AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA
A4IBAQCY8jda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AIWmcwV0Rc8t0NtCIJX2qn0JCPZyRh/fbVg/8x69XiAC
-----END RSA PRIVATE KEY-----
)KEY";
 
String deviceId = "154872";

Sensor sensors[] {
 Sensor("274", "Temperature (C)"),
}; 


// --- END ---

AWSConfig aws = AWSConfig(deviceId, sensors); // init AWS function


// Data wire is plugged into pin 2 on the Arduino 
#define ONE_WIRE_BUS 1

/********************************************************************/
// Setup a oneWire instance to communicate with any OneWire devices  
// (not just Maxim/Dallas temperature ICs) 
OneWire oneWire(ONE_WIRE_BUS); 
/********************************************************************/
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensor(&oneWire);
float TempC;

// Function to connect to WiFi
void connectToWiFi() {
  Serial.print("\nConnecting to AP ...");

  WiFi.begin(ssid, wiFiPassword);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nConnected to AP");
}

// initial function at starting your microcontroller (ESP, Arduino, etc)
void setup() {
  Serial.begin(115200); // init serial for logging

  connectToWiFi(); // call function to start WiFi connection

  //get AWS certificates to authenticate sending sensor data
  aws.setupAWSCertificates(cert, privateKey, caCert);

  // connect and start your sensor
 // start serial port 
 Serial.begin(9600); 
 Serial.println("Dallas Temperature IC Control Library Demo"); 
 // Start up the library 
 sensor.begin(); 
  delay(500);
}

// main loop for microcontroller where you will collect and send sensor data
void loop() {

  // Check Wifi connection is still active
  if (WiFi.status() != WL_CONNECTED) {
    connectToWiFi();
  }

  // MODIFY to get sensor readings from hardware connected to your microcontroller
 Serial.print(" Requesting temperatures..."); 
 sensor.requestTemperatures(); // Send the command to get temperature readings 
 Serial.println("DONE");

 Serial.print("Temperature is: "); 
 Serial.print(sensor.getTempCByIndex(0)); // Why "byIndex"?  
   // You can have more than one DS18B20 on the same bus.  
   // 0 refers to the first IC on the wire

  sensors[0].value = TempC;
  aws.sendSensorsTelemetry();
  
  // check that we're not bombarding Zentser with too much data
  // don't want to bring the system down in unintended DDoS attack
  aws.delayNextRead();
}

If anyone can see the issue that would be more than amazing

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.