Montag, 16. Juli 2012

Temperatur mit Arduino und DS18B20 auf Pachube ausgeben

Hardware


 

 

 

 

 

Arduino Sketch

  /*
Pachube Data Out

Demonstrates use of the ERxPachube library. 
Push local sensor data to Pachube server.
If you don't have a Pachube account, register one first 
(http://www.pachube.com/).

To run this sketch, you need:
 1. Create a same feed as http://www.pachube.com/feeds/23408
    (A manual feed with three data streams with ids 0, 1, 2.)
 2. Use your API key to replace the space holer PACHUBE_API_KEY below. 
 3. Use your feed id to replace the space holer feed id 23408 below. 

Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13

* Created 22 April 2011
* By Jeffrey Sun
* http://code.google.com/p/pachubelibrary/

*/

#include <SPI.h>
#include <ERxPachube.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// replace the values with the MAC address of your Ethernet Shield:
byte mac[] = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa };

// provide an IP address for your Ethernet shield. The IP address below _might_ work:
byte ip[] = { 192, 168, 178, 30 };

#define PACHUBE_API_KEY "xyz" // fill in your API key PACHUBE_API_KEY
#define PACHUBE_FEED_ID 58347 // fill in your feed id

ERxPachubeDataOut dataout(PACHUBE_API_KEY, PACHUBE_FEED_ID);

void PrintDataStream(const ERxPachube& pachube);

void setup() {
  // start the ethernet connection and serial port:
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
   // Start up the Dallas library
  sensors.begin();
dataout.addData(1);
}

void loop() {
    sensors.requestTemperatures(); // Send the command to get temperatures
    dataout.updateData(1, sensors.getTempCByIndex(0));  

int status = dataout.updatePachube();

 Serial.print("sync status code <OK == 200> => ");
 Serial.println(status);

 PrintDataStream(dataout);

 delay(5000);
}


void PrintDataStream(const ERxPachube& pachube)
{
 unsigned int count = pachube.countDatastreams();
 Serial.print("data count=> ");
 Serial.println(count);

 Serial.println("<id>,<value>");
 for(unsigned int i = 0; i < count; i++)
 {
  Serial.print(pachube.getIdByIndex(i));
  Serial.print(",");
  Serial.print(pachube.getValueByIndex(i));
  Serial.println();
 }
}

Ausgabe auf Pachube

Keine Kommentare: