2

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

Alexander Talavari
  • 418
  • 2
  • 9
  • 24

3 Answers3

2

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.

Dan Watts
  • 31
  • 2
1

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

0

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!

ashoke
  • 6,441
  • 2
  • 26
  • 25
  • I just started with Arduino and i got involved because of Microsoft. The documentation at the moment is lacking so i can not find-understand how to run a node.js script on the board. Where do i deploy it? – Alexander Talavari Sep 16 '14 at 02:20
  • recent galileo updates may already have nodejs installed. Can you run "node -v" on command line, does it show the version information. If it works, [install this nodejs REST client library and try out the example](https://github.com/danwrong/restler). – ashoke Sep 16 '14 at 02:35
  • Unfortunately it is not installed.I tried to install it silently but this version of Windows does not have msiexec so an quiet msi install fails and the binary of node js fails to run. – Alexander Talavari Sep 16 '14 at 03:22
  • Looks like [visual studio supports arduino programming for galileo](https://ms-iot.github.io/content/HelloBlinky.htm). If you are comfortable with c/++ i would try the [Arduino HTTP client](https://github.com/amcewen/HttpClient). There is an example in it which you can test out. I am not sure if VS supports importing library, just try adding those HTTP client source files to your project directly. – ashoke Sep 16 '14 at 03:48
  • The [Sample/Walkthrough](http://ms-iot.github.io/content/SampleApps.htm) for [Firmata and Cylon](http://ms-iot.github.io/content/Firmata.htm) implies that Node.js can be installed - but doesn't explain how. – Frank Boyne Oct 05 '14 at 00:15