Hi all,
Quite the noob with Adruino programming but learning little bits as I go. Hoping to get a little more help here.
I've got this set up working a treat (
http://www.freetronics.com/pages/online-thermometer) and use it in another webpage of mine which has other home automation on it. I want to continue to do this but also have a feed to Pachube.
I have added all the relevant code from the working online thermometer sketch to the example Pachube sketch I got here:
http://community.pachube.com/node/112#inputoutputI have verified and uploaded the sketch to my Adruidno and it continues to perform the online thermometer function which is printing the correct degrees celcius to a webpage served by the Arduino. The only problem is I have no idea what to put after the pachube_in_out(); function.
See my sketch below, hopefully you might be able to help me out. I figure I'm already getting the correct temp reading printing to the webpage so there can't be much more I need to send it to Pachube on a regular basis. I've already added all the Pachube feed details.
/* ==============================
* 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 <SPI.h>
#include <Ethernet.h>
#include <WebServer.h>
#include <string.h>
#undef int() // needed by arduino 0011 to allow use of stdio
#include <stdio.h> // for function sprintf
// No-cost stream operator as described at
// http://sundial.org/arduino/?page_id=119
template<class T>
inline Print &operator <<(Print &obj, T arg)
{ obj.print(arg); return obj; }
#define SHARE_FEED_ID 14512 // this is your Pachube feed ID that you want to share to
#define REMOTE_FEED_ID 13743 // this is the ID of the remote Pachube feed that you want to connect to
#define REMOTE_FEED_DATASTREAMS 2 // 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 "842fdd1657c26c8f3bdc680cb9fdcdefe4ebc74c509f12085ed35f64beb54fd2" // fill in your API key
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEE, 0xEE, 0xEF };
static uint8_t ip[] = { 192, 168, 1, 2 };
static uint8_t myPort = 80; // Listen port for tcp/www (range 1-254)
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
/* This creates an instance of the webserver. By specifying a prefix
* of "/", all pages will be at the root of the server. */
#define PREFIX "/"
WebServer webserver( PREFIX, myPort );
// Specify data pins for connected DS18B20 temperature sensors
#define SENSOR_A 14
#define SENSOR_B 15
#define SENSOR_C 16
#define SENSOR_D 17
#define SENSOR_E 18
#define SENSOR_F 19
// Function prototypes to trick the Arduino pre-processor into
// allowing call-by-reference
void sendTemperatureValues( WebServer &server);
void sendAboutPage( WebServer &server);
void sendFormButtons( WebServer &server);
/**
* Default page to return to browser
*/
void valuesCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
server.httpSuccess();
sendTemperatureValues( server );
sendFormButtons( server );
}
/**
* Default page to return to browser
*/
void aboutCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
server.httpSuccess();
sendAboutPage( server );
sendFormButtons( server );
}
/**
* Configure Ethernet shield
*/
void setup(){
Serial.begin(38400);
Ethernet.begin(mac, ip);
webserver.begin();
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
webserver.setDefaultCommand( &valuesCmd );
webserver.addCommand( "values", &valuesCmd );
webserver.addCommand( "about", &aboutCmd );
// Set up the data pins for communication with DS18B20 sensors
digitalWrite(SENSOR_A, LOW);
pinMode(SENSOR_A, INPUT);
digitalWrite(SENSOR_B, LOW);
pinMode(SENSOR_B, INPUT);
digitalWrite(SENSOR_C, LOW);
pinMode(SENSOR_C, INPUT);
digitalWrite(SENSOR_D, LOW);
pinMode(SENSOR_D, INPUT);
digitalWrite(SENSOR_E, LOW);
pinMode(SENSOR_E, INPUT);
}
void loop()
{
webserver.processConnection();
// 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.:
What do I put here?
// 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.
And here?
}
Continued in the next post.
Edit: spelling, more info.