简体   繁体   English

Arduino + WiFly屏蔽无法进行Xive通信

[英]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. 我在通过Arduino Uno v3和Sparkfun WiFly防护罩将传感器数据传递到xively API时遇到问题。 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. 问题不在硬件或在WiFly屏蔽库中,因为我可以将数据很好地传递到Paraimpu服务器。

The most fundamental problem is that the xively library will not work with the sparkfun WiFly library. 最根本的问题是xively库不能与sparkfun WiFly库一起使用。 The relevant declarations (suggested by xively in the documentation) are: 相关声明(在文档中由xive建议)是:

WiFlyClient client;
XivelyClient xivelyclient(client);

this will not work since the WiFlyClient declaration expects a server and port, hence I modified this to: 由于WiFlyClient声明需要服务器和端口,因此这将不起作用,因此我将其修改为:

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&) Xively_sketch2_aug20a:60:错误:没有匹配的函数可以调用'XivelyClient :: XivelyClient(WiFlyClient&)'/Users/paultravers/Documents/Arduino/libraries/xively/XivelyClient.h:11:注意:候选对象是:XivelyClient :: XivelyClient( Client&)/Users/paultravers/Documents/Arduino/libraries/xively/XivelyClient.h:9:注意: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. 为了解决这个问题,我使用成功运行以将数据发送到Paraimpu的代码模板,编写了构建put请求并将其发送到API的代码。

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 : 我打开一个连接(到api.xively.com或173.203.98.29;在此阶段没有影响),并发送以下内容:

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 我可能会看看WiFlyClient的文档...也许您需要以其他方式设置端口/等等...而不是扩展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 :) 注意:我从不使用wifly / etc,我只是使用arduino ...而我也遇到了类似的麻烦:)

I don't have a WiFly shield to test with. 我没有可测试的WiFly防护罩。 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. 但是,正如您在对Zoltan的评论中所说,我认为WiFly客户端的工作方式与Arduino以太网或Wifi的工作方式不同。 This means that the Xively library likely does not work with the WiFly client. 这意味着Xively库可能不适用于WiFly客户端。

This means that your approach of writing your own HTTP request is probably the way to go. 这意味着您可以编写自己的HTTP请求的方法。 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? 发送请求时,Xively Workbench请求日志中是否显示任何内容?

One thing you could try is to use the CSV format instead. 您可以尝试的一件事是改用CSV格式。 This can be better for testing since you avoid the possibility of a minor JSON error causing your entire request to not work. 这可以更好地进行测试,因为可以避免出现较小的JSON错误而导致整个请求无法正常工作的情况。 To do this change your .json to .csv and then simply make your body a comma separated list of datastream,value. 为此,请将您的.json更改为.csv,然后只需将您的正文变成逗号分隔的数据流,值列表即可。 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. 我在您的代码中注意到的一件事是,您没有在请求中发送HTTP版本。

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. 写入Xively时出现405错误,因为我在put请求中错误地将HTTP / 1.0作为版本。

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. SparkFun的WiFly库中还有一个示例,示例显示了对Thingspeak的写入,这有助于确保您正确使用WiFlyClient实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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