Created
July 19, 2010 07:38
-
-
Save solon/481107 to your computer and use it in GitHub Desktop.
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
/* | |
* light_mirror.pde | |
* Turns on an LED when it's bright in a remote location and vice versa | |
* Remote location is set to the Pachube office feed but this can easily be changed | |
*/ | |
/* ============================== | |
* This code, which assumes you're using the official Arduino Ethernet shield, | |
* updates a Pachube feed with your analog-in values and grabs values from a Pachube | |
* feed - basically it enables you to have both "local" and "remote" sensors. | |
* | |
* Tested with Arduino 14 | |
* | |
* Pachube is www.pachube.com - connect, tag and share real time sensor data | |
* code by usman (www.haque.co.uk), may 2009 | |
* copy, distribute, whatever, as you like. | |
* | |
* v1.1 - added User-Agent & fixed HTTP parser for new Pachube headers | |
* and check millis() for when it wraps around | |
* | |
* =============================== */ | |
#include <Ethernet.h> | |
#include <string.h> | |
#undef int() // needed by arduino 0011 to allow use of stdio | |
#include <stdio.h> // for function sprintf | |
#define SHARE_FEED_ID 8909 // this is your Pachube feed ID that you want to share to | |
#define REMOTE_FEED_ID 504 // 504 is the ID of the Pachube office feed http://www.pachube.com/feeds/504 ... light level ID = 1 | |
#define REMOTE_FEED_DATASTREAMS 7 // make sure that remoteSensor array is big enough to fit all the remote data streams | |
#define UPDATE_INTERVAL 10000 // if the connection is good wait 10 seconds before updating again - should not be less than 5 | |
#define RESET_INTERVAL 10000 // if connection fails/resets wait 10 seconds before trying again - should not be less than 5 | |
#define PACHUBE_API_KEY "YOUR_API_KEY_HERE" // fill in your API key | |
byte mac[] = { 0xCC, 0xAC, 0xBE, 0xEF, 0xFE, 0x91 }; // make sure this is unique on your network | |
byte ip[] = { 192, 168, 1, 144 }; // no DHCP so we set our own IP address | |
byte remoteServer[] = { 209,40,205,190 }; // pachube.com | |
float remoteSensor[REMOTE_FEED_DATASTREAMS]; // we know that feed 256 has floats - this might need changing for feeds without floats | |
int ledPin = 9; | |
void setup() | |
{ | |
Serial.begin(57600); | |
setupEthernet(); | |
pinMode(ledPin, OUTPUT); | |
digitalWrite(ledPin, LOW); | |
} | |
void loop() | |
{ | |
// call 'pachube_in_out' at the beginning of the loop, handles timing, requesting | |
// and reading. use serial monitor to view debug messages | |
pachube_in_out(); | |
// then put your code here, you can access remote sensor values | |
// by using the remoteSensor float array, e.g.: | |
Serial.print("Remote light level = "); | |
Serial.println(remoteSensor[1]); // 1 = ID of sensor we want to read (light level) | |
Serial.print("Local light level = "); | |
Serial.println(analogRead(0)); | |
// you can have code that is time sensitive (e.g. using 'delay'), but | |
// be aware that it will be affected by a short pause during connecting | |
// to and reading from ethernet (approx. 0.5 to 1 sec). | |
// e.g. this code should carry on flashing regularly, with brief pauses | |
// every few seconds during Pachube update. | |
if (remoteSensor[1] > 500) { | |
digitalWrite(ledPin, HIGH); | |
} else { | |
digitalWrite(ledPin, LOW); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment