Main Site Documentation

WebServer with Cerberus , ENC28 and Framework 4.3


#1

Hi,

I´m trying to make a webserver with cerberus, enc28 and framework 4.3.

I have tried different options.

When i try to connect it with dhcp never have an ip.

For this reason i am working with fixed ip.

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 Gadgeteer.Modules.GHIElectronics;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Net.NetworkInformation;
using GHI.Networking;

namespace GadgeteerApp7
{
    public partial class Program
    {
        private static EthernetENC28J60 netif;

        void ProgramStarted()
        {

            // FEZ Cerberus Socket and Pins assigments
            var socket = GT.Socket.GetSocket(1, true, null, null);
            var pinINT = socket.CpuPins[3];
            var pinRESET = socket.CpuPins[4];
            var pinSPI_CS = socket.CpuPins[6];

            netif = new EthernetENC28J60(SPI.SPI_module.SPI1, pinSPI_CS, pinINT, pinRESET);
            netif.Open();
            //netif.EnableDhcp();
            netif.EnableStaticIP("192.168.0.100", "255.255.255.0", "192.168.0.1");
            while (netif.NetworkInterface.IPAddress == "0.0.0.0")
            {
                Debug.Print("Waiting for DHCP");
                Thread.Sleep(250);
            }
            
            Debug.Print("Network IPAddress : " + netif.NetworkInterface.IPAddress);
            var allIf = NetworkInterface.GetAllNetworkInterfaces();
            WebServer.SetupWebEvent("hello").WebEventReceived += OnWebEventReceived;
            WebServer.DefaultEvent.WebEventReceived += DefaultEventOnWebEventReceived;
            WebServer.StartLocalServer(netif.IPAddress, 80);
        }

        private void DefaultEventOnWebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            throw new NotImplementedException();
        }

        private void OnWebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            responder.Respond("Hello");
        }
    }
}


If i connect the ENC28 in program.gadgeteer designer i have the next error:

netif = new EthernetENC28J60(SPI.SPI_module.SPI1, pinSPI_CS, pinINT, pinRESET);

Excepción no controlada del tipo ‘System.InvalidOperationException’ en GHI.Networking.dll

Información adicional: This interface type is already created.

if i dont connect the ENC28 in program.gadgeteer designer i have the next error in :

WebServer.StartLocalServer(netif.IPAddress, 80);

Excepción no controlada del tipo ‘System.Net.Sockets.SocketException’ en Microsoft.SPOT.Net.dll

I have tried it with the ENC28 in sockets 1, 5 and 6.

Did you know where can i found a complete example with this configuration??

I have tried differents but ones for spider, others for hydra, others for framework 4.2, etc…

thanks in advance,

Dispensadora Ropa
Alquiler Ropa Laboral Madrid


#2

You are using Gadgeteer, so that means ENC28 module is already initialized for you. You do not need any of these lines:

var socket = GT.Socket.GetSocket(1, true, null, null);
            var pinINT = socket.CpuPins[3];
            var pinRESET = socket.CpuPins[4];
            var pinSPI_CS = socket.CpuPins[6];

            netif = new EthernetENC28J60(SPI.SPI_module.SPI1, pinSPI_CS, pinINT, pinRESET);
            netif.Open();

All you need is to call:



Here the name "ethernetENC28" comes from Gadgeteer designer file.

#3

THANKS SIMON,

It's solved with your help.!!!

Now i'm starting to make new things with it.

In the other hand.... Can I mark the post like "solved"??

thanks,

Dispensadora Ropa
Alquiler Ropa Laboral Madrid