Raptor + WifiRS21 local web services

I am fiddling around with the web stuff and I am trying to have temperature readings being pushed to the cloud (Windows Azure). I deployed a small test web API to Azure and it works just fine. The gadgeteer app communicates fine.

For further dev I am using a local web project running on IIS Express on my Win 8.1 laptop. The web project is developed in VS2013. I have the same code as in Azure running in debug mode but my gadgeteer app is not able to communicate with the website hosted in my laptop…

All connections are up and running on the mainboard / app
Other devices (laptops, phone, tablet etc) are able to use the locally hosted web site and debugging goes just fine.
Gadgeteer just throws exceptions :frowning:

Exception System.Net.Sockets.SocketException - CLR_E_FAIL (25)

#### Message: 
#### Microsoft.SPOT.Net.SocketNative::getaddrinfo [IP: 0000] ####
#### System.Net.Dns::GetHostEntry [IP: 0008] ####
#### System.Net.HttpWebRequest::EstablishConnection [IP: 00e1] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### Gadgeteer.Networking.HttpRequest::HandleRequestSync [IP: 01a9] ####
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060

A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060
#### Exception System.Net.WebException - 0x00000000 (25) ####
#### Message: host not available
#### System.Net.HttpWebRequest::EstablishConnection [IP: 00f1] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### Gadgeteer.Networking.HttpRequest::HandleRequestSync [IP: 01a9] ####
A first chance exception of type ‘System.Net.WebException’ occurred in System.Http.dll
#### Exception System.Net.WebException - 0x00000000 (25) ####
#### Message:
#### System.Net.HttpWebRequest::GetResponse [IP: 00d3] ####
#### Gadgeteer.Networking.HttpRequest::HandleRequestSync [IP: 01a9] ####
A first chance exception of type ‘System.Net.WebException’ occurred in System.Http.dll

An exception occured while connecting to the Internet. Please, make sure that a valid URL is used and a network connection is up.

Code using is:

 
HttpRequest req = HttpHelper.CreateHttpGetRequest(API_HOST_LOCAL + "/api/gadgeteer");
req.ResponseReceived += new HttpRequest.ResponseHandler(wc_ResponseReceived);
req.SendRequest();

Any idea’s, experiences?

Extra info: hosted web in VS2013 uses port 4723. Not default port 80.

… then isn’t the use of port 4723 your challenge? Where do you set that in your code above??

The port is set via the constant see code below


using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHI.Premium.Net;
using System.Text;
using System.IO;

namespace Gadgeteer.Network.Wifi
{
    public partial class Program
    {
        bool connected = false;
        const string WIFI_HOME_SSID = "InfoFluxWLAN";
        const string WIFI_HOME_KEY = "******";

        const string WIFI_IFCMINE_SSID = "InfoFlux";
        const string WIFI_IFCMINE_KEY = "*******";

        const string API_HOST_LOCAL = "http://IF-PC-002:4725";
        const string API_HOST_AZURE = "http://ifgadgeteer.cloudapp.net";

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            Debug.Print("Program Started");

            GT.Timer t = new GT.Timer(1000);
            t.Tick += t_Tick;
            t.Start();
            button.ButtonPressed += button_ButtonPressed;
            
        }

        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            try
            {
                Debug.Print("**** Starting web request ****");

                HttpRequest req = HttpHelper.CreateHttpGetRequest(API_HOST_AZURE + "/api/gadgeteer");
                Debug.Print("Sending request of type " + req.HttpRequestMethod.ToString() + " to " + req.URL);
                req.ResponseReceived += new HttpRequest.ResponseHandler(wc_ResponseReceived);
                req.SendRequest();
            }
            catch (Exception exc) {
                Debug.Print("Exception during web request: " + exc.Message);
            }
        }

        void t_Tick(Timer timer)
        {
            timer.Stop();
            SetupWifi();
        }
        

        void wc_ResponseReceived(HttpRequest sender, HttpResponse response)
        {
            Debug.Print("Webrequest to " + sender.URL +  " completed with response " + response.Text); 
            
        }

       void SetupWifi() {

            Debug.Print("***** Setting up wifi *****");
            try
            {
                if (!wifi_RS21.Interface.IsOpen) { wifi_RS21.Interface.Open(); }

                if (!wifi_RS21.Interface.NetworkInterface.IsDhcpEnabled) { wifi_RS21.Interface.NetworkInterface.EnableDhcp(); }
                if (!wifi_RS21.Interface.NetworkInterface.IsDynamicDnsEnabled) { wifi_RS21.Interface.NetworkInterface.EnableDynamicDns(); }

                wifi_RS21.Interface.NetworkAddressChanged += Interface_NetworkAddressChanged;
                wifi_RS21.Interface.WirelessConnectivityChanged += Interface_WirelessConnectivityChanged;
                
                wifi_RS21.UseDHCP();


                NetworkInterfaceExtension.AssignNetworkingStackTo(wifi_RS21.Interface);


                GHI.Premium.Net.WiFiNetworkInfo[] ScanResp = wifi_RS21.Interface.Scan(WIFI_IFCMINE_SSID); //< Needs to be changed to SSID you are looking for

               if (ScanResp != null && ScanResp.Length > 0)
                {
                    foreach (GHI.Premium.Net.WiFiNetworkInfo info in ScanResp) {

                        if (info.ChannelNumber == 11) {

                            wifi_RS21.Interface.Join(info, WIFI_IFCMINE_KEY);
                            
                        }
                    }
               }

               Debug.Print("*** Wifi setup completed"); 
            }
            catch(GHI.Premium.Net.NetworkInterfaceExtensionException exc) {
                Debug.Print("Setup wifi failed: " + exc.Message);
            }
        }

        void Interface_WirelessConnectivityChanged(object sender, GHI.Premium.Net.WiFiRS9110.WirelessConnectivityEventArgs e)
        {
            Debug.Print("Interface_WirelessConnectivityChanged: " + e.IsConnected.ToString() + " - " + e.NetworkInformation.SSID);
            if (wifi_RS21.NetworkSettings.IPAddress == "0.0.0.0") 
            { 
                wifi_RS21.Interface.NetworkInterface.RenewDhcpLease(); 
            }
        }

        void Interface_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print("**** Network Address Changed ******");
            Debug.Print("IP: " + wifi_RS21.NetworkSettings.IPAddress);
            Debug.Print("GatewayAddress: " + wifi_RS21.NetworkSettings.GatewayAddress);
            for (int i = 0; i < wifi_RS21.NetworkSettings.DnsAddresses.Length; i++) { 
                Debug.Print("DnsAddress " + i.ToString() + ": " + wifi_RS21.NetworkSettings.DnsAddresses[i]);
            }
            
        }

    }
}


Debug output when using the Azure cloud service

Using mainboard GHI Electronics FEZRaptor version 1.0
RS9110 firmware version Number is 4.4.5
RS9110 driver version Number is 4.4.5
Program Started
***** Setting up wifi *****
The thread ‘’ (0x3) has exited with code 0 (0x0).
Interface_WirelessConnectivityChanged: True - InfoFlux
**** Network Address Changed ******
IP: 192.168.2.2
GatewayAddress: 192.168.2.1
DnsAddress 0: 192.168.2.1
*** Wifi setup completed
**** Starting web request ****
Sending request of type 0 to http://ifgadgeteer.cloudapp.net/api/gadgeteer
The thread ‘’ (0x9) has exited with code 0 (0x0).
Webrequest to http://ifgadgeteer.cloudapp.net/api/gadgeteer completed with response [“value1”,“value2”,“value3”]

When using local API running on laptop IF-PC-002 on port 4725:

Using mainboard GHI Electronics FEZRaptor version 1.0
RS9110 firmware version Number is 4.4.5
RS9110 driver version Number is 4.4.5
Program Started
***** Setting up wifi *****
The thread ‘’ (0x3) has exited with code 0 (0x0).
Interface_WirelessConnectivityChanged: True - InfoFlux
*** Wifi setup completed
**** Network Address Changed ******
IP: 192.168.2.2
GatewayAddress: 192.168.2.1
DnsAddress 0: 192.168.2.1
**** Starting web request ****
Sending request of type 0 to http://IF-PC-002:4725/api/gadgeteer
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (9) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::getaddrinfo [IP: 0000] ####
#### System.Net.Dns::GetHostEntry [IP: 0008] ####
#### System.Net.HttpWebRequest::EstablishConnection [IP: 00e1] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### Gadgeteer.Networking.HttpRequest::HandleRequestSync [IP: 01a9] ####
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060
#### Exception System.Net.WebException - 0x00000000 (9) ####
#### Message: host not available
#### System.Net.HttpWebRequest::EstablishConnection [IP: 00f1] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### Gadgeteer.Networking.HttpRequest::HandleRequestSync [IP: 01a9] ####
A first chance exception of type ‘System.Net.WebException’ occurred in System.Http.dll
#### Exception System.Net.WebException - 0x00000000 (9) ####
#### Message:
#### System.Net.HttpWebRequest::GetResponse [IP: 00d3] ####
#### Gadgeteer.Networking.HttpRequest::HandleRequestSync [IP: 01a9] ####
A first chance exception of type ‘System.Net.WebException’ occurred in System.Http.dll

An exception occured while connecting to the Internet. Please, make sure that a valid URL is used and a network connection is up.

I also changed the local server port to run under port 80 but that didn’t work either.

I suspect it’s a local DNS issue… de router settings are correct as other devices such like a surface running win 8.1 work perfectly and can call the web service running on my laptop.

But if it were a DNS issue how come the module is able to connect to the azure hosted api and not the api hosted in my laptop…

surely someone has setup a local dev environment with custom ports to debug api’s…

Any idea’s are welcome :slight_smile:

@ xavierk - Are you able to communicate to your laptop via it’s local IP address instead of a local DNS?

By default the ASP.Net Development Server/IIS Express do not allow for remote connections.
Here is a link to a MSDN blog article providing a workaround for IIS Express. The solution for ASP.Net Development Server looks to be a little more involved.

On your local network, you’re resolving names with NetBIOS, not DNS (unless you did install manually a DNS server). Ususally internet routers don’t act as real DNS server but only mirror ones on the internet (your isp for example).

When trying to resolve the name of your computer on the Raptor you’re trying with DNS not with NetBIOS as there’s no client for this protocol on the card. But you can make one.

I just tested the setup in my home network and it works with a default straight forward network setup (no dns, no ad, etc). The raptor is able to talk to the service hosted on my laptop. Both port 80 and port 4725.

On my office network it’s more complex which I was aware of. I installed a wifi router in the office creating a “gadgeteer network” to avoid having to handle DNS, AD and security issues. All the regular devices (tablet, laptop) connected to the gadgteer network worked just fine and found each other without any hassle. Will have to take a closer look tomorrow to see what’s going on.

A good exercise though as the board will eventually need to function in much more complex environments :slight_smile:

@ Mike11, I was aware of that :slight_smile:

@ maverick78, I guess the above kind of proves that the raptor handles netbios just fine unless there is another force at hand I am not aware of. I suspect that resolving names in a regular DNS/AD/Domain setup seems to be the tricky part… we don’t have any on site servers in the office as we have all our dns, domain, sso servers running in azure connected to the office network via VPN. Wild guess… I think it might be in there somewhere :wink:

Keep you posed and in the mean while any additional idea’s/suggestions are welcome :slight_smile:

Cheers