Pages: [1]   Go Down
Author Topic: uploading sensor data to cosm using enc28j60  (Read 2886 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i used the code below to upload the temperature data(in Celsius) from LM35 sensor.and i succeeded to get data onto my feed. What i want to know is how can i get another graph in the same feed that plots the temperature in fahrenheit.(2 graphs in the same feed)??? could someone guide me on this..???

Code:
#include <EtherCard.h>

#define FEED "feed id"
#define APIKEY "api key"

float tempC;
int tempPin = 0;

// ethernet interface mac address, must be unique on the LAN
byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

char website[] PROGMEM = "api.cosm.com";

byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;

static char statusstr[10];

void setup () {
Serial.begin(57600);
Serial.println("\n[webClient]");

if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");

ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);

if (!ether.dnsLookup(website))
Serial.println("DNS failed");

ether.printIp("SRV: ", ether.hisip);
}

void loop () {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);

if (millis() > timer) {
timer = millis() + 30000;
tempC=(5.0 * analogRead(tempPin) * 100.0)/1024.0;  //convert the analog data to temperature
Serial.println(tempC);
delay(5000);
             
dtostrf(tempC,3,1,statusstr);

// we can determine the size of the generated message ahead of time
byte sd = stash.create();
stash.print("116,");
stash.println(statusstr);
stash.save();

// generate the header with payload - note that the stash size is used,
// and that a "stash descriptor" is passed in as argument using "$H"
Stash::prepare(PSTR("PUT http://$F/v2/feeds/$F.csv HTTP/1.0" "\r\n"
"Host: $F" "\r\n"
"X-PachubeApiKey: $F" "\r\n"
"Content-Length: $D" "\r\n"
"\r\n"
"$H"),
website, PSTR(FEED), website, PSTR(APIKEY), stash.size(), sd);

// send the packet - this also releases all stash buffers once done
ether.tcpSend();
}
}


Quote
dtostrf(tempC,3,1,statusstr);
another doubt which i have is on the code above..what does that 3 and 1 refer to...i got that line from default cosm example in ethercard library..tried using that line when my code didn't work at first.
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 48
Posts: 3393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't help you with the cosm piece but the 3 and 1 in dtostrf are the length of the target buffer and the number of decimal places respectively.
Logged

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 29
Posts: 1667
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Somewhere in your code, you are telling cosm you are sending one variable, and doing that. You need to tell cosm you are sending two readings, and cosm will then make the second graph.
Logged

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

Thanks nick and bill. smiley ...
Quote
whenever i try reconnecting or reset the module the dns lookup for "api.cosm.com" fails...but it returns dns values (in most of the cases) whenever i removed connections to the sensor.
any  idea why this happens..?? i ran the cosm feed for over 6 hours last night..then it didn't had this problem.noticing it from today..Is it because of insufficient power or something? i was powering the arduino via usb only..
« Last Edit: March 24, 2013, 03:15:21 pm by altis » Logged

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 29
Posts: 1667
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it because of insufficient power or something? i was powering the arduino via usb only..

Quite likely. The power available via USB can be quite marginal and the Ethernet facility makes a significant extra demand.

BTW, while the ENC28j60 is clearly not a good  combination with cosm, it looks like you are getting a result. Once you have this sorted, it would be a good idea to post some kosher code on the "It Works!" section of the Cosm Forum, thereby making you the de facto ENC28J60 guru. 
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 48
Posts: 3393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Easy to test though. Find a charger that has a USB port on it and power your arduino that way. I have an arduino and a wifi card running nicely plugged into the charger I got with an iPod.
Logged

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

The problem was with the power..I attached a current sensor and uploaded Irms and apparent power values to cosm at the same time to 2 datastreams successfully..

Logged

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

facing issues with dnslook up at times..DNS failed message comes often.Could someone suggest some solutions to it...yesterday and day before the code worked fine..pls
Logged

Belgium
Offline Offline
Full Member
***
Karma: 0
Posts: 143
Just Do it (with Arduino of course)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Never had problems with dns, this is very likely due to some specific limitations/behaviour of your gateway. Note that there are also well-known problems with DHCP, that were apparently solved a few months ago (you need to refresh the DHCP lease every x hours). I still use the old version, so my Cosm feed will hang about every 6 weeks... (It's actually running the same sketch since October last year IIRC...)

Documentation on ENC28J60 is far from perfect, I tried to upgrade it some months ago but found no other playmate... A shame as this piece of HW is cheaper than the "official" and works nice. I'd like to get my device support both web server and web client at the same time, but that seems very very difficult, mainly because the example sketches simplify things by assuming there will never be more than one TCP connection at the time, and because Arduino RAM is so small it's a challenge to store Ethernet packets.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had problem running the sketch at the first post, I inserted the ID and the Api key, how come I still can not get the result on cosm?
By the way, why is that your sketch doesn't include cosm's library?
Logged

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 29
Posts: 1667
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The cosm libraries are not used with the ENC28J60 module. It uses the Ethercard library instead.
Logged

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

I had problem running the sketch at the first post, I inserted the ID and the Api key, how come I still can not get the result on cosm?
The code still works for me. you might not have changed the data stream ID in the code matching ur feed. and regarding the cosm library as Nick have mentioned it doesn't support Enc28j60. It supports only module based on W5100.
Logged

Pages: [1]   Go Up
Jump to: