Skip to content

Instantly share code, notes, and snippets.

@toolboc
Last active August 29, 2015 14:24
Show Gist options
  • Save toolboc/16766cd13b6473c16f5f to your computer and use it in GitHub Desktop.
Save toolboc/16766cd13b6473c16f5f to your computer and use it in GitHub Desktop.
ParticleWeatherShield.ino
// This #include statement was automatically added by the Spark IDE.
#include "HTU21D/HTU21D.h"
HTU21D htu = HTU21D();
char Org[] = "ORGANIZATION_NAME";
char Disp[] = "DISPLAYNAME";
char Locn[] = "LOCATION";
void setup()
{
Serial.begin(9600);
Serial.println("HTU21D test");
while(! htu.begin()){
Serial.println("HTU21D not found");
delay(1000);
}
Serial.println("HTU21D OK");
delay(1000);
}
void loop()
{
delay(5000);
float c = htu.readTemperature();
float f = c * (9.0/5.0) + 32;
float h = htu.readHumidity();
char payload[255];
snprintf(payload, sizeof(payload), "{ \"s\":\"wthr\", \"u\":\"F\",\"l\":\"%s\",\"m\":\"Temperature\",\"o\":\"%s\",\"v\": %f,\"d\":\"%s\" }", Locn, Org, f, Disp);
Spark.publish("ConnectTheDots", payload);
delay(5000);
snprintf(payload, sizeof(payload), "{ \"s\":\"wthr\", \"u\":\"%%\",\"l\":\"%s\",\"m\":\"Humidity\",\"o\":\"%s\",\"v\": %f,\"d\":\"%s\" }", Locn, Org, h, Disp);
Spark.publish("ConnectTheDots", payload);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment