Pages: [1]   Go Down
Author Topic: Cosm Template with 4 datastreams  (Read 3710 times)
0 Members and 1 Guest are viewing this topic.
Kuala Lumpur, Malaysia
Offline Offline
Full Member
***
Karma: 4
Posts: 204
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: 4
Posts: 204
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: 19
Posts: 936
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: 33
Posts: 1925
... 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: 3
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: 3
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: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

#include <Wire.h> //I2C library



  void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
    int rdata = data;
    Wire.beginTransmission(deviceaddress);
    Wire.send((int)(eeaddress >> smiley-cool); // MSB
    Wire.send((int)(eeaddress & 0xFF)); // LSB
    Wire.send(rdata);
    Wire.endTransmission();
  }

  // WARNING: address is a page address, 6-bit end will wrap around
  // also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
  void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
    Wire.beginTransmission(deviceaddress);
    Wire.send((int)(eeaddresspage >> smiley-cool); // MSB
    Wire.send((int)(eeaddresspage & 0xFF)); // LSB
    byte c;
    for ( c = 0; c < length; c++)
      Wire.send(data[c]);
    Wire.endTransmission();
  }

  byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
    byte rdata = 0xFF;
    Wire.beginTransmission(deviceaddress);
    Wire.send((int)(eeaddress >> smiley-cool); // MSB
    Wire.send((int)(eeaddress & 0xFF)); // LSB
    Wire.endTransmission();
    Wire.requestFrom(deviceaddress,1);
    if (Wire.available()) rdata = Wire.receive();
    return rdata;
  }

  // maybe let's not read more than 30 or 32 bytes at a time!
  void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length ) {
    Wire.beginTransmission(deviceaddress);
    Wire.send((int)(eeaddress >> smiley-cool); // MSB
    Wire.send((int)(eeaddress & 0xFF)); // LSB
    Wire.endTransmission();
    Wire.requestFrom(deviceaddress,length);
    int c = 0;
    for ( c = 0; c < length; c++ )
      if (Wire.available()) buffer[c] = Wire.receive();
  }




  void setup()
  {
    char somedata[] = "this is data from the eeprom"; // data to write
    Wire.begin(); // initialise the connection
    Serial.begin(9600);
    i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata)); // write to EEPROM

    delay(10); //add a small delay

    Serial.println("Memory written");
  }

  void loop()
  {
    int addr=0; //first address
    byte b = i2c_eeprom_read_byte(0x50, 0); // access the first address from the memory

    while (b!=0)
    {
      Serial.print((char)b); //print content to serial port
      addr++; //increase address
      b = i2c_eeprom_read_byte(0x50, addr); //access an address from the memory
    }
    Serial.println(" ");
    delay(2000);

  }

I got this code from the arduino website but it is giving me this error "wire.send has been renamed write.write ". How do i solve the error.

http://playground.arduino.cc/Code/I2CEEPROM#.UztWn_ldWSo
Logged

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 47
Posts: 2273
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

............ Now tell us this has something to do with datastreams to cosm
Logged

Pages: [1]   Go Up
Jump to: