2 dht22


#22

After uncomment define CAYENNE_DEBUG the ide show this message

Arduino:1.8.5 (Linux), Scheda:“Arduino/Genuino Uno”

In file included from /home/pi/Arduino/libraries/CayenneMQTT/src/CayenneMQTTEthernetClient.h:21:0,
from /home/pi/Arduino/libraries/CayenneMQTT/src/CayenneMQTTEthernet.h:25,
from /home/pi/Arduino/sketch_jul15c/sketch_jul15c.ino/sketch_jul15c.ino.ino:14:
/home/pi/Arduino/libraries/CayenneMQTT/src/CayenneArduinoMQTTClient.h: In member function ‘void CayenneArduinoMQTTClient::connect()’:
/home/pi/Arduino/libraries/CayenneMQTT/src/CayenneArduinoMQTTClient.h:58:63: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
if (!NetworkConnect(&_network, CAYENNE_DOMAIN, CAYENNE_PORT)) {
^
avrdude: stk500_recv(): programmer is not responding
Lo sketch usa 25678 byte (79%) dello spazio disponibile per i programmi. Il massimo è 32256 byte.
Le variabili globali usano 1213 byte (59%) di memoria dinamica, lasciando altri 835 byte liberi per le variabili locali. Il massimo è 2048 byte.
Problema di caricamento sulla scheda. Guarda http://www.arduino.cc/en/Guide/Troubleshooting#upload per suggerimenti
avrdude: stk500_loadaddr(): (a) protocol error, expect=0x14, resp=0x5b

avrdude: stk500_paged_load(): (a) protocol error, expect=0x14, resp=0x30
avrdude: stk500_cmd(): programmer is out of sync
avr_read(): error reading address 0x0000
read operation not supported for memory “flash”
avrdude: failed to read all of flash memory, rc=-2
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x20
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x20

Questo report potrebbe essere più ricco di informazioni abilitando l’opzione
“Mostra un output dettagliato durante la compilazione”
in “File -> Impostazioni”


#23

which version of aduino ide are you using?


#24

1.8.5

It does not do anything, I do not waste any more time for myself.
Thanks so much.


#25

do you have any thing connected to RX and TX pins?


#26

Yes, on pins 2 and 3 I connected the two dht22


#27

That last error seems like an issue uploading the build to the device. You could try the suggestions at http://www.arduino.cc/en/Guide/Troubleshooting#upload. If you’ve uploaded successfully before it’s probably not an issue with the Arduino software or drivers but could be some issue with the serial port or connection. You might need to reconnect the device to your computer or perhaps reboot your machine.


#28

Thank you so much for your answer. What puzzles me are all those mistakes when compiling the sketch. I tried to delete the library folder and reinstall it from the beginning. Errors persist.

Thanks!


#29

Those all appear to be warnings, not errors. You can ignore those.


#30

Thanks!


#31

Thanks for the help you gave me up to here.
Now I would like to put two widgets to read the values ​​of the two dht22 that for now I read only through the serial monitor.
Please where do I start?

Thank you.


#32

If you are able to get the readings and show them in the Serial Monitor you should be able to send them via a Cayenne write call. For example:

CAYENNE_OUT_DEFAULT()
{
    // Send temperature in Celsius
    Cayenne.virtualWrite(0, dht.readTemperature(true),  "temp", "c"); 
    // Send relative humidity in percent
    Cayenne.virtualWrite(1, dht.readHumidity(), "rel_hum", "p");
}

Then load up the dashboard site and you should see temporary widgets appear once data is sent. You can make those widgets permanent by clicking on the plus sign.


#33

Thank you very much, unfortunately I can not program, the code to read the values of the dht I got after a long series of ctrl -c and ctrl-v … :wink: will not be the state of the art programming but it works.
Thanks for the tips on how to send the values to the dashboard, I immediately start to try.


#34

Hi, I changed the code so I get an error report in CAYENNE_IN_DEFAULT () but I do not understand where I’m wrong.
Thank you

 /*
This example shows how to connect to Cayenne using a Serial USB connection 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.

This requires the use of the Serial USB connection so you cannot use the Serial device for
printing messages. If you need to print you can use SoftwareSerial and connect another device
to read messages via the SoftwareSerial pins.

In order for this to work you must run the connection script on the machine the Arduino is connected to.
The scripts are located under the extras\scripts folder in the main library folder. This redirects the traffic
from the Arduino to the Cayenne server.

Steps:
1. Set the Cayenne authentication info to match the authentication info from the Dashboard.
2. Compile and upload this sketch.
3. Launch the connection script as described below for Windows or Linux/OSX.

Windows:
  1. Open the Windows command line (cmd.exe)
  2. Navigate to the scripts folder by typing "cd [path]", e.g.  "cd C:\Users\[YourUserName]\Documents\Arduino\libraries\CayenneMQTT\extras\scripts"
  3. Run the script by typing "cayenne-ser.bat -c COM4" (where COM4 is the Arduino serial port) and hitting Enter

Linux and OSX:
    ./cayenne-ser.sh (may need to run with sudo)
    
You can specify port, baud rate, and server endpoint like this:
    ./cayenne-ser.sh -c <serial port> -b <baud rate> -s <server address> -p <server port>

    For instance :
      ./cayenne-ser.sh -c /dev/ttyACM0 -b 9600 -s mqtt.mydevices.com -p 1883

    Run cayenne-ser.sh -h for more information

    Be sure to select the right serial port (there may be multiple).

ATTENTION!
  Do not use Serial to display any output in this sketch. It will interfere with the Serial
  USB connection. When uploading sketches the Arduino IDE may complain with "programmer is
  not responding" or "Access is denied." You will need to terminate the connection script
  before uploading new sketches since it blocks access to the Serial port. Also make sure 
  the Serial Monitor is disabled in the IDE since that can prevent the Arduino from 
  connecting to the Windows/Linux/OSX machine. If you use Visual Micro for Visual Studio make
  sure Automatic Debugging is disabled. Otherwise the Serial Monitor can interfere with the
  Serial connection.
*/

#include <CayenneMQTTSerial.h>
#include "DHT.h"

DHT dht(2,DHT22); //I define the pin to which the sensor and the type is connected
DHT dht2(3,DHT22);

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

void setup()
{
  //Baud rate can be specified by calling Cayenne.begin(username, password, clientID, 9600);
  Cayenne.begin(username, password, clientID);
}

void loop()
{
  float h = dht.readHumidity(); // Leggo il valore di umidità
  float t = dht.readTemperature(); // Leggo il valore di temperatura
  float h2 = dht2.readHumidity(); // Leggo il valore di umidità
  float t2 = dht2.readTemperature(); // Leggo il valore di temperatura
  if (isnan(t) || isnan(h)) // Se almeno uno dei due valori è NaN (Not a Number)
  if (isnan(t) || isnan(h)) // Se almeno uno dei due valori è NaN (Not a Number)
  {
    Serial.println("Impossibile leggere il sensore!");
  }
  else //altrimenti
  {
    Serial.print("Umidità_sensore1: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperatura_sensore1: ");
    Serial.print(t);
    Serial.println(" *C");
    Serial.print("Umidità_sensore2: ");
    Serial.print(h2);
    Serial.print(" %\t");
    Serial.print("Temperatura_sensore2: ");
    Serial.print(t2);
    Serial.println(" *C");
    delay(10000);
    
    
  }

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
    // Send temperature in Celsius
    Cayenne.virtualWrite(0, dht.readTemperature(true),  "temp_1_sensor", "c"); 
    Cayenne.virtualWrite(2, dht2.readTemperature(true),  "temp_2_sensor", "c"); 
    // Send relative humidity in percent
    Cayenne.virtualWrite(1, dht.readHumidity(), "rel_hum_1_sensor", "p");
    Cayenne.virtualWrite(3, dht2.readHumidity(), "rel_hum_2_sensor", "p");
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}

#35

you were missing a } in void loop(). i have made the changes to your code.

#include <CayenneMQTTSerial.h>
#include "DHT.h"

DHT dht(2,DHT22); //I define the pin to which the sensor and the type is connected
DHT dht2(3,DHT22);

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

void setup()
{
  //Baud rate can be specified by calling Cayenne.begin(username, password, clientID, 9600);
  Cayenne.begin(username, password, clientID);
}

void loop()
{
  float h = dht.readHumidity(); // Leggo il valore di umidità
  float t = dht.readTemperature(); // Leggo il valore di temperatura
  float h2 = dht2.readHumidity(); // Leggo il valore di umidità
  float t2 = dht2.readTemperature(); // Leggo il valore di temperatura
  if (isnan(t) || isnan(h)) // Se almeno uno dei due valori è NaN (Not a Number)
  if (isnan(t) || isnan(h)) // Se almeno uno dei due valori è NaN (Not a Number)
  {
    Serial.println("Impossibile leggere il sensore!");
  }
  else //altrimenti
  {
    Serial.print("Umidità_sensore1: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperatura_sensore1: ");
    Serial.print(t);
    Serial.println(" *C");
    Serial.print("Umidità_sensore2: ");
    Serial.print(h2);
    Serial.print(" %\t");
    Serial.print("Temperatura_sensore2: ");
    Serial.print(t2);
    Serial.println(" *C");
    delay(10000);
    
    
  }
}
// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
    // Send temperature in Celsius
    Cayenne.virtualWrite(0, dht.readTemperature(true),  "temp_1_sensor", "c"); 
    Cayenne.virtualWrite(2, dht2.readTemperature(true),  "temp_2_sensor", "c"); 
    // Send relative humidity in percent
    Cayenne.virtualWrite(1, dht.readHumidity(), "rel_hum_1_sensor", "p");
    Cayenne.virtualWrite(3, dht2.readHumidity(), "rel_hum_2_sensor", "p");
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}

As a beginner you should avoid using the CayenneMQTTSerial.h library and replace with CayenneMQTTEthernet.h. it will help you in debuging in future,


#36

Thanks for your help.:pray:


#37

does not work. I give up my skills are too scarce for these things.
Thank you all for your help.


#38

this code works for me without any problem. it is currently using a single DHT22, is if it works for you.

/*
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"
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#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
unsigned long lastMillis_dht = 0;

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

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

void loop() {
	Cayenne.loop();
  //DTH
  if (millis() - lastMillis_dht > 10000) {
    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");

  }
}

#39

this code works for me without any problem. it is currently using a single DHT22, is if it works for you.

Thanks


#40

When you get reading from one dht22, just duplicate for second DHT.


#41

I was able to duplicate (only partially) the reading of the second dht. Below the screen shot of my dashboard and then that of the serial monitor.
I have not yet figured out which widgets I need to insert and how to connect them to the second dht.
I tried to copy the settings of the widgets that appeared automatically in the dashboard, but I did not understand anything :slight_smile:

Schermata 2018-07-17 alle 15.28.38

[820439] Publish: topic 1, channel 4, value 20.776, subkey c, key temp
[821519] Connection ok
Humidity: 43.10 % Temperature: 21.20 *C 70.16 *F Heat index: 20.50 *C 68.90 *F
[830852] Publish: topic 1, channel 1, value 43.100, subkey p, key rel_hum
[830930] Publish: topic 1, channel 2, value 21.200, subkey c, key temp
[831005] Publish: topic 1, channel 3, value 70.160, subkey f, key temp
[831080] Publish: topic 1, channel 5, value 68.902, subkey f, key temp
[831156] Publish: topic 1, channel 4, value 20.501, subkey c, key temp
Humidity2: 45.20 % Temperature2: 21.40 *C 70.52 *F Heat index: 20.78 *C 69.40 *F
[831520] Publish: topic 1, channel 1, value 45.200, subkey p, key rel_hum
[831600] Publish: topic 1, channel 2, value 21.400, subkey c, key temp
[831675] Publish: topic 1, channel 3, value 70.520, subkey f, key temp
[831750] Publish: topic 1, channel 5, value 69.396, subkey f, key temp
[831824] Publish: topic 1, channel 4, value 20.776, subkey c, key temp
[832904] Connection ok