While I was updating my codes from Pachube to Cosm, I find the current documentation for Cosm API was really confusing, not updated or missing info...
They spend so much money on Google Ads but did not get people to clean up the documentations, especially on Arduino portion...
Here is a template I use for my Cosm feeds...
Here is my cosm feeds for those that are interested :-
https://cosm.com/feeds/78111
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Cosm.h>
// Location of the libraries need for Cosm to work
// Cosm Arduino lib : https://github.com/mnin/CosmArduino
// HttpClient lib : https://github.com/amcewen/HttpClient
// MAC address for your Ethernet shield
// Change this if you have more than one Eth Shield on your network
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Change this to your Cosm key to let you upload data
// The API Key are located at https://cosm.com/users/<cosm_username>/keys
char cosmKey[] = "xxxxxxxXXXXXxxxxxxxx";
// Define the strings for our datastream IDs
// Create the 4 feeds
char sensorId[] = "Range1";
char sensorId2[] = "Range2";
char sensorId3[] = "Temp1";
char sensorId4[] = "Temp2";
// DATASTREAM_INT = integer
// DATASTREAM_FLOAT = float
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_INT), // define this ID in cosm
CosmDatastream(sensorId4, strlen(sensorId), DATASTREAM_INT), // define this ID in cosm
};
// Finally, wrap the datastreams into a FeedID, change this
CosmFeed feed(78111, datastreams, 4 ); // Using 4 feeds with FeedID of 78111, get from cosm
// I use static IP address for easy troubleshooting
IPAddress ip(192,168,0,50); // Static IP address
EthernetClient client;
CosmClient cosmclient(client);
void setup(){
Serial.begin(9600);
Serial.println("Starting single datastream upload to Cosm...");
// Setting up Ethernet static IP address
Serial.println("Starting Ethernet Client...");
Ethernet.begin(mac, ip);
Serial.println("Ethernet client & IP address OK");
delay(1000);
}
void loop()
{
int A,B,C,D = 0; // Change to your sensor variable names
int cosmReturn = 0;
// Put your sensor input code here
// Put sensor values into the 4 datastreams,
// 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].setInt(C); // Set sensor values into datastreams 3
datastreams[3].setInt(D); // Set sensor values into datastreams 4
// getInt for integer, getFloat for floating point
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].getInt()); // Print datastream to serial monitor
Serial.print("D:");
Serial.println(datastreams[3].getInt()); // Print datastream to serial monitor
// This line send the feed to cosm, while testing/debugging your codes, comment it out
cosmReturn = cosmclient.put(feed,cosmKey); // Send feed to cosm
Serial.print("COSM client returned : "); // Get retern code, similar to HTTP code
Serial.println(cosmReturn);
delay(2000); // Put a delay before the next updates to Cosm
}