Last active
August 29, 2015 14:09
-
-
Save AlexMikhalev/a49d35c6a18ffe74a266 to your computer and use it in GitHub Desktop.
DHT22 Sketch for Pinoccio Scout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Working DHT 22 sketch for Pinoccio | |
#include <SPI.h> | |
#include <Wire.h> | |
#include <Scout.h> | |
#include <Shell.h> | |
#include <GS.h> | |
#include <bitlash.h> | |
#include <lwm.h> | |
#include <js0n.h> | |
extern "C" { | |
#include "key/key.h" | |
#include "util/memdebug.h" | |
#include "util/StringBuffer.h" | |
} | |
#include "dht.h" | |
#define DHT22_PIN 4 | |
dht odht; | |
void setup() { | |
// Serial.begin(115200); | |
Scout.setup(); | |
// Add Bitlash functions | |
addBitlashFunction("dht22.temperature", (bitlash_function)temperature); | |
addBitlashFunction("dht22.humidity", (bitlash_function)humidity); | |
addBitlashFunction("dht22.report", (bitlash_function)reportToHQ); | |
} | |
void loop() { | |
Scout.loop(); | |
} | |
// Bitlash function to retrieve temperature | |
numvar temperature(void){ | |
// Read DHT Values | |
odht.read(DHT22_PIN); | |
return (numvar)odht.temperature; | |
} | |
// Bitlash function to retrieve humidity | |
numvar humidity(void){ | |
// Read DHT Values | |
odht.read(DHT22_PIN); | |
return (numvar)odht.humidity; | |
} | |
static numvar reportToHQ(void){ | |
// Report temperature and humidity to HQ | |
odht.read(DHT22_PIN); | |
Serial.println(odht.temperature); | |
Serial.println(odht.humidity); | |
char buf[64]; | |
sprintf(buf, "{\"dht22.temperature\":%i, \"dht22.humidity\":%i}", (int)odht.temperature, (int)odht.humidity); | |
Shell.eval("hq.report", "dht22", buf); | |
speol(buf); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment