Instantly share code, notes, and snippets.

Embed
What would you like to do?
DHT22 Sketch for Pinoccio Scout
// 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