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

Simple HTTP server using GHI’s Premium Net library

GHI’s exclusive new networking library adds a highly configured way to take handle the networking interfaces on a device. Developers are able to control and to receive events from each individual interface, like a Ethernet cable was removed or WiFi connection is Lost. Then one of the interfaces can be assigned to the TCP/IP stack. This means no interface (Ethernet, WiFI…) is active by default.

This Application sets a static or dynamic IP address to “Built-in Ethernet” interface and runs a simple HttpServer. Of course this example requires a device with built in Ethernet PHY, not ENC28 Ethernet. The code can be be simply changed to use ENC28


Nice! I think I like this approach, I will definitely give it at try soon.

thanks Gus. I will try later today. Grandkids are coming to visit.

I assume that the Gadgeteer way will be similar.

@ Mike - gadgeteer driver exposes the object, not much more. Enjoy and grand kids then let’s us know if it worked for you.

I tried it… and it appears to work great. I was able to get an IP address using DHCP. I have not tried
to do anything else yet.

Later, when I have time, I want to check error recovery, and then do some performance tests with the new stack.

Yeah it would be great to see the closed source stack vs LwIP stack :slight_smile:

Got a some projects moved over to the new 4.2, but what does a Cerberus with a ENC28 modules look like configuration wise for the new networking? its 5:30am here and sorry but my brain is done heavy lifting.


I have a EMX Development System with a UEXT cable to a WiFi_RS21. Can I use:
static WiFiRS9110 wifi = new WiFiRS9110(SPI.SPI_module.SPI1, chipSelect, externalInterrupt, resetPin);
If I can what would be the values:
e.g. chipSelect = externalInterrupt = resetPin = ??? just guessing.
Can anyone help with this? KG1

Does the schematic help you in figuring out the pins?

Thanks for the reply. It does not help especially in comparing with

Sorry, exactly why doesn’t it help ?

Interrupt is on IO3 on EMX
Reset is on IO2
CS is on IO12

Thank you for the help.

I have tried to use the ENC28 with the G120HDR board.
But when assigning the Network stack (2nd line here)

Eth1 = new EthernetENC28J60(SPI.SPI_module.SPI2, G120.Pin.P1_11, G120.Pin.P0_6, G120.Pin.P0_1);

I get an exception

The thread '<No Name>' (0x2) has exited with code 0 (0x0).
    #### Exception GHI.Premium.Net.NetworkInterfaceExtensionException - 0x00000000 (1) ####
    #### Message: 
    #### GHI.Premium.Net.NetworkInterfaceExtension::SetDefaultInterface [IP: 001b] ####
    #### GHI.Premium.Net.NetworkInterfaceExtension::AssignNetworkingStackTo [IP: 0026] ####
    #### EmulatorApp.Program::InitEthernet [IP: 0011] ####
    #### EmulatorApp.Program::Main [IP: 0003] ####
A first chance exception of type 'GHI.Premium.Net.NetworkInterfaceExtensionException' occurred in GHI.Premium.Net.dll
An unhandled exception of type 'GHI.Premium.Net.NetworkInterfaceExtensionException' occurred in GHI.Premium.Net.dll

The program '[6] Micro Framework application: Managed' has exited with code 0 (0x0).

Is it possible that I have used some wrong pins? I have connected them to one of the user ports.
Any idea?

@ Reinhard Ostermeier - Are you trying to use the emulator? External hardware does not work in emjlafor

@ Mike: I’m not trying to use the Emulator. I have an actual G120HDR (V1.1) board. I have only USB Client DP Module and ENC28 Module connected.
The ENC28 is connected to User-Port 1, and I have wired the Pins as seen in code to it (MOSI2, MISO2, SCLK2, CS, Interrupt and reset). I did not connect the ‘WOL’ PIn. I’m not sure what it is used for. When I’m back at work (on Moday) I will post my exact wireing.
I’m using SDK 0.0.6. NETMF 4.2, Firmware is updated.
Some other small program which controls an AEDog LCD Display via SPI1 is working well on this board.

I believe you have to do an open on Eth1 before making it the active device/stack.


1 Like

I thought I made a 1:1 copy of the sample, but somehow I’ve missed that line.
Thank you Mike.

Can somebody tell me why is this better comparing to classic sockets (
I am using Spider, and i will be using Cobra II.

with MF 4.2 the IP stack was changed, and GHI built a new API for initialization.

Which one should i pick? What things are important for my decision?