我正在尝试调试为什么事件 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 模块触发的事件?