Double ds18b20

#1

Hello everyone, my dashboard with two dht22 has stopped working for the second time.
Not bad I think it’s cayenne that I no longer accept that configuration on a free account. understandable.
I want to try with two ds18b20, I tried to modify this sketch but it does not work. Please tell me where I’m wrong?

#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <OneWire.h>
#include <DallasTemperature.h>
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";


#define SENSOR_PIN 2 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define VIRTUAL_CHANNEL 1

#define SENSOR_PIN7 7 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define VIRTUAL_CHANNEL 2

OneWire oneWire(SENSOR_PIN);
OneWire oneWire7(SENSOR_PIN7);
DallasTemperature sensors(&oneWire);
DallasTemperature sensors7(&oneWire7);

void setup()
{
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID);
  sensors.begin();
  sensors7.begin();
}

void loop()
{
  Cayenne.loop();
}

// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL)
{
  // Send the command to get temperatures.
  sensors.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Channel.
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
  //Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL, sensors.getTempFByIndex(0));

  // Send the command to get temperatures.
  sensors7.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Channel.
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors7.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
  //Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL, sensors.getTempFByIndex(0));
}

Thank you very much

#2

there is no limit for the free account and it should work without any issue. can you share me the serial monitor output of your DHT22 code so that we can see what the issue is here.

#3

Thanks for your time. Now I have disassembled the dht22 to try with the ds18b20.

Suddenly, only one sensor data was updated in the dashboard. Outpout of the serial monitor instead displayed and updated both sensors, the code is what you had corrected me.

So definitely something has changed from you. As I said it’s not serious, nothing vital is monitored by those sensors.

Thank you

#4

there is nothing changed from cayenne side. it is only some issue at your end code. if you can re-connect them and share the serial monitor we can rule out the issue.

#5

All right, we’re gonna take some time.
As soon as he reconnected the dht22 we’re adjourned. Thank you

1 Like
#6

Hi, I managed to reassemble the dht22, his is what appears in the serial monitor

17:30:52.496 -> Humidity: 47.90 % Temperature: 18.00 *C 64.40 *F Heat index: 17.11 *C 62.79 *F
17:30:52.596 -> Humidity7: 39.00 % Temperature7: 17.70 *C 63.86 *F Heat index: 16.54 *C 61.78 *F
17:31:02.700 -> Humidity: 47.70 % Temperature: 18.00 *C 64.40 *F Heat index: 17.10 *C 62.78 *F
17:31:02.766 -> Humidity7: 38.90 % Temperature7: 17.70 *C 63.86 *F Heat index: 16.54 *C 61.77 *F
17:31:12.901 -> Humidity: 47.50 % Temperature: 18.10 *C 64.58 *F Heat index: 17.21 *C 62.97 *F
17:31:13.000 -> Humidity7: 39.10 % Temperature7: 17.70 *C 63.86 *F Heat index: 16.55 *C 61.78 *F
17:31:23.107 -> Humidity: 47.60 % Temperature: 18.10 *C 64.58 *F Heat index: 17.21 *C 62.98 *F
17:31:23.174 -> Humidity7: 39.00 % Temperature7: 17.70 *C 63.86 *F Heat index: 16.54 *C 61.78 *F
17:31:33.279 -> Humidity: 47.50 % Temperature: 18.00 *C 64.40 *F Heat index: 17.10 *C 62.77 *F
17:31:33.379 -> Humidity7: 39.50 % Temperature7: 17.70 *C 63.86 *F Heat index: 16.56 *C 61.80 *F
17:31:43.483 -> Humidity: 47.60 % Temperature: 18.10 *C 64.58 *F Heat index: 17.21 *C 62.98 *F
17:31:43.582 -> Humidity7: 39.30 % Temperature7: 17.70 *C 63.86 *F Heat index: 16.55 *C 61.79 *F

Here’s the code that you kindly corrected for me

But in the dashboard I only see channels 1 and 2 :frowning: (Sorry, I can’t add a screenshot.)

Thanks a lot

#7

this shows that you are getting the temperature from both the DHT22. can you share the code used for this.
Also, share the code you used to send data to cayenne and is not working.

#8

Thanks for the quick reply

this is the code in use

/*
This example shows how to connect to Cayenne using an Ethernet W5100 shield and send/receive sample data.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:
1. Set the Cayenne authentication info to match the authentication info from the Dashboard.
2. Compile and upload the sketch.
3. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
*/

//#define CAYENNE_DEBUG       // Uncomment to show debug messages
//#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>

//DTH
#include "DHT.h"

DHT dht(2, DHT22);
DHT dht7(7, DHT22);
#define DTH_hum_Virtual_Channel 1
#define DTH_tempC_Virtual_Channel 2
//#define DTH_tempF_Virtual_Channel 3
//#define DTH_hic_Virtual_Channel 4
//#define DTH_hif_Virtual_Channel 5
#define DTH7_hum_Virtual_Channel 6
#define DTH7_tempC_Virtual_Channel 7
//#define DTH7_tempF_Virtual_Channel 8
//#define DTH7_hic_Virtual_Channel 9
//#define DTH7_hif_Virtual_Channel 10
unsigned long lastMillis_dht = 0;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";

void setup() {
    //DTH
  dht.begin();
  dht7.begin();
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID);
}

void loop() {
  Cayenne.loop();
  //DTH
  if (millis() - lastMillis_dht > 30000) {
    lastMillis_dht = millis();
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    float h = dht.readHumidity();
    // Read temperature as Celsius (the default)
    float t = dht.readTemperature();
    // Read temperature as Fahrenheit (isFahrenheit = true)
    float f = dht.readTemperature(true);

    // Check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t) || isnan(f)) {
      Serial.println("Failed to read from DHT sensor!");
      return;
    }

    // Compute heat index in Fahrenheit (the default)
    float hif = dht.computeHeatIndex(f, h);
    // Compute heat index in Celsius (isFahreheit = false)
    float hic = dht.computeHeatIndex(t, h, false);
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.print(" *C ");
    Serial.print(f);
    Serial.print(" *F\t");
    Serial.print("Heat index: ");
    Serial.print(hic);
    Serial.print(" *C ");
    Serial.print(hif);
    Serial.println(" *F");
    Cayenne.virtualWrite(DTH_hum_Virtual_Channel, h, "rel_hum", "p");
    Cayenne.virtualWrite(DTH_tempC_Virtual_Channel, t, "temp", "c");
    //Cayenne.virtualWrite(DTH_tempF_Virtual_Channel, f, "temp", "f");
    //Cayenne.virtualWrite(DTH_hif_Virtual_Channel, hif, "temp", "f");
    //Cayenne.virtualWrite(DTH_hic_Virtual_Channel, hic, "temp", "c");

   //}

    //if (millis() - lastMillis_dht > 30000) {
    //lastMillis_dht = millis();
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    float h7 = dht7.readHumidity();
    // Read temperature as Celsius (the default)
    float t7 = dht7.readTemperature();
    // Read temperature as Fahrenheit (isFahrenheit = true)
    float f7 = dht7.readTemperature(true);

    // Check if any reads failed and exit early (to try again).
    if (isnan(h7) || isnan(t7) || isnan(f7)) {
      Serial.println("Failed to read from DHT sensor!");
      return;
    }

    // Compute heat index in Fahrenheit (the default)
    float hif7 = dht7.computeHeatIndex(f7, h7);
    // Compute heat index in Celsius (isFahreheit = false)
    float hic7 = dht7.computeHeatIndex(t7, h7, false);
    Serial.print("Humidity7: ");
    Serial.print(h7);
    Serial.print(" %\t");
    Serial.print("Temperature7: ");
    Serial.print(t7);
    Serial.print(" *C ");
    Serial.print(f7);
    Serial.print(" *F\t");
    Serial.print("Heat index: ");
    Serial.print(hic7);
    Serial.print(" *C ");
    Serial.print(hif7);
    Serial.println(" *F");
    Cayenne.virtualWrite(DTH_hum_Virtual_Channel, h7, "rel_hum", "p");
    Cayenne.virtualWrite(DTH_tempC_Virtual_Channel, t7, "temp", "c");
    //Cayenne.virtualWrite(DTH_tempF_Virtual_Channel, f7, "temp", "f");
    //Cayenne.virtualWrite(DTH_hif_Virtual_Channel, hif7, "temp", "f");
    //Cayenne.virtualWrite(DTH_hic_Virtual_Channel, hic7, "temp", "c");
    }
}
  


  
#9

you are using the same variable name.
replace all places:

to:

#define DTH7_hum_Virtual_Channel_2 6 
#define DTH7_tempC_Virtual_Channel_2 7
2 Likes
#10

Sorry, just now I see your answer. I didn’t get the notification email.
Once again thank you so much for the solution.

1 Like