A class to configure the network parameters from an HTTP page

I think I have found the trouble -> needs to be confirmed if someone can test it.

I believe that it really is an HW problem, exactly a power problem. Since the beginning, I have always worked with USB power only. It should have worked. Something must be at the “limit”. Most of the time it works, but it some peak traffic, or after some hours (domino regulator heating ?) the power lacks. I added an external power of 6V DC and now, I don’t have any more error or crashes. I tried 7.5VDC but the regulator on my Domino was eating too much. I just spend one week finding it out… :-[

Previously I had the problem with a frequency of about 24 hours. This week I replaced my professional computer, and I had the problem every 2 hours or so in average. The power provided on USB on my new computer seem to be less than old one ?

Now I am starting to wonder why my arduino ethernet Shield v5 is sucking out so much power. Looking at the schematics doesn’t trigger any alarm. However, following the tracks on the board worries me more : I have found out that the board is powered through a 3.3V regulator out of the 5V of the FEZ board : That looks fine. HOWEVER, the 3V3 out of the regulator is looped back to the 3.3V pin on the the FEZ. For me, that looks VERY BAD : we have then two 3V3 regulator in parallel (the one on the FEZ board, the one the ethernet Shield). As far as I remember, Voltage regulators should never be mounted in // ? Am I wrong ? How is the FEZ connect wired ? (I have the schematics, but not the board layout). That might be the problem.

I have cut the 3v3 strip on the arduino ethernet shield and some tests are running again on USB power only. Running fine so far. If it is to be confirmed, as far as many peoples are using this ethernet shield (the only one that was available at RobotShop at the time I ordered it), it may be usefull to issue a warning to them. But I might be completly wrong, I haven’t done any electronics design for the past 10 years… :o (besides fixing the kids toys :wink: )

Yes regulators outputs shouldn’t be connected but they are both 3.3V so it is bad but not horrible.

Ethernet draws a lot of power, this is normal. We always use powered USB hubs here as you can’t grantee what kind of power the PC or non-powered-hub is providing. As you found out, this can lead into some very strange behavior that takes weeks to figure out, just to know that it is power issue.

The new Wiz5200 has a low power mode :whistle:

My domino regulator is not heating any more at all !
It is now less warm than the NXP chip itself… So I guess the 2 parallel regulators must have been making some kind of disturbance to the domino board :wink: Then making the board suck more power out of the USB, then making all the problems I have been facing for the last months… 8)

My experience with USB says to never trust the USB to be implemented correctly on a PC. I have one PC that the built in USB just does not work reliably with anything. A PCI card with USB ports fixed that. The amount of current you can actually source from a USB port also seem to be quite variable and depends on what ever the manufacturer decided to do.

Another big issue is that the OS can decide to drop power to a USB device (actually part of the USB spec ‘Selective Suspend’). If traffic is not seen from that port for something like 50ms it can be shut off to save power. This is very maddening as it is quite random and I’ve even read about folks who have this issue with their mouse! In P find each Root Hub in Device Manager and disable this potion in the power tab. In Windows 7 you can kill it in the advanced Power Profile settings

W5200 looks like a W5100 but done right :slight_smile: We like it too so you never know what the future brings :whistle:

I modified the Wiki for this particular ethernet shield.

We have a Release Candidate !!! http://opensource.grisambre.net/fez/NetConfig.zip

If someone can test, this is welcome !

http://opensource.grisambre.net/fez/NetConfig.zip

If you have an idea of something to add to it, please let me know 8) !


/*  
* This class allows the network configuration of the smaller devices (domino, panda)
*  to be managed from an embedded webpage (http://mydevice/netconfig) : "home router configuration style".
*
*  Right now, it supports:
*  - Access with password (however, the security is kind of weak still)
*  - Easy customization of the http config page (a template is provided, but it should be very simple to adapt it to any other design, using the provided tags).
*  - static or DHCP IP addresses
*  - change of Mac address
*  - NETBIOS name resolution (very basic implementation)
*  - NTP time update at startup
*  - Basic Javascript error detection is made on the web page
*  - Allowing to add more of your own pages easyly
*  - An external button / jumper contact can be used at startup time to put the equipement back into default configuration (forgotten password...)
*  - /netstatus tab for system status information
*  - Customizable tabs for the user
*  - Time stored and checked inside the RTC clock
* - Optional cable status monitoring (requiring an extra interrupt pin)
*
*  It was designed to be small and simple (meaning : everything is basic)...
*  It stores its configuration into InternalFlashStorage.
*  You can initialy change the default parameters in your program, but after then, the end user manages it all by himself.
*         
* 
* ----------------------
*  NetConfig Class Usage
* ----------------------
* 
* Please add in your project 2 files as resources:
* - Template.html.bin : Template header for simple message to the user (password, error, you own tabs). Actualy covers CSS and html headers up to </head>
* - NetConfig.html.bin : Template for the main configuration page. It includes zero to several "tags" under the form:
*                        @ PARAMETERNAME  which will be replaced by the actual value when the page is transmitted
*  The HTML ressources have to be named as .bin to be considered as binary ressources by Visual C# express, to use
*  half less memory inside the FEZ: a conversion from string to binary is not any more necessary.
* 
* 
*  Constructor : (non blocking : returns immediatly, even if the configuration
*  is not completed : DHCP, NTP can take take. User shall read the public fields
*  Ready and NTPpending to check if things are ready)
*  
*  NetConfig(SPI.SPI_module SPI,    // First 4 parameters same as
*            Cpu.Pin CsPin,         // for the function WIZnet_W5100.Enable
*            Cpu.Pin ResetPin,      // Number of pages served by the Http Server
*            bool Reservesocket,    // If set to false and user selects DHCP, this will forced to true
*            Cpu.Pin Resetcfg = Cpu.Pin.GPIO_NONE, // Optional Pin that is checked at startup, shall be grounded by user to go back to default parameters
*            uint Flashoffset = 0,  // The configuration is written to Flash at this offset
*                                   // Offset can be adjusted for the program to store other information there
*                                   // User can know the number of necessary bytes for the config by checking NetConfig.FlashSize
*            Cpu.Pin ledPin = Cpu.Pin.GPIO_NONE) // Optional Pin looped from the "Link Led" (Wiz5100 side) to monitor Link status in software
*                                  // This allows for an example to renew DHCP when link is going up "again"
* 
*  Public Fields:
*  
*  public string Http404 { get; set; }  //Customizable 404 Error
*  public uint HttpPagesViewed { get; private set;  // Number of pages served by the Http Server
*  public DateTime HttpLastTime { get; private set; } // Time of the last page served by the Http Server
*  public uint UsedSockets { get; private set; } // Provide user how many sockets are reserved by the class (from 1 to 3: DHCP/DNS(WIZ5100) ; NETBIOS; HTTPSERVER)
*  public const int FlashSize // How many bytes (max) is necessary in FlashStorage to store the configuration
*  public bool Ready { get; private set; }  // True if the network is initialized
*  public bool NTPpending { get; private set; }   //True if the time is beeing adjusted : don't use a Time function in your program, it might change !
*  public delegate void HttpProcess(HttpListenerContext ctx,NetConfig MyNet);  // delegate you should use if creating a function to handle your own pages.
*  public int LastResetCause { get; private set; }  // Since the Watchdog reset cause can be read only once, it is kept here
*  public bool CableConnected { get; private set; }  //True if network cable is connected (if optional Pin LinkLED is used)
*  public int CableChanges { get; private set; } // Number of times the cable connected went up (if optional Pin LinkLED is used)
*  public bool HttpServerStatus { get; } // Return Http Server Status 
*  public bool NetBiosServerStatus { get; } // Return NetBios Server Status 
* 
*  // Following the default configuration you can adjust to your needs (if flash empty or user ask for default config return
*  // Make sure to respect the correct format, length and allowed characters !
*  public const string DefaultCfg = "PSW=;" //Password string[10] [a-zA-Z0-9.-] (empty = no password): Max Length=4+10+1=15 bytes
*                           + "DN=DefaultConfig;" //Device Name string[15] [a-zA-Z0-9.-] :Max Length=3+15+1=19 bytes
*                           + "NETB=checked;" //NetBios enabled if value "checked" disabled if empty: Max Length=5+7+1=13 bytes
*                           + "MAC=AA-AA-AA-AA-AA-AA;" //Mac address : Length=4+17+1=22 bytes
*                           + "DHCP=;" //DHCP enabled if value "checked" disabled if empty: Max Length=5+7+1=13 bytes
*                           + "IP=192.168.0.10;" //Max Length=3+15+1=19 bytes
*                           + "MSK=255.255.255.0;" //Max Length=4+15+1=20 bytes
*                           + "GTW=192.168.0.1;" //Max Length=4+15+1=20 bytes
*                           + "DNS=8.8.8.8;" //Max Length=4+15+1=20 bytes
*                           + "NTP=pool.ntp.org;" //NTP server string[30] [a-zA-Z0-9.-] : Max Length=4+30+1=35 bytes
*                           + "NTPO=-300;" //NTP time offset from GMT is minutes : Max Length=5+5+1=11 bytes
*                           + "TCP=80;"; //TCP port for the webserver : Max Length=4+5+1=10 bytes
* 
* 
*  Public methods:
*  
*  public void NetworkInitialize()  // ReIntialize network or tries again every 10s (please use in separate thread since this is blocking)
*  public void AutoReinitialize(DateTime StartTime, TimeSpan Frequency) // Optionaly Set up a timer to reinitialize the network part automaticaly
*  public void StopHttpServer() // Stops http server. Can be used to temporary disabled the server to free sockets
*  public void StartHttpServer() // Starts an http server thread. 
*  public bool StopNetBiosServer() // Stops NetBios server (if enabled. Can be used to temporary disabled the server to free sockets (if enabled returns true, if disabled false)
*  public bool StartNetBiosServer() // Starts a NetBios server thread (if enabled returns true, if disabled false). 
*  
*  public void HttpAddDispatcher(string Request, HttpProcess Function, string tabname="")   // Add your own function to handle "Request" urls. If Tabname is specified, a tab will be added in the netconfig menu
*  public string MyLanUrl()   // returns the LAN Url of this Weberver, with ending "/" (valid for LAN only since using netbios name if available)
*  public string GetParam(string param)   // Returns a string giving the current parameter value or empty if not set 
*  public string GetUrlPassword(string RawUrl)  // Returns the password as specified in URL
*  public string HtmlTabs(string ActiveTab,string Password)  // returns an html tab structure to be sent before the <div class='n'> tag
*  public void PasswordScreen(HttpListenerContext ctx, string callingpage)   // Send the html password page
* 
*  // a few utilities hardly related to NetConfig
*  public string IpToString(byte[] Adress)   // Convert a byte[] IP address into a string ex "192.168.0.1"  
*  public string MacToString(byte[] Mac)  // Convert a byte[] Mac address into a string ex "AA-AA-AA-AA-AA-AA"
*  public string Replace(string s, string olds, string news)  // Quick function to replace some text by another in a string; made to work only for the first needle occurence
*/

Updated to RC2 ! :smiley:
No bug found or corrected since RC1.
Only a few minor cosmetic changes, more statistics available from the netstatus page, and Netbios thread optimized to produce less GC calls…

Thank you Nicolas for all the contributions you are making. 8)

Thank you Joe for helping me so much :wink:
Here is RC3. Corrected httpserver leaking memory in some cases when a socket is closed by remote client when only a part of the response has been sent. http://opensource.grisambre.net/fez/NetConfig.zip

Netconfig final has been released :stuck_out_tongue: ! You can download it here:
http://code.tinyclr.com/project/308/netconfig-wiz5100-http-configuration-framework/

A few differences since last RC: it is not using resources files anymore, thus making it much more simple to use (only one single file to include in your project). CSS, HTML and Javascript are embedded into the code, as const strings, and are easy to adapt to one’s needs.

Thank you all for your help :wink: ! I learnt so much about .NETMF making that piece of code !

Hi Nicolad, Nice work!

It seems only the one .cs file is in the latest download… Can you upload the entire program?
Thanks!

@ Supermac You can use the “usage example” program to show you how to use this one .CS file. As Nicolas pointed out:

[quote]it is not using resources files anymore, thus making it much more simple to use (only one single file to include in your project). [/quote] so it’s meant to work that way…

I think it is easier for future usage where it is a driver and example usage instead of complete project.

Thanks Nicolas for doing this great work and sharing it with everyone. I tweeted about it and got it to facebook too :slight_smile:

Thanks, got it up and running. Pardon my questions. I finally figured out what references it needed and got it to compile.

It seems to bomb out after a while though. I’m running it on a FEZ domino so I’m not sure if it makes a difference.
Great work Nicolas, I cant wait to see what else comes of this great step forward.

You’ll need to be more specific about what ‘seems to bomb after a while’ means. I’ve run this code on both a Panda II and a Domino (turned off netbios and dchp) successfully. Exceptions occasionally get thrown, but they are handled just fine. I beat on several beta versions pretty hard, so I’m 99% sure the ‘normal bell curve’ of issues has been tested. Something weird might happen in an atypical use case, but that’s why this stuff is open source :wink:

As Spock might say if he were on this forum…

I have to say that since english is far to be a natural language for me, I checked in two different dictionnaries without beeing really sure of the sense of some code bombing out. This seems not quite good however, and I am interested to understand how and why that happened !

The code is globaly “stable”. I have one board with all options used that has been running fine for 4 days, with 50’000+ web page viewed. Another one with 2 days up and 20’000+ pages served.

These are the known problems :

  • on my domino (but not with my panda II !?), I had the program crash on a specific computer evry 24 to 48h hours. On another computer it was every 2 hours, during a network access. I found out that it was a lack of USB power : when I powered the board with external power, those crashes disapeared.
  • Sometimes, with several concurent sockets connections, the http server might fail (lack of sockets mainly). Right now sometimes it takes the board up to 5 minutes sometimes to get an exception, and then to “reload” the http server. I don’t understand why it sometimes takes so long, but let it cool down and try again a few minutes later, it usualy works ! (you will see the http server starts statistic counter increased).
  • I spent also a long time understand that when a program is started inside the VS software (“debug”), if you stop debugging, the program will crash at the next exception (or run fine for days). If you want the software to run a long time, without your computer, start it cleanly with a reset or a power up. I was said that it might be normal. If you want to watch exceptions and debug output then, just connect to your board using mfdeploy.

Let me know of any other trouble you met !

PS: thank you Eric, this Spock is a wise guy :wink:

@ Nicolas3 - Les Français j’ai appris à l’école, avec l’aide de Google, peut suffire. “bombing out” signifie qu’il a éclaté. Pas très utile.

Nicolas3,
I really appreciate your work on this project. I am working on a thermostat project for my home. I know just enough javascript to be really dangerous and am little more than a beginner with C#. I have some assembly and C experience with PIC microcontrollers, and I have done quite a bit of Arduino programming. I can see how you used javascript in your project. In mine, I need to have multiple buttons on a form (such as increase temperature, decrease temperature, on, off, A/C, Heat, etc.). How would you go about having multiple buttons on a form and responding to each one differently? I have managed to do it with 3 buttons, but it will not consistently respond. It randomly hangs and crashes. I am not asking you to do it for me, just some direction. Thanks for your time and input!

I just added to the code site the first “plugin” for NetConfig: http://code.tinyclr.com/project/340/fakedns---dynamic-web-server-redirection/

It is a “Fake DNS” : a dynamic PHP web server redirection to have a single internet php server to rule all your FEZ server. Let me know if anyone meet any trouble with this one !

It just adds a new tab in the netconfig framework, stores its configuration in the flash memory as well.

@ docwelch sorry I missed your question, however since it’s a little off-topic, please contact me directly on my email opensource (at) grisambre (dot) net and I’ll see if I can help ! The javascript was a pain to tune, and I made it much less readable “to pack” the code so it would take much less space in the FEZ memory…