如何使用英特尔 Galileo 板连接到 REST 服务?
我需要独立于 PC 客户端的解决方案。
只要通过以太网或 Wi-Fi 访问互联网,代码就会执行
最佳答案
如果您还没有倾向于 Node 项目,最直接的解决方案是使用 Win32 API。
ms-iot Sample Apps page on GitHub最近更新引用了 WinSock sample on MSDN 。我对 WinSock 客户端示例代码进行了一些更改,以将数据发布到使用 REST API 的 Cosm(现在是 Xively)。
Winsock客户端代码的相关更改是:
// replace nnnnn with your Feed ID, and xxxxxxxxxxx with your API key!
char *sendbuf = "PUT /v2/feeds/nnnnn.csv HTTP/1.1\r\nHost: api.cosm.com\r\nX-ApiKey: xxxxxxxxx\r\nUser-Agent: WinGalileo\r\nContent-Length: 18\r\nContent-Type: text/csv\r\nConnection: close\r\n\r\n";
char *databuf = "GalileoTest,123.45\r\n";
. . .
iResult = getaddrinfo("www.cosm.com", 80, &hints, &result);
. . .
// Send the HTML
iResult = send(ConnectSocket, sendbuf, (int)strlen(sendbuf), 0);
. . .
// send the data
iResult = send(ConnectSocket, databuf, (int)strlen(databuf), 0);
过去几个月,Arduino 库已添加到 ms-iot Galileo SDK 中,因此我怀疑正在努力移植 WebClient 和以太网库。请密切关注 GitHub 页面。
关于windows - 使用 Intel Galileo Windows 版本连接到 REST 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25778989/