Zentser Remote Aquarium Monitor

This is a project I have been working on and off for some time now to produce an device which will monitor the temperature of an aquarium and notify the owner through a mobile app allowing them to take action on an otherwise unnoticed issue.
I have been using the Zentser app for this as it seems like it should be well suited to this application if I could just sort the coding using the ESP8266 wifi board and a DS18B20 temperature sensor

coding is as below

/*#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-----
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/zAOBgNVHQ8BAf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CHXtrnK5eTxZ
A1tl7U5G7qijMeqevK3U/fKHIFRVBMD056OHugjISHTUxm4PrPAJmgMsyOX1n2Id
O706x+TwNSdXAIWmcwV0Rc8t0NtCIJX2qn0JCPZyRh/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();
}
type or paste code here

currently the sensor seems to be communicating with the app but is always returning a temperature of 0

I have been looking at this for a while and cannot work out why my initial thought was that the 0 is this line should match the 274 which looks like it has been generated by the app as a name for the sensor - I don't have any logic behind this reasoning but thought I would give it a go anyway - this code runs but still has the same issue

sensors[0].value = TempC;
  aws.sendSensorsTelemetry();

I have been looking at this for about a week now at the same stage and I am no closer to a solution so any advice would be magic

Thanks

Is your code print real temperature to the Arduino Serial in this lines:

And what are you doing in this line?

Where do you assign any reasonable value to the TempC variable?

thanks for this
honestly the serial.print stuff has come from copying code in from an example script and is more or less redundant
most of this has been made by trying to merge the two example scripts together to use this temperature probe with the code for the app - i will try to find both original scripts again and post them

it has been several months since i started this project but as far as i remember that line is where the device sent a value as a sensor reading to the app but i will go back and double check on this

Thanks again

Please answer to the first question of post 2

the code is printing to the serial monitor but the temperature reading being given is -127

Blockquote⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮Dallas Temperature IC Control Library Demo
Requesting temperatures...DONE
Temperature is: -127.00Send data by schedule.
PubSubClient connecting to: a3k0qrpvxv7791-ats.iot.us-west-1.amazonaws.com.
Not connected. Wait. State is: -2
SSL error code: 62
Chain could not be linked to a trust anchor.

#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();
}

This is the example code from the zentser website I think I am correct in saying the

sensors[0].value

is setting up what value to send to the app but I think I have an issue with how I am providing this reading to the code

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