我无法从以太网Shiled到Cosm的Arduino Mega上传数据。我尝试了一个教程示例(DatastreamUpload.ino
)。我使用了Cosm在注册时给我的API密钥和Feed ID,并将init()
函数更改为使用静态IP地址,如下所示:
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);
然后:
Ethernet.begin(mac, ip, gateway, subnet);
以下是串行监视器的输出:
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
有人有解决方案吗?
答案 0 :(得分:0)
目前缺乏关于此的文档,需要查看源代码才能找到答案。这些错误代码在HttpClient.h
中定义如下:
// 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;
答案 1 :(得分:0)
不出所料,你链接到的人看起来100%犹太教,我很难看到与我用过的东西不同的东西。
作为预防措施,我会提出 int ret = 0; 在循环开始时
我发现你只有一个传感器,但建议你一丝不苟地将它识别为sensorId0
我有一个缓冲区
const int bufferSize = 100;
char bufferValue[bufferSize];
CosmDatastream datastreams[] = {
CosmDatastream(sensorId0, strlen(sensorId0), DATASTREAM_FLOAT),
整瓶已于去年10月在cosm论坛上发布。
我不使用那个ip,网关和子网的东西。这可能会让水变得混乱。