Connecting to a REST Service using the Intel Galileo Windows build

1.1k Views Asked by At

How can I connect to a REST Service using the Intel Galileo board?

I need the solution to be autonomous of a PC client.

As long there is Internet Access through Ethernet or Wi-Fi the code would execute

3

There are 3 best solutions below

0
On

There is a C++ SDK available that enables calling REST services. It is C++ REST SDK (code name Casablanca). It’s a library from Microsoft published as an open source project on CodePlex. Currently only version 2.2. can be used on Galileo. Instructions how to use it are here: http://ms-iot.github.io/content/Casablanca.htm

If you want to access Azure with REST using Casablanca, there is a library on GitHub: Azure Storage Client Library for C++. It allows you to build applications against Microsoft Azure Storage.

But, if you want to use it on Galileo, you will have some problems. If you want to know how to avoid/workaround problems, you can find the whole instruction on my blog http://kardum.net/iot/intel-galileo-windows-application-azure-storage/

I hope this will help you. Best Regards, Ivan

5
On

you can access the REST service using Arduino HTTP client .

Another option is to install nodejs on Galileo board, and use nodejs based REST or HTTP client libraries.

To install nodejs, just download the windows x32 binary directly no formal installation required. Also download the latest npm.zip and extract in the same folder that has node.exe.

Now you are all set to use the restler REST client library...just install with npm install restler

There is an example at the end of the restler page, copy-paste into a rest_test.js and run node rest_test.js you should have a simple REST client on Galileo working!

0
On

If you aren't already leaning towards a Node project, the most straightforward solution would be to use Win32 APIs.

The ms-iot Sample Apps page on GitHub was recently updated with a reference to a WinSock sample on MSDN. I made a few changes to the WinSock client sample code to post data to Cosm (now Xively), which uses a REST API.

The relevant changes to the Winsock client code are:

// 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 libraries have been added to the ms-iot Galileo SDK over the last couple of months, so I suspect that efforts are underway to port the WebClient and Ethernet libraries. Keep an eye on the GitHub page.