I was having problems getting my Gadgeteer ethernet card initialised and running. I wanted to set it up to use DHCP but I never got an IP address assigned. I am using a GHI Electronics J11D ethernet card and browsing for examples seemed to pull up a lot of code but none of it seemed to work or the code didn’t seem to match what the libraries were providing. I eventually found the solution.
// Wire up the event handler to notify when the ip address has been assigned
// and the port is ready to use
ethernet_J11D.Interface.NetworkAddressChanged += new
// Open the ethernet port
// Assign the network stack to the ethernet card
// Turn on DHCP and Dynamic DNS
It was the line (NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet_J11D.Interface); ) that was the issue, once that was in everything worked fine.
I can now connect to my Windows Azure Websites hosted web api/signalR service.
The code for this is fairly standard and once I got the connection it worked well. The code below shows you how to call the web api service from Gadgeteer. This method works for both GET (read) and PUT (update) requests.
private string CallWebservice(string fn, bool put, string data)
string responseFromServer ;
// Create a request for the URL.
WebRequest request = WebRequest.Create(url + fn);
// set a timeout of a nice big value - 10 minutes
request.Timeout = 600000;
request.Method = "PUT";
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
byte arr = encoding.GetBytes(data);
request.ContentType = "application/json";
request.ContentLength = arr.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(arr, 0, arr.Length);
// Get the response.
WebResponse response = request.GetResponse();
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
responseFromServer = reader.ReadToEnd();
// Tidy up
catch (Exception ex)
return responseFromServer ;