简体   繁体   中英

Arduino+WiFly shield failing to communicate to xively

I have a problem in delivering sensor data to the xively API via an Arduino Uno v3 and a Sparkfun WiFly shield. The problem is not in the hardware, or in the WiFly shield library since I can deliver the data to the Paraimpu server just fine.

The most fundamental problem is that the xively library will not work with the sparkfun WiFly library. The relevant declarations (suggested by xively in the documentation) are:

WiFlyClient client;
XivelyClient xivelyclient(client);

this will not work since the WiFlyClient declaration expects a server and port, hence I modified this to:

byte server[] = {173,203,98,29}; //api.xively.com IP address
WiFlyClient client(server,80);
XivelyClient xivelyclient(client);

This gives me an error on compilation of :

Xively_sketch2_aug20a:60: error: no matching function for call to 'XivelyClient::XivelyClient(WiFlyClient&)' /Users/paultravers/Documents/Arduino/libraries/xively/XivelyClient.h:11: note: candidates are: XivelyClient::XivelyClient(Client&) /Users/paultravers/Documents/Arduino/libraries/xively/XivelyClient.h:9: note: XivelyClient::XivelyClient(const XivelyClient&)

At this point I am stuck, and my attempts to modify the various libraries to try to reconcile this issue have come to no avail - mostly because it is above my skill level and I really don't know what I am doing.

To get round this, I have written the code to build the put request and send that to the API, using the template of the code that runs successfully to send data to Paraimpu.

I open a connection (either to api.xively.com or to 173.203.98.29; it makes no difference at this stage) and send the following :

PUT /v2/feeds/<feed ID redacted>.json
Host: api.xively.com
Content-Type: application/json
User-Agent : Xively-Arduino-Lib/1.0
X-ApiKey: < API key redacted >
Content-Length: 197
{"version":"1.0.0","datastreams" : [{"id":"TEMPERATURE_CHANNEL" , "current_value" : "29.00"},{"id":"LIGHT_SENSOR_CHANNEL","current_value":"541.00"},{"id":"ALARM_CHANNEL","current_value":"0.00"}]}

Terminating with a blank line.

Needless to say I have set up channels in xively with those names. But this does not work - I don't get the expected return, and the channels don't update. If I read the returning input on the connection it is just a long string of numbers. Can anyone see anything wrong in the format of this request?

i might take a look at WiFlyClient 's documentation...maybe you need to set the port/etc in some other way...than extend WiFlyClient

class WiFlyClient2 : public WiFlyClient {
   WiFlyClient2(int[] ip,int port) : WiFlyClient() {
     //setup up your parent by calling it's functions here
   }
}

then it should work like:

byte server[] = {173,203,98,29}; //api.xively.com IP address
WiFlyClient client(server,80);
XivelyClient xivelyclient(client);

note: i never use wifly/etc, i just use arduino...and i run into troubles like this too :)

I don't have a WiFly shield to test with. But as you said in your comment to Zoltan, I don't think that the WiFly client works in the same way that the Arduino Ethernet or Wifi do. This means that the Xively library likely does not work with the WiFly client.

This means that your approach of writing your own HTTP request is probably the way to go. I looked through your request and it looks exactly correct to me. Does anything show up in the Xively Workbench Request Log when you send the request?

One thing you could try is to use the CSV format instead. This can be better for testing since you avoid the possibility of a minor JSON error causing your entire request to not work. To do this change your .json to .csv and then simply make your body a comma separated list of datastream,value. Your body should look something like this:

TEMPERATURE_CHANNEL,29.00
LIGHT_SENSOR_CHANNEL,541.00
ALARM_CHANNEL,0.00

If this does not work it would be helpful if you could post what the return is, that would help us help you. Good luck!

One thing I noticed in your code is that you don't send the HTTP version in your request.

You should try sending:

PUT /v2/feeds/<feed ID redacted>.json HTTP/1.1

I was getting 405 errors when writing to Xively because I incorrectly had HTTP/1.0 as the version in my put requests.

There's also an example from SparkFun's WiFly library that shows writing to Thingspeak which is helpful to make sure you're using the WiFlyClient instance correctly.

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