为什么NetworkUp事件不会在.Net Gadgeteer GHI WiFi RS21模块上触发?

时间:2013-09-17 11:00:05

标签: .net-gadgeteer

我正在尝试调试为什么NetworkUp从未在WiFi RS21 Gadgeteer模块上触发,我将其简化为一个非常简单的代码清单:

using Microsoft.SPOT;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace NetworkUpTest
{
    public partial class Program
    {  
        void ProgramStarted()
        {
            wifi_RS21.UseDHCP();
            wifi_RS21.NetworkUp += wifi_RS21_NetworkUp;
            wifi_RS21.NetworkDown += wifi_RS21_NetworkDown;
            var scans = wifi_RS21.Interface.Scan("LLOYDREGANS");
            if (scans != null && scans.Length > 0)
            {
                Debug.Print("Joining " + scans[0].SSID);
                wifi_RS21.Interface.Join(scans[0], "**********");
            }
            var giveUpWaitingForTheNetworkUpEvent = new GT.Timer(300000, GT.Timer.BehaviorType.RunOnce);
            giveUpWaitingForTheNetworkUpEvent.Tick += giveUpWaitingForTheNetworkUpEvent_Tick;
            giveUpWaitingForTheNetworkUpEvent.Start();
        }

        void wifi_RS21_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("NetworkUp");
        }

        void wifi_RS21_NetworkDown(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("NetworkDown");
        }

        void giveUpWaitingForTheNetworkUpEvent_Tick(GT.Timer timer)
        {
            Debug.Print("Give up waiting for the NetworkUp event and try requesting the router homepage");
            var request = HttpHelper.CreateHttpGetRequest("http://192.168.1.1/");
            request.ResponseReceived += request_ResponseReceived;
            request.SendRequest();
        }

        void request_ResponseReceived(HttpRequest sender, HttpResponse response)
        {
            Debug.Print("Response received. response.Text.Length = " + response.Text.Length);
        }
    }
}

这是程序运行时输出窗口中的列表(减去线程退出的报告):

Using mainboard GHI Electronics FEZSpider version 1.0
RS9110 firmware version Number is 4.4.5
RS9110 driver version Number is 4.4.5
Joining LLOYDREGANS
NetworkDown
Give up waiting for the NetworkUp event and try requesting the router homepage
Response received. response.Text.Length = 2509

鉴于网络明显上升,为什么“NetworkDown”是唯一可以从WiFi RS21模块发出的事件?

1 个答案:

答案 0 :(得分:0)

The answer on the GHI forum表示要使用的正确事件是:

Interface.WirelessConnectivityChanged
Interface.NetworkAddressChanged

代替GHI's WiFi RS21 Gadgeteer module page上的示例代码。