0
votes

i have multiple temperature and humidity sensors conected to arduino board mega(DHT22, DS18b20,...) In my program i get the temperature from the sensors and i put them into datastream and send it to Xiviely, and here comes the problem. When i put the fake float number into the stream (e.g. float number 100.12) i got client reply "xivelyclient.put returned 200" witch is ok, but when i put real data (temperature or humidity) from the sensors in the datastream i dont get answer from Xively. (the program stops there and sometimes after few minutes Xively returns -3 or something like that).

Code which works fine:

/*OUTSIDE ANY METHOD*/
XivelyDatastream datastreamsRekuperator[] = {
XivelyDatastream("01-T-zunanji", strlen("01-T-zunanji"), DATASTREAM_FLOAT),
XivelyDatastream("02-T-notranji", strlen("02-T-notranji"), DATASTREAM_FLOAT),
XivelyDatastream("03-T-odvod", strlen("03-T-odvod"), DATASTREAM_FLOAT),
XivelyDatastream("04-T-vpih", strlen("04-T-vpih"), DATASTREAM_FLOAT),
XivelyDatastream("05-T-kanal", strlen("05-T-kanal"), DATASTREAM_FLOAT),
XivelyDatastream("06-V-zunanji", strlen("06-V-zunanji"), DATASTREAM_FLOAT),
XivelyDatastream("07-V-notranji", strlen("07-V-notranji"), DATASTREAM_FLOAT),
XivelyDatastream("08-V-odvod", strlen("08-V-odvod"), DATASTREAM_FLOAT),
XivelyDatastream("09-V-vpih", strlen("09-V-vpih"), DATASTREAM_FLOAT),
XivelyDatastream("10-V-kanal", strlen("10-V-kanal"), DATASTREAM_FLOAT),
};

XivelyFeed rekuperatorFeed(XXXXXXXXX, datastreamsRekuperator, 10/* number of datastreams */);

/*IN LOOP METHOD*/
datastreamsRekuperator[0].setFloat(100.12);
datastreamsRekuperator[1].setFloat(100.12);
datastreamsRekuperator[2].setFloat(100.12);
datastreamsRekuperator[3].setFloat(100.12); 
datastreamsRekuperator[4].setFloat(100.12);
datastreamsRekuperator[5].setFloat(100.12);
datastreamsRekuperator[6].setFloat(100.12);
datastreamsRekuperator[7].setFloat(100.12); 
datastreamsRekuperator[8].setFloat(100.12);
datastreamsRekuperator[9].setFloat(100.12);

Serial.println("Uploading it to Xively");
int retRekuperator = xivelyclient.put(rekuperatorFeed, xivelyKey);
Serial.print("xivelyclient.put returned ");
Serial.println(retRekuperator);

Code which don't work:

/*OUTSIDE ANY METHOD*/
XivelyDatastream datastreamsRekuperator[] = {
XivelyDatastream("01-T-zunanji", strlen("01-T-zunanji"), DATASTREAM_FLOAT),
XivelyDatastream("02-T-notranji", strlen("02-T-notranji"), DATASTREAM_FLOAT),
XivelyDatastream("03-T-odvod", strlen("03-T-odvod"), DATASTREAM_FLOAT),
XivelyDatastream("04-T-vpih", strlen("04-T-vpih"), DATASTREAM_FLOAT),
XivelyDatastream("05-T-kanal", strlen("05-T-kanal"), DATASTREAM_FLOAT),
XivelyDatastream("06-V-zunanji", strlen("06-V-zunanji"), DATASTREAM_FLOAT),
XivelyDatastream("07-V-notranji", strlen("07-V-notranji"), DATASTREAM_FLOAT),
XivelyDatastream("08-V-odvod", strlen("08-V-odvod"), DATASTREAM_FLOAT),
XivelyDatastream("09-V-vpih", strlen("09-V-vpih"), DATASTREAM_FLOAT),
XivelyDatastream("10-V-kanal", strlen("10-V-kanal"), DATASTREAM_FLOAT),
};

XivelyFeed rekuperatorFeed(XXXXXXXXX, datastreamsRekuperator, 10/* number of datastreams */);

/*IN LOOP METHOD*/
datastreamsRekuperator[0].setFloat(getTemperatureDHT22(6));
datastreamsRekuperator[1].setFloat(getTemperatureDHT22(7));
datastreamsRekuperator[2].setFloat(getTemperatureDHT22(8));
datastreamsRekuperator[3].setFloat(getTemperatureDHT22(9)); 
datastreamsRekuperator[4].setFloat(getTemperatureDHT22(10));
datastreamsRekuperator[5].setFloat(getHumidityDHT22(6));
datastreamsRekuperator[6].setFloat(getHumidityDHT22(7));
datastreamsRekuperator[7].setFloat(getHumidityDHT22(8));    
datastreamsRekuperator[8].setFloat(getHumidityDHT22(9));
datastreamsRekuperator[9].setFloat(getHumidityDHT22(10));

Serial.println("Uploading it to Xively");
int retRekuperator = xivelyclient.put(rekuperatorFeed, xivelyKey);
Serial.print("xivelyclient.put returned ");
Serial.println(retRekuperator);

The getTemperature method (getHumidity is created on the same way):

float getTemperatureDHT22(int DHT22_PIN){
  DHT22 myDHT22(DHT22_PIN);
  delay(2000); //DHT22 can be read every 2s
  DHT22_ERROR_t errorCode = myDHT22.readData();
  if(errorCode==DHT_ERROR_NONE){
      Serial.print("Pin ");
      Serial.print(DHT22_PIN);
      Serial.print(" ");
      Serial.println(myDHT22.getTemperatureC());
      return myDHT22.getTemperatureC();
  }
  else{
      Serial.print("Pin ");
      Serial.print(DHT22_PIN);
      Serial.println(" No data");
      return 0.0;
  }
}

The only difference in code is that "100.12" is replaced with "getTemperatureDHT22(PIN)" or "getHumidityDHT22(PIN)".

Reply from the working code:

Uploading it to Xively
xivelyclient.put returned 200

Reply from the non working code:

Pin 6 17.40
Pin 7 20.70
Pin 8 19.90
Pin 9 16.40
Pin 10 19.10
Pin 6 50.10
Pin 7 52.50
Pin 8 51.20
Pin 9 44.00
Pin 10 45.20
Uploading it to Xively
/*HERE THE PROGRAM STOPS*/

Does anybody know what it could go wrong? I would realy be thankfull for any reply and any suggestion. Thank you.

1

1 Answers

1
votes

I see that inside of your

float getTemperatureDHT22(int DHT22_PIN) {

function, you are aware that the DHT22 requires waiting 2 seconds before taking consecutive reads, and you do account for that at the beginning of the procedure. However, at the bottom of the

if(errorCode==DHT_ERROR_NONE) {

block, you are making two consecutive reads of the DHT22 without any delay:

  ...
  Serial.println(myDHT22.getTemperatureC());
  return myDHT22.getTemperatureC();
}

Either make one call, saving the return value in a local variable, and print and return that variable, or just comment out the Serial.println(myDHT22.getTemperatureC()); and see how you make out.

Hopefully that helps.

EDIT:

===============

Some clarification is required because this could be library dependent. In the version of the DHT22 library that I'm using, the only call that actually interrogates the sensor for the above code would be

      DHT22_ERROR_t errorCode = myDHT22.readData();

The 2 second delay requirement between consecutive calls relates to calls to that method. In contrast, calls to getTemperatureC() and getHumidity() are only returning DHT22 class variables. Those calls are not interrogating the sensor and do not require a delay, again in the library that I am now using.

Check your version of the DHT22.cpp library file to be absolutely sure. If the getTemperatureC() does nothing except return _lastTemperature; then consecutive calls to getTemperatureC() and getHumidity() do not require additional delays. Just remember that they will not be updated until the next call to readData().

===============

Considerations for Ethernet shield and DHT22 pin selection:

The next thing I noticed is that you are using Pin 10 for one of your sensors. You stated you are using a Mega. Although you don't specify, I'm going to assume you are using Rev 3 of the Mega, and the Arduino Ethernet shield (wired) based on the Wiznet W5100 ethernet chip (hopefully this assumption is correct, as the following is applicable to that hardware). Requirements of the Ethernet shield on the Uno and Mega 2560 R3 are:

On both boards, pin 10 is used to select the W5100 and pin 4 for the SD card. These pins cannot be used for general I/O. On the Mega, the hardware SS pin, 53, is not used to select either the W5100 or the SD card, but it must be kept as an output or the SPI interface won't work. http://arduino.cc/en/Main/ArduinoEthernetShield

Therefore, the next things to try next are

  1. Move the DHT22 off of pin 10
  2. Set pin 53 as an output
  3. If using the above Ethernet shield, and you are not using an SD card, set pin 4 to output and write it high (see link above)

Then please report back.