I'm trying to build a simple sensor upload to Pachube. I've been troubleshooting this for awhile, and it seems that the problem is with the DHT22 readings, not with the push to Pachube.
I'm reading the data from the DHT22 correctly:
+++++++++++++++++++++++++++++++++++++++++++++++++
OK, 47.2, 26.0
sync status code <OK == 200> => 200
data count=> 4
,
0,654
1,712
2,1
3,1
That's my serial output.
The line after the "+"s is the checksum and humidity and temperature read from the DHT22. The two lines below that are link messages regarding my connection to Pachube. The final 5 lines deal with the data being sent to Pachube. The first two pieces (0 and 1) of data are analog reads from a light sensor and a motion sensor connected to analog lines. The two items following that (2,3) are the temperature and humidity reads from the DHT22.
I can read the DHT22 in the first portion of my code. I cannot read them in the second portion of my code. Why?
I've tried various methods of placing the initial DHT22 data into variables, and printing those variables. Inevitably the serial monitor prints out a "1" when it is trying to send the data feed to Pachube.
Am I wrong? Am I attacking this the wrong way, and instead should be looking at the Pachube end of things?
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Sensors: DHT22 dataline connected to pin 7. Suggested 4.7k Pull-up used
Analog Pin 0 is a photocell to detect light levels
Analog Pin 1 is a motion sensor
* Based on code:
* Created 22 April 2011
* By Jeffrey Sun
* http://code.google.com/p/pachubelibrary/
* and
* robtillart
* http://arduino.cc/forum/index.php/topic,58531.0.html
* http://arduino.cc/playground/Main/DHTLib
*/
#include <dht.h>
#include "ERxPachube.h"
#include <Ethernet.h>
#include <SPI.h>
dht DHT;
#define DHT22_PIN 7
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x21, 0xE3 };
byte ip[] = { 192, 168, 1, 20 }; // no DHCP so we set our own IP address
int Temp;
int Humidity;
int OldTemp = Temp;
int OldHumidity = Humidity;
#define PACHUBE_API_KEY "PACHUBE API KEY" // fill in your API key PACHUBE_API_KEY
#define PACHUBE_FEED_ID 34665 // fill in your feed id
ERxPachubeDataOut dataout(PACHUBE_API_KEY, PACHUBE_FEED_ID);
void PrintDataStream(const ERxPachube& pachube);
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
dataout.addData(0);
dataout.addData(1);
dataout.addData(2);
dataout.addData(3);
}
void loop() {
Serial.println("+++++++++++++++++++++++++++++++++++++++++++++++++");
float fSensorData = 15.23;
int chk = DHT.read22(DHT22_PIN);
switch (chk)
{
case 0: Serial.print("OK,\t"); break;
case -1: Serial.print("Checksum error,\t"); break;
case -2: Serial.print("Time out error,\t"); break;
default: Serial.print("Unknown error,\t"); break;
}
// DISPLAY DATA
Temp = (DHT.temperature, 1);
Humidity = (DHT.humidity, 1);
//Serial.print(Temp);
//Serial.print(",\t");
//Serial.println(Humidity);
Serial.print(DHT.humidity, 1);
Serial.print(",\t");
Serial.println(DHT.temperature, 1);
dataout.updateData(0, analogRead(0));
dataout.updateData(1, analogRead(1));
dataout.updateData(2, (DHT.temperature,1));
dataout.updateData(3, (DHT.humidity,1));
int status = dataout.updatePachube();
Serial.print("sync status code <OK == 200> => ");
Serial.println(status);
PrintDataStream(dataout);
OldTemp = Temp;
OldHumidity = Humidity;
delay(30000);
}
void PrintDataStream(const ERxPachube& pachube)
{
unsigned int count = pachube.countDatastreams();
Serial.print("data count=> ");
Serial.println(count);
Serial.println("<id>,<value>");
for(unsigned int i = 0; i < count; i++)
{
Serial.print(pachube.getIdByIndex(i));
Serial.print(",");
Serial.print(pachube.getValueByIndex(i));
Serial.println();
}
}