0

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.

Hugo
  • 3
  • 2

1 Answers1

1

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.

avr6130
  • 26
  • 3
  • Omg, thank you, i didn't notice it at all... Should i delay 2 sec after the call "DHT22_ERROR_t errorCode = myDHT22.readData();" or this call isn't directly a sensor call? – Hugo Mar 26 '14 at 11:28
  • I tried with usage of local variable: float temp = myDHT22.getTemperatureC(); and then i used that variable, but it still doesn't get the return of xively site, the same problem as i wrote up there. – Hugo Mar 26 '14 at 11:39
  • Hugo, I began adding comments here but had too much information so I deleted the comment and made significant changes above. Please see my original post for additions. – avr6130 Mar 28 '14 at 15:03
  • Thank you, you assume correct. But my problem is not in reading sensors, the problem is that i dont recieve code 200 OK from Xively. I am printing out the temperature and humidity out of the sensors and the reading goes well. When i post "fake" data to Xively it allways returns me 200 but when i post real data to Xively it doesnt returns me anything. And i noticed something too, when i post 3 real temperatures and 7 "fake" ones in the same stream, i get the response (200), but when i put 4 of the real temperatures and 6 "fake" ones, then again, i dont get the response... – Hugo Apr 02 '14 at 15:31
  • You're welcome, my pleasure. I'm not suggesting you will have problems reading sensors (from your comment), rather that **the sensor on pin 10 will interfere with Ethernet communications** (the problem you appear to be having). Pardon me for pointing it out again but you didn't say in your response so have you made changes to your connections, no longer using pin 10 (and set pin 4 and 53 accordingly)? I have a different suggestion regarding variable scope, global and stack space but I'll wait until you respond back, if you're interested. Maybe we'll get to the bottom of this. – avr6130 Apr 02 '14 at 17:27
  • Hi, first of all, sorry for such a delay. I did what you suggested in previous post (DHT22 from pin 10 moved to pin 5, set pin 53 and 4 as output) and it worked, so apparently pin 10 did interfere with Ethernet, thank you so much! – Hugo Apr 25 '14 at 11:07
  • Now i got only one more problem to solve, when i connect 8 more DS18b20 sensors on pin 3 it gets sensor addresses and prints it, just the temperatures i get are all "4095.94" (which cannot be real). Also when i post those values to Xively, i get error -403. Any idea? – Hugo Apr 25 '14 at 11:59
  • Hugo. Glad your original problem is solved. What I respectfully suggest you do is to up-vote the answer and mark this topic as resolved (don't know if that is two distinct actions). That way future visitors will see that the information is accurate and helpful. If possible, you also may want to change the original question and add the words "Mega" and "Ethernet Shield" (something like **Arduino Mega, ethernet shield, and sending data to Xively** because that was your actual problem - and resolution. This again will help future visitors. – avr6130 Apr 27 '14 at 20:05
  • Because your next question is completely unrelated, I suggest you begin a new topic, asking about using multiple DS18B20 sensors, because your issue probably doesn't relate to Xively. Otherwise very few people will find it buried in the comments. And to get you started, what I suggest you do first is to get one working, then add one or two. Those sensors are the most sensitive devices for Arduino that I've personally used - blown up two of them so far :-). In fact, I've switched to thermistors. – avr6130 Apr 27 '14 at 20:09
  • Thank you again, I checked the answer as correct, i am sort of new here so i didn't know that i have to do that :) I allready connected 15 of DS18b20 sensors on that, same board, and they work fine, just those 8 are returning such a funny temperature :) ok thank you again, i will try to solve it on my own and if i wont make it, i ll post a new question. – Hugo Apr 27 '14 at 21:44