More of an update:
I added in batch of code that records how often the system is getting Checksum errors. I then left the system running while I went to sleep. Lo and Behold, the error rate is consistently 45%, and I'm frequently getting abberant readings of ~55f (~12c). The room is clearly not that cold.
I know you're not supposed to check the sensor more often than every 2 seconds. I rewrote robtillaart's code a little bit (Which is like having a 4th grader trying to follow Da Vinci, his code is much more succinct):
#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
float TempC = 0;
float Humidity = 0;
float TempF = 0;
float OldTemp = 0;
float OldHumidity = 0;
float error = 0;
float run = 0;
float errorPerc = 0;
#define PACHUBE_API_KEY "Your API Here" // 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);
delay(10000);
switch (chk)
{
case 0:
Serial.print("OK,\t");
TempC = DHT.temperature;
//Humidity = DHT.humidity;
break;
case -1:
Serial.print("Checksum error,\t");
error = error +1;
break;
case -2:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
TempF = float((TempC * float(1.8))+32);
if (TempF > 150)
{
TempF = OldTemp;
}
delay(20000);
int chk2 = DHT.read22(DHT22_PIN);
delay(10000);
switch (chk2)
{
case 0:
Serial.print("OK,\t");
//TempC = DHT.temperature;
Humidity = DHT.humidity;
break;
case -1:
Serial.print("Checksum error,\t");
error = error + 1;
break;
case -2:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
if (Humidity > 101)
{
Humidity = OldHumidity;
}
dataout.updateData(0, analogRead(0));
dataout.updateData(1, analogRead(1));
dataout.updateData(2, TempF);
dataout.updateData(3, Humidity);
int status = dataout.updatePachube();
Serial.print("sync status code <OK == 200> => ");
Serial.println(status);
PrintDataStream(dataout);
if (TempF < 150)
{
OldTemp = TempF;
}
if (Humidity < 101)
{
OldHumidity = Humidity;
}
run = run+2;
errorPerc = error / run;
Serial.print(errorPerc);
Serial.println("% errors");
delay(20000);
}
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();
}
}
I'm trying to send information my environmental conditions to Pachube every minute. That's the goal.
I'm wondering about the requests to the sensor. The
int chk = DHT.read22(DHT22_PIN);
and subsequent "case" check, is that a request from the sensor?
When I'm asking the sensor for the current humidity and temperature, are those two different requests? Should I space these out as much as possible? (This is what I did in the code above).
Or does the
int chk = DHT.read22(DHT22_PIN);
request call all the sensor information, and load it into the Arduino memory, waiting for the DHT.temperature and DHT.humidity calls?
Does anyone else have a similar error rate? That's what I'm really trying to drive down.