Snippet - Simple HTTP server using GHI's Premium Net library

if you are going to be using the Cobra II you will have to use the 4.2 API.

I had a similar problem like this (and another one) so I changed my code to this:


 Eth1 = new EthernetENC28J60(SPI.SPI_module.SPI2,  G120.Pin.P1_9, G120.Pin.P2_4,  G120.Pin.GPIO_NONE);//P0_1);
         if (Eth1.IsActivated)
         {
            Eth1.Close();
            Eth1.Dispose();

            Eth1 = new EthernetENC28J60(SPI.SPI_module.SPI2, G120.Pin.P1_9, G120.Pin.P2_4, G120.Pin.GPIO_NONE);//P0_1);
         }
         
         IPAddressSetResetEvent = new ManualResetEvent(false);
         Eth1.CableConnectivityChanged += new EthernetENC28J60.CableConnectivityChangedEventHandler(Eth1_CableConnectivityChanged);
         Eth1.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Eth1_NetworkAddressChanged);

         Eth1.Open();

         NetworkInterfaceExtension.AssignNetworkingStackTo(Eth1);

         Thread.Sleep(100);

         //Eth1.NetworkInterface.EnableDhcp();
         Eth1.NetworkInterface.EnableStaticIP(myIP, "255.255.255.0", "192.168.42.252");

1st: Iā€™ve register my events earlier and put a 100ms sleep between AssignNetworkStackTo and setting the IP address. 10 ms is to less sometimes.
By this the address is always assigned.

2nd: Sometimes my Ethernet object tells me it is already activated (at least the ENC28) on startup. By this you can not assign it as network stack.
The solution to this was to closem dispose and recreate it.

Hi Richard,
Can you please list what dll references yuo have in your project and what using statements you have.

thanks

Mike

Thtā€™s not too easy to answer because my project has more references than needed for networking.
But in general it sould be as this:
References:
GHI.Preminum.Hardware
GHI.Preminum.Hardware.G120 (because I use a G120 HDR)
GHI.Preminum.Net
Microsoft.SPOT.Hardware (not sure if needed for networking)
Microsoft.SPOT.Native (not sure if needed for networking)
Microsoft.SPOT.TinyCore (not sure if needed for networking)
mscorlib
System
System.Net.Security
usings:
using System;
using System.Net;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHI.Premium.Net;
using GHI.Premium.Hardware;
using System.Net.Sockets;

about the usings in Visual Studio:
If the references are complete, but a using is missing, then you can set the cursor on any unknown type. When you then hover it with the mouse, a underscore is added to the left of the type. Hover it to get a small button, click it to get two options: add using to beginning of file or add namespace to type.

I just wanted to make my networking code more error proof and played around with the network cable.
So I found out that the EthernetENC28J60.CableConnectivityChanged is never fired.
Also if the cable is not connected at the beginning, no Ip address is assigned, even after the cable was connected.
Iā€™m using
G120HDR
ENC28, SPI2, Reset and WOL is not connected
4.2 Premium Lib V0.0.6
static IP

Can this code (if changed) work with FEZ Cerberus Mainboard?
If yes, did someone changed the code to work with ENC28?

Yes as the web server goes but not using any premium code.

Thatā€™s what i was thinking.
Did someone correct it to work with FEZ Cerberus?

Hello, I am using STM32F4 Discovery board and ENC28J60, SPI3 is only usable, how can i configure for SPI3?

Regards
Vishal

Hello. I am trying use Simple HTTP server on G120HDR and ENC28. But VS dont know class HttpListenerContex,HttpListenerRequest ,ā€¦ . I have System in references and using System.Net; But all Httpxxxx are red and unknown.

@ BeranekCZ - the micro framework does not support all classes as on its big brother .net frameworkā€¦

@ RobvanSchelven - I know. But Gus used those class in his Http server class. I only copied his snippet.

Ok. I must add reference to System.Http and now its ok.

I am testing a slightly modified version on the G120HDR v1 with the ENC28 and I got the device to seemingly configure and connect properly to the network. But when I step through the code and reach HTTPListener.Start() the device gets hung up on something and does not continue through the rest of the code. The code does get hung up occasionally while loading the dlls just before the code actually begins to run.

Output shown in picture and no visible errors or exceptions are thrown

I can not compile the project

very thanks/
but I do not see libraries for IPAddress. micro framework has no libraries system.net

I can manage the devices (enable \ disable) via the web site of this server?

I do not see this

yes. I add this reference. but still having a problem with IPAddress

C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le