Main Site Documentation

Using JD11 with NETMF 4.3 and Fez Spider


#1

I have tried to fetch an ip via DHCP and could only do it, by assigning a static-ip first. Otherwise the Network_Up event will not be fired. Looking for the correct way to do it.


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;

namespace FTW
{
    public partial class Program
    {

        bool requestDone = false;

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

            SetupEthernet();


           
        }
               

        void SetupEthernet()
        {

            ethernetJ11D.NetworkInterface.Open();
                      
            //It will work each time only setting the static ip
           ethernetJ11D.UseStaticIP("192.168.178.26", "255.255.255.0", "192.168.178.1", new string[]{"192.168.178.1"});
            
            ethernetJ11D.NetworkInterface.EnableDhcp();
            //ethernetJ11D.NetworkSettings.EnableDynamicDns();

            ethernetJ11D.DebugPrintEnabled = true;
            ethernetJ11D.NetworkUp += ethernetJ11D_NetworkUp;
           
          
        }

        void ethernetJ11D_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            
            ListNetworkInterfaces();
        }

        private  int tries = 0;
        void ListNetworkInterfaces()
        {




            PrintNetworkInfo();




            if (!ethernetJ11D.NetworkSettings.IPAddress.Trim().Equals("0.0.0.0") && !ethernetJ11D.NetworkSettings.SubnetMask.Trim().Equals( "0.0.0.0")
                && !ethernetJ11D.NetworkSettings.GatewayAddress.Trim().Equals("0.0.0.0"))
            {
                Debug.Print("Network initialized!");

               
                Debug.Print("Tries: " + tries);

                PrintNetworkInfo();
                
            }
            else
            {

                tries = tries + 1;
                ListNetworkInterfaces();
               
              

                
            }

        }

        private void PrintNetworkInfo()
        {
            Debug.Print("------------------------------------------------");
            //Debug.Print("MAC: " + ByteExtensions.ToHexString(settings.PhysicalAddress, "-"));
            Debug.Print("IP Address:   " + ethernetJ11D.NetworkSettings.IPAddress);
            Debug.Print("DHCP Enabled: " + ethernetJ11D.NetworkSettings.IsDhcpEnabled);
            Debug.Print("Subnet Mask:  " + ethernetJ11D.NetworkSettings.SubnetMask);
            Debug.Print("Gateway:      " + ethernetJ11D.NetworkSettings.GatewayAddress);
            Debug.Print("------------------------------------------------");
        }
        
    }

}


Thanks :slight_smile:


#2

Hi Andre,

thanks :slight_smile: I will try that. And I have fixed the typo. I post the result back here.

UPDATE: Found everything. Thanks for your help!
UPDATE: It looks like the NetworkAvailabiltyChanged event is not accessible anymore using the latest Firmware and NETMF 4.3. Maybe I am missing an assembly reference? I created the project in VS2012 and I uninstalled all GHI based components before I installed the latest SDK.

Ilija