Sending Float values to Pachube from Arduino

Hi.. OK, I may get sleep after all :sleeping:

I got it working well with the Cosm-Arduino library. (Links in the code example below). It makes it easy to change the number of variables(streams) and if they are int or float. I have it running on https://cosm.com/feeds/96891

Tomorrow I will work on integrating DHT11 and DS18B20 sensors in an example. For now it just sends phoney changing int and float data.

Many thanks to all.. This is a community I am very happy to be part of!

OK, let's see if I know how to do the Code Thing...

OH: Please nitpick my format and comments in this code etc.. I want this to be as clear as I wished it was at 1AM last night. Think of very inexperienced Arduino enthusiasts reading this, not BitHeads like Rob :slight_smile: There will be a WIKI page of How-to and explanation to go with this code.

/* YourDuinoStarter Example: Web Cloud Data Display for Arduino

  • Create Web Server to send data to cosm.com for display/archive
  • SEE the comments after "//" on each line below
  • CONNECTIONS:
  • V1.03 01/09/12
    Questions: terry@yourduino.com */

/-----( Import needed libraries )-----/
#include <SPI.h> // Standard Arduino Library
#include <Ethernet.h> // Standard Arduino Library
#include <HttpClient.h> // HttpClient lib : GitHub - amcewen/HttpClient: Arduino HTTP library
#include <Cosm.h> // Cosm Arduino lib : GitHub - mnin/CosmArduino

// NOTE: The lines below are from the automatically generated Arduino code that Cosm makes
// when you create a new feed. Cut and paste just these lines for reference
// #define API_KEY "r5LAQylJnH2_S05o1t8yi1yxBtiSAKxxSmpJR0orTTVlbz0g" // your Cosm API key
// #define FEED_ID 96891 // your Cosm feed ID

// NOTE: The "API Key" and "Feed ID" are unique to you. Get them from your Cosm account.
// The API Key is located at https://cosm.com/users/<cosm_username>/keys
// #define API_KEY "r5LAQylJnH2_S05o1t8yi1yxBtiSAKxxSmpJR0orTTVlbz0g" // your Cosm API key
// #define FEED_ID 96891 // your Cosm feed ID

/-----( Declare Constants and Pin Numbers )-----/
char cosmKey[] = "r5LAQylJnH2_S05o1t8yi1yxBtiSAKxxSmpJR0orTTVlbz0g";
unsigned long FeedID = 96891;

/-----( Declare Variables )-----/
// MAC address for your Ethernet shield:Change if you have more than one on your network
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,122); // Available Static IP address on your Network. See Instructions
// Define the strings for our datastream IDs
char sensorId[] = "Int1";
char sensorId2[] = "Int2";
char sensorId3[] = "Float1";
char sensorId4[] = "Float2";

// Define variables for Sensor data to be sent to Cosm
int A,B; // Change to your sensor variable names
float C,D; // Change to your sensor variable names

int cosmReturn = 0; // Result Return code from data send

/-----( Declare objects )-----/
// NOTE: DATASTREAM_INT = integer DATASTREAM_FLOAT = float
// Define the 4 streams
CosmDatastream datastreams[] = {
CosmDatastream(sensorId, strlen(sensorId), DATASTREAM_INT), // define this ID in cosm
CosmDatastream(sensorId2, strlen(sensorId), DATASTREAM_INT), // define this ID in cosm
CosmDatastream(sensorId3, strlen(sensorId), DATASTREAM_FLOAT), // define this ID in cosm
CosmDatastream(sensorId4, strlen(sensorId), DATASTREAM_FLOAT), // define this ID in cosm
};

// Define the Feed, consisting of the 4 DataStreams
CosmFeed feed(FeedID, datastreams, 4 );

// Define the Ethernet Library structures
EthernetClient client;
CosmClient cosmclient(client);
/------------------( END OF DECLARATION AREA )-----------------------------/

void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600); //Ready to send debug info to Serial Monitor

Serial.println("Starting datastream upload to Cosm...");
Serial.println("Starting Ethernet Client...");

Ethernet.begin(mac, ip);
Serial.println("Ethernet client & IP address OK");

// Initialize Sensor Data For Test
A = 10;
B = 20;
C = 40.12;
D = 80.24;

delay(1000); //Wait for Server to start up
}//--(end setup )---

void loop() /****** LOOP: RUNS CONSTANTLY ******/
{

// Put your sensor input code here (This is temporary for changing data for test)
A = A + 1;
B = B + 2;
C = C * 1.05;
D = D * 1.10;

// Put sensor values into the 4 datastreams,
// NOTE: Use setInt() for integer setFloat() for floating point
datastreams[0].setInt(A); // Set sensor values into datastreams 1
datastreams[1].setInt(B); // Set sensor values into datastreams 2
datastreams[2].setFloat(C); // Set sensor values into datastreams 3
datastreams[3].setFloat(D); // Set sensor values into datastreams 4

// NOTE: getInt for integer, getFloat for floating point
// Show the values in the streams for test/debug
Serial.print("A:");
Serial.println(datastreams[0].getInt()); // Print datastream to serial monitor
Serial.print("B:");
Serial.println(datastreams[1].getInt()); // Print datastream to serial monitor
Serial.print("C:");
Serial.println(datastreams[2].getFloat()); // Print datastream to serial monitor
Serial.print("D:");
Serial.println(datastreams[3].getFloat()); // Print datastream to serial monitor

// Send the feed to cosm. (while testing/debugging sensor codes, you can comment it out.
cosmReturn = cosmclient.put(feed,cosmKey); // Send feed to cosm

Serial.print("COSM client returned : "); // Get return result code, similar to HTTP code
if (cosmReturn == 200) { Serial.print(" OK "); }
Serial.println(cosmReturn);

delay(2000); // Put a delay before the next updates to Cosm
}//--(end main loop )---

/-----( Declare User-written Functions )-----/

//( THE END )**