private static void SetupNetworking() { Microsoft.SPOT.Net.NetworkInformation.NetworkInterface NI = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0]; NI.EnableStaticIP("192.168.0.50", "255.255.255.0", "192.168.0.198"); Debug.Print("Got IP: " + NI.IPAddress.ToString()); }
private void initializeWireless() { try { wifi.NetworkInterface.Open(); wifi.NetworkSettings.EnableDhcp(); wifi.NetworkSettings.EnableDynamicDns(); wifi.NetworkSettings.EnableStaticIP("192.168.1.99", "255.255.255.0", "192.168.1.1"); //Debug.Print("Setting DHCP"); //wifi.UseDHCP(); GHI.Networking.WiFiRS9110.NetworkParameters[] scanResults = wifi.NetworkInterface.Scan(config.ssid); if (scanResults != null) { scanResults[0].Key = config.password; scanResults[0].SecurityMode = GHI.Networking.WiFiRS9110.SecurityMode.Wpa2; scanResults[0].NetworkType = GHI.Networking.WiFiRS9110.NetworkType.AccessPoint; wifi.NetworkInterface.Join(scanResults[0]); Debug.Print("Network joined"); Thread.Sleep(1250); Microsoft.SPOT.Net.NetworkInformation.NetworkInterface settings = wifi.NetworkSettings; Debug.Print("---------------------------------"); Debug.Print("MAC: " + ByteExtensions.ToHexString(settings.PhysicalAddress)); Debug.Print("IP Address: " + settings.IPAddress); Debug.Print("DHCP Enabled: " + settings.IsDhcpEnabled); Debug.Print("Subnet Mask: " + settings.SubnetMask); Debug.Print("Gateway: " + settings.GatewayAddress); Debug.Print("---------------------------------"); } if (wifi.IsNetworkUp) { networkStatusLED.TurnGreen(); Microsoft.SPOT.Net.NetworkInformation.NetworkInterface settings = wifi.NetworkSettings; Debug.Print("---------------------------------"); Debug.Print("MAC: " + ByteExtensions.ToHexString(settings.PhysicalAddress)); Debug.Print("IP Address: " + settings.IPAddress); Debug.Print("DHCP Enabled: " + settings.IsDhcpEnabled); Debug.Print("Subnet Mask: " + settings.SubnetMask); Debug.Print("Gateway: " + settings.GatewayAddress); Debug.Print("---------------------------------"); } else { networkStatusLED.BlinkRepeatedly(GT.Color.Red); } } catch (Exception ex) { Debug.Print(ex.Message); throw ex; } }
public StaticEthernetNetwork(string ipaddress, string netmask, string gateway) { _ethernet = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0]; if (_ethernet == null) { throw new NullReferenceException(); } _ethernet.EnableStaticIP(ipaddress, netmask, gateway); }
public DynamicEthernetNetwork() { _ethernet = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0]; if (_ethernet == null) { throw new NullReferenceException(); } _ethernet.EnableDhcp(); }
/// <summary> /// Sets up the webserver socket /// </summary> private void Setup() { //Print IP networkInterface = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0]; Debug.Print(networkInterface.IPAddress); //Set Socket to be TCP listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //Set socket to listen on port 80 from any ip listenerEndPoint = new IPEndPoint(IPAddress.Any, endpointPort); //Bind socket to port 80, any ip listenerSocket.Bind(listenerEndPoint); //Start listening listenerSocket.Listen(Int32.MaxValue); }
public static void Main() { // initialize all ports connected to the dual // channel relay and temp sensors ledPort = new OutputPort(Pins.ONBOARD_LED, false); digiPort0 = new OutputPort(Pins.GPIO_PIN_D0, true); digiPort1 = new OutputPort(Pins.GPIO_PIN_D1, true); aPort0 = new AnalogInput(AnalogChannels.ANALOG_PIN_A0); aPort1 = new AnalogInput(AnalogChannels.ANALOG_PIN_A1); aPort2 = new AnalogInput(AnalogChannels.ANALOG_PIN_A2); // wait few seconds for netduino to get the ip address and then display the IP address: Thread.Sleep(5000); Microsoft.SPOT.Net.NetworkInformation.NetworkInterface networkInterface = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0]; Debug.Print("Board's IP Address:" + networkInterface.IPAddress.ToString()); // if a valid IP address is successfully obtained then open a listener socket and // start processing incoming requests: if (!networkInterface.IPAddress.ToString().Equals("0.0.0.0")) { // Create listener Socket and start listening on port 80 Socket listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint listenerEndPoint = new IPEndPoint(IPAddress.Any, 80); // bind to listening socket and start listening for incoming connections: listenerSocket.Bind(listenerEndPoint); listenerSocket.Listen(1); // Process incoming requests on the socket created above ProcessRequests(listenerSocket); } else { Debug.Print("NetDuino Failed to obtain a valid IP Address!"); Debug.Print("Exiting Program..."); return; } }
public static void Main() { Debug.EnableGCMessages(false); Debug.Print("Web Server test software"); // Print the network interface information to the debug interface Microsoft.SPOT.Net.NetworkInformation.NetworkInterface NI = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0]; //NI.EnableDhcp(); Debug.Print("IP Address = " + NI.IPAddress + ", Gateway = " + NI.GatewayAddress + ", MAC = " + NI.PhysicalAddress); var webServer = new WebServer(null, Resources.ResourceManager); webServer.Add(new RequestRoute("/", Resources.StringResources.Index, "text/html")); webServer.Add(new RequestRoute("/MyStyles.css", Resources.StringResources.MyStyles, "text/css")); webServer.Add(new RequestRoute("/test", HttpMethods.GET, request => new HtmlResponse("Hello World !"))); webServer.Add(new RequestRoute("/redirect", HttpMethods.GET, request => new RedirectResponse("/"))); webServer.Add(new RequestRoute("/api/time", HttpMethods.GET, GetTime)); webServer.Add(new RequestRoute("/api/time", HttpMethods.PUT, SetTime)); Thread.Sleep(Timeout.Infinite); }
public static void Main() { int port = 8080; Thread.Sleep(8000); Microsoft.SPOT.Net.NetworkInformation.NetworkInterface networkInterface = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0]; Debug.Print("my ip address: " + networkInterface.IPAddress.ToString()); socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //Request and bind to an IP from DHCP server socket.Bind(new IPEndPoint(IPAddress.Any, port)); //Debug print our IP address Debug.Print(Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress); //Start listen for web requests socket.Listen(10); Debug.Print("listening"); StartListener listener = new StartListener(socket, led); listener.Start(); }
public static int netconn() { int result = 0; Microsoft.SPOT.Net.NetworkInformation.NetworkInterface nf = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0]; if (!nf.IsDhcpEnabled) { Debug.Print("dhcp not enabled, setting up"); nf.EnableDhcp(); nf.RenewDhcpLease(); Thread.Sleep(10000); } if (nf.IPAddress == "0.0.0.0") { result = 1; } else { result = 0; } return(result); }
void initializeNetwork() { string[] googleDNS = new string[] { "8.8.8.8" }; try { //ethernetJ11D.NetworkInterface.Open(); //ethernetJ11D.NetworkSettings.EnableDhcp(); //ethernetJ11D.NetworkSettings.EnableDynamicDns(); //ethernetJ11D.UseStaticIP("192.168.1.222", "255.255.254.0", "192.168.1.1"); ethernetJ11D.UseDHCP(); ethernetJ11D.NetworkSettings.EnableStaticDns(googleDNS); Microsoft.SPOT.Net.NetworkInformation.NetworkInterface settings = ethernetJ11D.NetworkSettings; while (ethernetJ11D.NetworkSettings.IPAddress == "0.0.0.0") { Debug.Print("Waiting for DHCP"); Thread.Sleep(2500); } ethernetJ11D.UseDHCP(); setInternet(true); } catch (Exception ex) { Debug.Print(ex.Message); } if (ethernetJ11D.IsNetworkUp) { Debug.Print("network is up"); } else { Debug.Print("network down"); } }