Pages: [1]   Go Down
Author Topic: Pachube Enc28j60  (Read 1074 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have the following code:
Code:
// Simple demo for feeding some random data to Pachube.
// 2011-07-08 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

#include <EtherCard.h>

// change these settings to match your own setup
#define FEED    "98772"
#define APIKEY  " " // empty due too online post

// ethernet interface mac address, must be unique on the LAN
byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
// Static IP configuration to use if no DHCP found
// Change these to match your site setup
static byte static_ip[] = { 192,168,1,110};
static byte static_gw[] = { 192,168,1,1};

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

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

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

if (ether.begin(sizeof Ethernet::buffer, mymac,10) == 0)
    printf_P(PSTR( "Failed to access Ethernet controller\n\r"));
  if (!ether.dhcpSetup())
  {
    printf_P(PSTR("DHCP failed, using static configuration\n\r"));
    ether.staticSetup(static_ip, static_gw);
   
  }
 
  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip); 
  ether.printIp("DNS: ", ether.dnsip); 
 
  if (!ether.dnsLookup(website))
    printf_P(PSTR("DNS failed\n\r"));
   


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

}

void loop () {
  ether.packetLoop(ether.packetReceive());
 
  if (millis() > timer) {
    timer = millis() + 10000;

    byte sd = stash.create();
    stash.print("0,");   // 5 est le numero du datastream
    stash.println(30);
    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://api.cosm.com/v2/feeds/98772.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);
    Serial.println("SEND");
    // send the packet - this also releases all stash buffers once done
    ether.tcpSend();
   

  }
}

It prints out the following on my serialmonitor:
Quote
[webClient]
IP:  192.168.1.105
GW:  192.168.1.1
DNS: 192.168.1.1
SRV: 216.52.233.121
SEND
SEND
SEND
SEND
SEND
Yet there is no update on my feed from cosm. https://cosm.com/feeds/98772
 What am I doing wrong? Please if anyone can assist.
Logged

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 30
Posts: 1705
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

These cosm problems seem to be all the same - junk code, either based on the wrong libraries, or perhaps in this case no libraries at all.

The first thing you need to do is get the right libraries from github   HttpClient.h and cosm.h. The cosm tutorial has a new quickstart which refers to this, there are suitable examples in the libraries, and working examples in the cosm forum.

Get the libraries, start over again, and it will probably work.
Logged

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

would the cosm libraries be compatible with my ethernet card enc28j60?
Logged

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

Fransh, Nick jumped the gun a bit, no the Cosm library (at least the only one I could find) is not compatible with the EtherCard library you got from JeeNodes.  I haven't worked with the enc28j60 due to the huge (relatively) amount of memory it needs to work on the arduino, so I can't be of direct help, but there are some tricks you can try to see what is happening.

Cosm is picky about the content length, if it's wrong, Cosm will reject the message.  What I did overcoming this kind of problem when I first started updating to pachube was print out the actual stuff I was sending and hand counted the bytes to get it right.  You can also experiment with Curl and the command line to get the api key and such correct until you understand exactly what needs to be sent.

If I remember correctly, there is a way to get stash to dump what is going to be sent such that you can look it over to see what may be happening.  If I'm wrong, the source can be hacked to do a serial print before it is sent to help you get a handle on it.

Other stash users may chime in and help you better than I can, but these are suggestions that can help regardless of the library used.
Logged

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

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 30
Posts: 1705
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

would the cosm libraries be compatible with my ethernet card enc28j60?

I'm afraid I wasn't aware that Enc28j60 was an ethernet card.

Check the new cosm tutorial site for which I forgot to post a link

http://cosm.com/docs/quickstart/arduino.html

 In the Prerequisites it, amongst other pearls of wisdom, specifically says 

"You should also note that the Cosm library will not work with boards that don't use the Wiznet W5100 Ethernet chipset, so for example ENC28J60 based boards will not work........."

I think this is the first, last, and only mention of the Enc28j60.  That, and a tiny bit of reading between the lines from Draythomp, will probably tell you that, if your first priority is to get a result with cosm, the best bet is to ditch the enc28j60, which doesn't work, and get a W5100 like everybody else uses, which does. Then get the proper cosm libraries.........

You may find you can use your gear on an alternative service, like ThingSpeak or Kuidino, but I rather think cosm is the best of them.



   


Logged

Pages: [1]   Go Up
Jump to: