Go Down

Topic: Arduino ethernet board and Pachube (Read 601 times) previous topic - next topic

cotixtof

I'm using an Ethernet Arduino board.
I've downloaded a code that uses the ERxPachube library to upload data to Pachube.
In this code, I didn't use DHCP, I assign the IP address manualy.
It works but at some point, the connection is lost.
Any information about it wiuld be usefull for me.
Chris

Cylindric

You're going to have to post some code. What have you tried already?
Current Projects: Rodentometer - Hamster Endurance Moni

cotixtof

Here is the code I use :
/*
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 <Arduino.h>
#include <HardwareSerial.h>
#include <ERxPachube.h>
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0xCC, 0xBC, 0xBE, 0xEF, 0xAE, 0x91 }; // POD-1 make sure this is unique on your network
// byte mac[] = { 0xCC, 0xAC, 0xBE, 0xEF, 0xFE, 0x91 }; // POD-2 make sure this is unique on your network

byte ip[] = { 192, 168, 0, 71};                      // LUTETIUM : POD-1 no DHCP so we set our own IP address
// byte ip[] = { 192, 168, 0, 11};                      // SODIUM : POD-1 no DHCP so we set our own IP address
// byte ip[] = { 192, 168, 0, 31};                      // GALLIUM : POD-2 no DHCP so we set our own IP address

#define PACHUBE_API_KEY            "tFWNG4AjZnsefakP70ceeYgCc1A7CYDpFWmznTqe4beEcgYsKq21WkSQ_ipnFzKD_q0fXi-uM4Cj1Px9eG-bEQNik23rEapDxHjXEhOtiiPFKbR980vNWEwnSSkDeCF4" // fill in your API key PACHUBE_API_KEY

#define PACHUBE_FEED_ID            45832 // POD-1 feed id
// #define PACHUBE_FEED_ID            45831 // POD-2 feed id

ERxPachubeDataOut dataout(PACHUBE_API_KEY, PACHUBE_FEED_ID);

void PrintDataStream(const ERxPachube& pachube);

void setup() {

   Serial.begin(9600);
   Ethernet.begin(mac, ip);

   dataout.addData(0);
   dataout.addData(1);
   dataout.addData(2);
        dataout.addData(3);
       
        // Assign LED to blink once data are sent to Pachube
        // pinMode(13, OUTPUT);
}

void loop() {

   Serial.println("+++++++++++++++++++++++++++++++++++++++++++++++++");
   // float fSensorData = 15.23; // POD-2
        float fSensorData = 55.84; // POD-1
       
        float sensorReading = analogRead(A0); // POD-1 & POD-2
        sensorReading = sensorReading * 5 * 100. / 1024.;
   // dataout.updateData(0, analogRead(0)); // Example
        dataout.updateData(0, sensorReading);
       
   dataout.updateData(1, fSensorData); // POD-1 & POD-2

   dataout.updateData(2, "POD-1");
        // dataout.updateData(2, "POD-2");
       
        // sensorReading = analogRead(A1); // POD-2
        // sensorReading = (sensorReading * 5. / 1024.) * 60. + 800.; // POD-2
        // dataout.updateData(3, sensorReading); // POD-2
        dataout.updateData(3, analogRead(1)); // POD-1
       
   int status = dataout.updatePachube();

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

   PrintDataStream(dataout);

        // Blink the LED
        // digitalWrite(13, HIGH);
        // delay(1000);
        // digitalWrite(13, LOW);
        // delay(1000);

   delay(10000);
}

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();
   }
}

Go Up