简体   繁体   中英

Cannot upload data to Cosm from arduino mega by tutorial sketch

I cannot upload data from my Arduino Mega with Ethernet Shiled to Cosm. I tried one of the tutorial examples ( DatastreamUpload.ino ). I used the API key and feed ID that Cosm gave to me at the registration and changed the init() function to use a static IP address as below:

    byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0xD3, 0x45 };
    IPAddress ip(192,168,0, 110);
    IPAddress gateway(192,168,0, 1);
    IPAddress subnet(255, 255, 255, 0);

then:

    Ethernet.begin(mac, ip, gateway, subnet);

Here is the output from serial monitor:

Read sensor value 452.00
Uploading it to Cosm
cosmclient.put returned -1

Read sensor value 451.00
Uploading it to Cosm
cosmclient.put returned -1

Read sensor value 378.00
Uploading it to Cosm
cosmclient.put returned -3

Read sensor value 352.00
Uploading it to Cosm
cosmclient.put returned -3

Does someone have a solution to this?

There is a lack of documentation on this at the moment, one needs to look at the source code to find out. These error codes are defined in HttpClient.h as below:

// The end of the headers has been reached.  This consumes the '\n'
static const int HTTP_SUCCESS =0;
// Could not connect to the server
static const int HTTP_ERROR_CONNECTION_FAILED =-1;
// This call was made when the HttpClient class wasn't expecting it
// to be called.  Usually indicates your code is using the class
// incorrectly
static const int HTTP_ERROR_API =-2;
// Spent too long waiting for a reply
static const int HTTP_ERROR_TIMED_OUT =-3;
// The response from the server is invalid, is it definitely an HTTP
// server?
static const int HTTP_ERROR_INVALID_RESPONSE =-4;

Unsurprisingly, the ino you link to looks 100% kosher and I struggle to see anything different from what I have used.

As a precaution I would put int ret=0; at the start of the loop

I realise you have only one sensor but suggest you meticulously identify it as sensorId0

I have a buffer

const int bufferSize = 100; char bufferValue[bufferSize]; CosmDatastream datastreams[] = { CosmDatastream(sensorId0, strlen(sensorId0), DATASTREAM_FLOAT),

The full bottle was published on the cosm forum last October.

I don't use that ip, gateway and subnet stuff. It is probably muddying the water.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM