Monthly Archives: September 2014

flackmonkey

September 2, 2014

Well that did not take long.  I got my fist failure with the LED status indicators and only the green light is lit which narrows it down to only one line; “DHT22.acquire();”  Now I need to dig deeper into this library.  Its been a while since I checked the code there may even be an updated version.

Sensor Data – Part 2

So I have been neglecting my temperature and humidity sensor.  I haven’t had it in my filament box because the battery does not last long enough and it occasionally hangs up.  I am attempting to address the latter first.  I added 4 more leds (total of 5) to try to find where in the code it is hanging.

Here is the new config:

20140901_140221And the code:


// This #include statement was automatically added by the Spark IDE.
#include "idDHT22/idDHT22.h"
#include ;

// declaration for DHT11 handler
int idDHT22pin = D4; //Digital pin for comunications
void dht22_wrapper(); // must be declared before the lib initialization

// DHT instantiate
idDHT22 DHT22(idDHT22pin, dht22_wrapper);

char message[75]={0};
//char shortmessage[62] ={0}; //events have a limit of 63 bytes
String rmessage = "";
String smessage="";
double Humidity =0;
double degF = 0;
double degC = 0;
double DewPoint = 0;
double DewPointSlow = 0;
int result;
int greenled = 5;
int redled = 3;
int orangeled = 2;
int yellowled = 1;
int blueled = 0;

void setup()
{

	pinMode(greenled, OUTPUT);
	pinMode(redled, OUTPUT);
	pinMode(orangeled, OUTPUT);
	pinMode(yellowled, OUTPUT);
	pinMode(blueled, OUTPUT);
	
	Spark.variable("message", &message, STRING);
	//Spark.variable("Humidity", &Humidity, DOUBLE);
	//Spark.variable("degF", &degF, DOUBLE);
	//Spark.variable("degC", &degC, DOUBLE);
	//Spark.variable("DewPoint", &DewPoint, DOUBLE);
	//Spark.variable("DewPointSlow", &DewPointSlow, DOUBLE);
}
// This wrapper is in charge of calling
// mus be defined like this for the lib work
void dht22_wrapper() {
	DHT22.isrCallback();
}
void loop()
{

	digitalWrite(greenled, HIGH);   // turn the LED on (HIGH is the voltage level)
  
 
 
	//Serial.print("\nRetrieving information from sensor: ");
	//Serial.print("Read sensor: ");
	//delay(100);
	DHT22.acquire();
	digitalWrite(redled, HIGH);
	while (DHT22.acquiring());
	
	digitalWrite(orangeled, HIGH);
	result = DHT22.getStatus();
	switch (result)
	{
		case IDDHTLIB_OK:
			//Serial.println("OK");
			break;
		case IDDHTLIB_ERROR_CHECKSUM:
			//Serial.println("Error\n\r\tChecksum error");
			break;
		case IDDHTLIB_ERROR_ISR_TIMEOUT:
			//Serial.println("Error\n\r\tISR Time out error");
			break;
		case IDDHTLIB_ERROR_RESPONSE_TIMEOUT:
			//Serial.println("Error\n\r\tResponse time out error");
			break;
		case IDDHTLIB_ERROR_DATA_TIMEOUT:
			//Serial.println("Error\n\r\tData time out error");
			break;
		case IDDHTLIB_ERROR_ACQUIRING:
			//Serial.println("Error\n\r\tAcquiring");
			break;
		case IDDHTLIB_ERROR_DELTA:
			//Serial.println("Error\n\r\tDelta time to small");
			break;
		case IDDHTLIB_ERROR_NOTSTARTED:
			//Serial.println("Error\n\r\tNot started");
			break;
		default:
			//Serial.println("Unknown error");
			break;
	}
    
    digitalWrite(yellowled, HIGH);
    Humidity = DHT22.getHumidity();
    degF = DHT22.getFahrenheit();
    degC = DHT22.getCelsius();
    DewPoint = DHT22.getDewPoint();
    DewPointSlow = DHT22.getDewPointSlow();
    
    rmessage = "";
    smessage = "";
    sprintf(message, "{\"Humidity\":%3.4f,\"degF\":%3.4f,\"degC\":%3.4f,\"DewPoint\":%3.4f,\"DewPointSlow\":%3.4f}", Humidity, degF,degC,DewPoint,DewPointSlow);
    //rmessage = "{\"Humidity\":" + doubleToString(Humidity,4) + ",\"degF\":"+ doubleToString(degF,4) + ",\"degC\":" + doubleToString(degC,4) + ",\"DewPoint\":" + doubleToString(DewPoint,4) +",\"DewPointSlow\":" + doubleToString(DewPointSlow,4) + "}";
    //message = doubleToString(Humidity,4) +","+ doubleToString(degF,4) +","+ doubleToString(degC,4) +","+ doubleToString(DewPoint,4) +","+ doubleToString(DewPointSlow,4);
    //rmessage = "I hate this sooooooo much";
    
    
    //smessage = doubleToString(Humidity,4) +","+ doubleToString(degF,4) +","+ doubleToString(degC,4) +","+ doubleToString(DewPoint,4) +","+ doubleToString(DewPointSlow,4);
    //Spark.publish("TempData",smessage);
    
    digitalWrite(blueled, HIGH);
    delay (2000);
    
    digitalWrite(greenled, LOW);
    digitalWrite(redled, LOW);
    digitalWrite(orangeled, LOW);
    digitalWrite(yellowled, LOW);
    digitalWrite(blueled, LOW);    // turn the LED off by making the voltage LOW
    
	//Spark.sleep(900);
	delay(30000);
}

//Rounds down (via intermediary integer conversion truncation)
String doubleToString(double input,int decimalPlaces){
    if(decimalPlaces!=0){
        String string = String((int)(input*pow(10,decimalPlaces)));
        if(abs(input)<1){             if(input>0)
            string = "0"+string;
            else if(input<0)
            string = string.substring(0,1)+"0"+string.substring(1);
        }
        return string.substring(0,string.length()-decimalPlaces)+"."+string.substring(string.length()-decimalPlaces);
    }
    else {
        return String((int)input);
    }
}

If you are interested here is a graph of the data:

All of the data

All of the data

 

Typical Day

Typical Day