Posting Arduino Home Sensors to phant.io

I have used Xively and its predecessors for several years to post some of my home data; inside temperature & humidity, furnace on/off, state of AC power to house, as well as outside weather. Nothing wrong with Xively. It works great. But recently I decided to look for alternatives and tried both Temboo and PushingBox to update a Google spreadsheet. Those also worked nicely. In fact it was much easier to retrieve data from my Google spreadsheet than Xively.

In any case, I decided to try Sparkfun’s new data service; phant.io. It also works great, but what separates it from the others is how easy it is to setup and use. It’s also very easy to get a csv file of uploaded data and open it on your local computer. Numbers are automatically entered as numbers saving even more time. I also like the fact that the time of the post is automatically posted with the data, since my Arduino doesn’t have time of day.

I modified Sparkfun’s Arduino Phant_Ethernet.ino sketch written by Jim Lindblom for my purposes. Here’s a link to my HomeStatus2 URL: https://data.sparkfun.com/streams/n11XMdRY3dCNV857aV9b

Here’s the working code. The sensor formulas would need to be adjusted to match your sensors. I’m using a Phidget 1125 Temp/humidity sensor on my Uno.

#include <SPI.h>

#include <Ethernet.h>

#include <Progmem.h>

byte mac = { 0xDE, 0xBD, 0xBE, 0xEF, 0xFE, 0xED };

char server = “data.sparkfun.com”;

IPAddress ip(192,168,1,180);

EthernetClient client;

const String publicKey = “n11XMdRY3dCNV857aV9b”;

const String privateKey = “enter your private key here”;

const byte NUM_FIELDS = 4;

const String fieldNames[NUM_FIELDS] = {“humidity”, “temp”, “power”, “hvac”};

String fieldData[NUM_FIELDS];

const int tempPin = 2;

const int humidPin = 3;

const int powerPin = 4;

const int hvacPin = 5;

void setup()

{

Serial.begin(115200);

pinMode(powerPin, INPUT_PULLUP);

pinMode(hvacPin, INPUT_PULLUP);

setupEthernet();

}

void loop()

{

int humidVal = analogRead(humidPin);

humidVal = ((humidVal * 5.0/5.1) * 0.1906) - 40.2;

int tempVal = analogRead(tempPin);

tempVal = ((((tempVal * 5.0/5.1) * 0.2222) - 61.11) * 9.0/5.0) + 32.0;

fieldData[0] = String(humidVal);

fieldData[1] = String(tempVal);

fieldData[2] = String(digitalRead(powerPin));

fieldData[3] = String(digitalRead(hvacPin));

Serial.println(“Posting to data.sparkfun.com/streams/n11XMdRY3dCNV857aV9b”);

postData();

delay(60000); // post every 60 seconds

}

void postData()

{

if (client.connect(server, 80))

{

client.print(“GET /input/”);

client.print(publicKey);

client.print(“?private_key=”);

client.print(privateKey);

for (int i=0; i<NUM_FIELDS; i++)

{

client.print(“&”);

client.print(fieldNames*);*
client.print(“=”);
client.print(fieldData);
}
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println(“Connection: close”);
client.println();
}
else
{
Serial.println(F(“Connection failed”));
}
while (client.connected())
{
if ( client.available() )
{
char c = client.read();
Serial.print(c);
}
}
Serial.println();
client.stop();
}
void setupEthernet()
{
Serial.println(“Setting up Ethernet…”);
if (Ethernet.begin(mac) == 0)
{
Serial.println(F(“Failed to configure Ethernet using DHCP”));
Ethernet.begin(mac, ip);
}
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
delay(1000);
}

Cool project!

You might be interested in using imp.guru to visualize your data and receive real time streaming updates. Imp.guru also shortens your url so that it can be easily remembered and shared with friends. Check out your stream here:

http://imp.guru/ft

I would love to hear your feedback on the site as well since it sounds like you have been using many other services.