Reports with release 2014 R2-Beta1

Here is a basic example in C# to start the network:

using GHI.Networking;
using Microsoft.SPOT.Net.NetworkInformation;

private static void DoNetwork()
{
	NetworkChange.NetworkAvailabilityChanged += (a, b) => Debug.Print("SPOT NAVAC " + b.IsAvailable.ToString());
	NetworkChange.NetworkAddressChanged += (a, b) => Debug.Print("SPOT NADRC");

	using (var netif = new EthernetENC28J60(..., ..., ..., ...))
	{
		netif.Open();
		netif.EnableDhcp();
		netif.EnableDynamicDns();

		while (netif.IPAddress == "0.0.0.0")
			Thread.Sleep(250);

		Debug.Print(netif.IPAddress);

		//Network ready
	}
}

Thanks John:
Does the new 4.3 allow use of the Gadgeteer socket numbers, and constructs built in Program.generated.vb (Me.ethernetENC28 = New GTM.GHIElectronics.EthernetENC28(11)), or do I need to dig much farther into the documetnation and schematics to see how to fill out the (…,…,…,…)?
It would be too bad if we lost this convenience…

You can still use the Gadgeteer modules with your mainboards. Just drag the module onto the designer like you did in 4.2. You will then want code similar to the following. Make sure you don’t keep the while loop in ProgramStarted, though.

using Microsoft.SPOT.Net.NetworkInformation;

public void ProgramStarted()
{
    NetworkChange.NetworkAvailabilityChanged += (a, b) => Debug.Print("SPOT NAVAC " + b.IsAvailable.ToString());
    NetworkChange.NetworkAddressChanged += (a, b) => Debug.Print("SPOT NADRC");

	var netif = ethernetENC28.NetworkInterface;
	
	netif.EnableDhcp();
	netif.EnableDynamicDns();

	while (netif.IPAddress == "0.0.0.0")
		Thread.Sleep(250);

	Debug.Print(netif.IPAddress);

   //Network ready
}

@ Simon from Vilnius - Thanks for the spelling stuff, it’ll be taken care of. ExtractFloat and ExtractInt32 will be considered, but as iamin said, since BitConverter exists, they might be removed all together. Moisture should be a module in 4.3 under GHI and the TempHumidity bug will be fixed. As is the CAN bug. Do you have to display anything for the N18 to mess up or does just adding the module cause it? The CAN timings will be publically exposed. The public field in RLP will be made into a property as it should be.

@ iamin - Since those types are an integer and an enum I do not think we will be able to define a cast for them like that.

@ CSharpie - The CP7 null bug will be fixed. It should read this.onScreenReleased = new TouchEventHandlerTouchReleased(this.OnScreenReleased); I believe. Notice the capital O.

@ John - that works, after changing
var netif = ethernetENC28.NetworkInterface;
to
var netif = ethernetENC28.interface

(cast to VB of course) 8)

Why or when would you use ethernetENC28.UseThisNetworkInterface() ?

If you have multiple modules plugged in, such as a WiFi RS21 and Ethernet ENC28. Whichever one is initialized first gets opened for you automatically. To switch to the other one you need to call that function since only one interface can be open at a time.

@ John, based on this example I believe you can do that casting: How to: Define a Conversion Operator - Visual Basic | Microsoft Learn

And I was curious, why did you use [em]const[/em] instead of [em]enum[/em] for Pins?

I’ve heard BitConverter has memory leaks, so it’s a too early to rely on it…

I’m just painting bitmaps in exactly the same way I do on Cerberus. Totally nothing special. The regions on the screen seems to be correct, it’s just messed up.

@ iamin - We used consts because we wanted the pins to be of the type Cpu.Pin and an enum cannot be derived from or derive itself (except for the basic integer types). Casting operators, as far as I know, and as the article itself implies, can only be defined inside the class or struct or be converted from or to as evidenced by the compiler error “user defined conversions must convert to or from the enclosing type”. While the pins classes are actual classes, they are just containers for consts, not an actual new, usable data type so we have nowhere to define that conversion operator.

See User-defined explicit and implicit conversion operators - provide conversions to different types | Microsoft Learn

@ Simon from Vilnius - We will do some testing for BitConverter to see if the leak would affect any of the replacing functions. We’ll take a look into the N18 problem and see what we can find.

I have been testing the new release with a FEZ-Raptor with ENC28 network module. In the previous release (4.2) I had problems with DHCP, and in my lab network could not get the router to grant an address. In my work network environment, it always connected. I documented the code in this thread: https://www.ghielectronics.com/community/forum/topic?id=14986&page=4

In response, last month GHI send a custom version of NETMF which I tested, and which solved the problem.

I find that the new beta version does not always connect using DHCP. In tests last night I found that in 19 out of 35 instances it did NOT connect using DHCP. I also verified that the previous (custom) version always connects.

In summary, you had the fix, but perhaps it did not make it into the beta. If you would like any additional testing, please let me know.

1 Like

My issue, too! DHCP is [em]very [/em]unreliable in 4.3.

@ rockybooth and Simon from Vilnius - can either of you get a Wireshark capture of the NETMF 4.3 (not using Gadgeteer) DHCP sessions that do and do not result in an address being issued?

It is strange.

As we tested here, DHCP always work well. Can you please run example code below pls?


using GHI.Networking;

using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Security;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Net;
using Microsoft.SPOT.Net.NetworkInformation;

namespace Networking
{
    public class Program
    {
        //static EthernetBuiltIn netif;
        static EthernetENC28J60 netif;
        //static WiFiRS9110 netif;
        public static void Main()
        {
            DoNetwork();
        }

        static OutputPort led = new OutputPort((Cpu.Pin)(3 * 32 + 3), true); // led pd3
        static InputPort ldr1 = new InputPort((Cpu.Pin)(4), false, Port.ResistorMode.PullUp);
        static InputPort butsellect_chipworkx = new InputPort((Cpu.Pin)20, false, Port.ResistorMode.PullUp);
        static OutputPort led_chipworkx = new OutputPort((Cpu.Pin)(3 * 32 + 0), true); // pd0
        static bool isUseDHCP = true;
        static bool isNetworkReady = false;
        private static void DoNetwork()
        {

            while (ldr1.Read() == true)
            {
                led.Write(true);
                led_chipworkx.Write(true);
                Thread.Sleep(100);
                led.Write(false);
                led_chipworkx.Write(false);
                Thread.Sleep(100);
            }


            led.Write(false);

            //Build In Ethernet
            //netif = new EthernetBuiltIn(); 
            
            //wifi
            //netif = new WiFiRS9110(SPI.SPI_module.SPI2, (Cpu.Pin)86, (Cpu.Pin)95, (Cpu.Pin)5); 
            // For the wifi, need to be tire the wire good.
            
            //enc28
            netif = new EthernetENC28J60(SPI.SPI_module.SPI2, (Cpu.Pin)86, (Cpu.Pin)95, (Cpu.Pin)5); // socket 6
            
            
            NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
            NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
            netif.Open();

            if (isUseDHCP == false)
            {
                // If static ip
                netif.EnableStaticIP("x.y.z.t", "255.255.255.0", "x.y.z.t");
                netif.EnableStaticDns(new string[] { "x.y.z.t", "x.y.z.t" });
            }
            else
            {
                // dhcp IP
                if (netif.IsDhcpEnabled == false)
                {
                    netif.EnableDhcp();
                    netif.EnableDynamicDns();
                }
            }
            // if use wifi => need to be enable Join
            //netif.Join("user ", "pass");
            int cnt = 0;
            while (isNetworkReady == false)
            {
                Thread.Sleep(1000);
                Debug.Print("Waiting for network stable " + cnt);
                cnt++;
            }
            
            led.Write(true);          
            Thread.Sleep(Timeout.Infinite);
        }

        static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
        {
            Debug.Print("Network has changed! ");
        }
        
        static void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print("New address for the Network Interface ");
            Debug.Print("Is DhCp enabled: " + netif.NetworkInterface.IsDhcpEnabled);
            Debug.Print("Is DynamicDnsEnabled enabled: " + netif.NetworkInterface.IsDynamicDnsEnabled);
            Debug.Print("NetworkInterfaceType " + netif.NetworkInterface.NetworkInterfaceType);
            Debug.Print("Network settings:");
            Debug.Print("IP Address: " + netif.NetworkInterface.IPAddress);
            Debug.Print("Subnet Mask: " + netif.NetworkInterface.SubnetMask);
            Debug.Print("Default Gateway: " + netif.NetworkInterface.GatewayAddress);
            Debug.Print("Number of DNS servers:" + netif.NetworkInterface.DnsAddresses.Length);
            for (int i = 0; i < netif.NetworkInterface.DnsAddresses.Length; i++)
                Debug.Print("DNS Server " + i.ToString() + ":" + netif.NetworkInterface.DnsAddresses[i]);
            Debug.Print("------------------------------------------------------");
            if (netif.IPAddress != "0.0.0.0" && netif.IPAddress != "127.0.0.1")
            {
                isNetworkReady = true;
            }
        }        
    }
}

@ Dat, @ John, I will try the code below later today or tonight and report. I will also capture wireshark and send it.

@ John:
Since I am a VB programmer, I am not sure if I am doing this right. I built a new project, deleted the gadgeteer autogenerated files, and compiled this with 4.3. I connect the ENC28 to socket 6.
I start the code, the LED starts flashing, then I push LDR1 and it tries to connect, right?
I get a messages:
Waiting for network stable 0
Waiting for network stable 1
Network has changed!
Waiting for network stable 2
Waiting for network stable 3
… up to 30 before giving up…

I expect that if the network connected, the messages would stop and the network description would be printed in the Immediate Window.

I have tried this 10 times, and the NetworkAddressChanged event has not fired.

Please verify that I am doing this correctly. If so, then later tonight I will try wireshark. I assume I would start capture slightly before pressing LDR1.

@ Dat - I just checked and socket 6 is not SPI for the raptor. Can you check the socket line In the code you wanted me to run as confirm what socket to use?
There as also some Chipworx references in that code that I do not understand.

@ rockybooth - I will get you a VB example when I get in to the office tomorrow. For now, any SPI socket on the Raptor will work - just make sure to get the proper pins when constructing the object.

@ John: I emailed directly Dat, since I did not have your mail, the vb solution I have been running, along with wireshark captures of both when it connected and when it did not.
You sill see in the code, if it gets a dhcp address, it then connects to NIST and sets the RTC and NETMF clocks. It then will check with NIST every several minutes and log the time errors to SCcard. This later part works fine if it gets a network connection.
As I mentioned in the forum, this all worked great with the hotfix to 4.2.
I was intending on posting this as an example VB program to the codeshare, and was pleased with it after the 4.2 hotfix Dat sent, but with 4.3 I do not want to post it until it is solid.
Let me know what else I can do to help debug this.
BTW: netmf timekeeping leaves something to be desired but RTC with Raptor is pretty good with 4.3.
Rocky

Socket 6 on G400HDR, sorry because it was not clear
you see ChipworkX because I also tested G400 on ChipworkX Development board

@ Dat:
You have my code and test results. That should give you the information you need to solve the problem. The ball is in your court.