Loading...
Pages: [1]   Go Down
Author Topic: Cosm Template with 4 datastreams  (Read 2515 times)
0 Members and 1 Guest are viewing this topic.
Kuala Lumpur, Malaysia
Offline Offline
Full Member
***
Karma: 2
Posts: 137
Anything is possible
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
#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
}                     
Logged

Dee Why NSW
Offline Offline
Full Member
***
Karma: 5
Posts: 206
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Stanley

I have been having a nightmare of a time with cosm. I finally got a result with a single feed using the new libraries. Your code gave me the breakthrough I needed for multiple data.

https://cosm.pachube.com/feeds/83153
Logged

Kuala Lumpur, Malaysia
Offline Offline
Full Member
***
Karma: 2
Posts: 137
Anything is possible
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm glad you find it useful..

With Arduino, I want everyone to be able to use it easily and easy to read the codes too...

Logged

Adelaide, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Stanley
I agree with Nick, I have been pulling my hair out, thanks a million.
However, I am for some reason only getting 0.00 as my float value in Cosm and via serial monitor, I am doing something wrong but it seems so straightforward I can't think what. I am simply doing an analogRead straight to the variable (A) for testing.
Any help appreciated, I am not very good at this yet.....

Cheers John

Code:
void loop()
{
  //float A,B,C,D = 0;             // Change to your sensor variable names
  int cosmReturn = 0;
 
  // Put your sensor input code here
  float A = analogRead(A0);
  float B = analogRead(A1);
  float C = analogRead(A2);
  float D = analogRead(A3);
 
  // Put sensor values into the 4 datastreams,
  // setInt() for integer
  // setFloat() for floating point
  datastreams[0].setFloat(A);    // Set sensor values into datastreams 1
  datastreams[1].setFloat(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
Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 15
Posts: 876
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I totally cheat in my uploads of data to cosm.  I use comma separated values in a string, then define them on the site.  I was too darn lazy to work out the json for it.

It turned around and bit me though when I started to bring the data back for charting.  I had to break down and learn how to parse the darn json values returned.  Still use the csv format for sending data up though.
Logged

Trying to keep my house under control http://www.desert-home.com/

Topsham, Vermont USA
Offline Offline
Edison Member
*
Karma: 16
Posts: 1466
... in The Woods In Vermont
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I have an Arduino test program that successfully sends both INT and FLOAT data to Cosm.com

It's on the http://ArduinoInfo.Info WIKI here:

http://arduino-info.wikispaces.com/Cosm-Arduino

UPDATE: I have developed real-data examples with DHT11 (Temp-Humidity) and DS18B20 Temp (not done yet)  and they are shown there, along with better how-to setup etc.
« Last Edit: January 13, 2013, 11:23:52 am by terryking228 » Logged

Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

Adelaide, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the help, very nice easy to follow work.
Cheers
John
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the post,

Very helpful and working well  smiley

https://cosm.com/feeds/106332
« Last Edit: March 09, 2013, 07:46:17 pm by rominou1987 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i have a problem with using an HD44780 20X4 lcd with the arduino Uno and  ethernet shield. I load code unto it but it doesn't display anything. i need help. i used the code from the website. http://www.betasix.net/connecting-a-amc2004a-hd44780-compatible-lcd-to-arduino/
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i have a problem with using an HD44780 20X4 lcd with the arduino Uno and  ethernet shield. I load code unto it but it doesn't display anything. i need help. i used the code from the website. http://www.betasix.net/connecting-a-amc2004a-hd44780-compatible-lcd-to-arduino/
Logged

Pages: [1]   Go Up
Print
 
Jump to: