A class to configure the network parameters from an HTTP page

Hello !

I have been working lately on a class to allow the smaller devices (domino, panda) WIZ5100 network configuration from a 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
  • Basic Javascript error detection is made on the web page
  • Allowing to add more of your own pages easyly
  • An optional 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
  • An optional input pin can be used to monitor the link status (available in software) to renew DHCP lease automaticaly when the network is going Up.

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.

Since I am very new to C# programming, I would be interrested to know if someone could help testing it / helping troubleshoot or propose improvements before I put it to http://code.tinyclr.com (which is great, but does not allow feedback yet or contact author, if there is a bug or a problem).

It is “working” and to be considered as a beta, however I am not very happy of how I handled some problems (including what I think might be heap fragmentation).

Let me know if someone is interrested to test/help :stuck_out_tongue:

Best regards,
Nicolas

1 Like

You can post it here and I am sure you’ll get an extra pair of eyes. ;D

i can take a look if you like. it’s funny because I was about to store similar config parameters to 24LC256 chip.

Sorry, the code is tight.
As to work it needs 2 ressources files (netconfig.html and message.html) I enclosed the whole cs project into a zip you can download here: http://opensource.grisambre.net/fez/NetConfig.zip

Thank You !

Edited code with beta4 on April 5th

I think NetConfig is something everybody needs to have if their FEZ has HTTP interface. Thanks for sharing Nicolas.

On suggestion. Writting C# code on embedded systems has lots of advantages. For me one of those things is clean object model. So maybe try to encapsulate some logic into separate classes or take a look at patterns. I know people that don’t agree with object model and accept only procedural ansi c. Maybe it’s because of a paradax, that having more code can make it more clear and understadable.

I updated to beta2 (code as well as zip file for downloading).

Corrected a few minor bugs.
Improved the handling of resources and memory usage by forcing resources to be binary: netconfig page should be faster to load and use half memory than when using the string version (no need for conversion).
Added something of a quick documentation inside the source code.

As for the clean object model, well, I am still learning, I’ll do better next time :wink:
My purpose here was to produce something “small” (embedded !), and easy to use with any application. Yes, my ansi C looking code style might be a mess ! Next time, I will be introducing a new improvement : the goto :stuck_out_tongue: !!

Oh yeah everybody loves goto :smiley:

I know we should “think small” but i don’t see any advantage over ansi c if we end up with similar looking code. Glad you are willing to take a step into the dark side :wink:

@ Nicolas - Double thanks for sharing. I’ve got a WIZ5100 board on the way from Sparkfun, and will gladly bang on this stuff once it arrives. GHI also just announced a Connect Shield which will be out at the end of April, so I’m guessing there will be a flurry of related posts around this new hardware in the near future.

I do C# dev for a living, and I’m happy to help refactor/test the C-R-A-P out of this. The geeks in this forum are great with help at whipping it into highly optimized, well designed code in no time. Don’t be afraid to post it up on http://code.tinyclr.com in the meantime.

@ Gralin - any particular pattern in mind? Are there other existing network libraries that implement a particular design? I’m a GHI hardware newb, so haven’t dug into networking ‘FEZ style’ yet.

I will post for sure on code.tinyclr.com, probably next week.
Still a couple of minor corrections / optimizations before doing so.

Code updated to beta3

@ Nicolas3 …

I put my network board together and your code worked out of the box! I think this is the first time I’ve had both hardware and software behave in this environment on the first attempt. So, to celebrate, I cleaned up the code to make it a bit easier on the eyes. I put the NetConfig class in its own file, added XML commenting to everything, and did some general housekeeping. The function parameters still need some comments, and I might suggest moving all the big text strings into a resource file, or at least centralizing them in one place as constants. That alone would make the code much more readable IMHO.

Functionally it’s very solid. I’ve had a Panda II on my network for most this afternoon without issue. I’ve powered it up and down several times and it just works.

Thanks for sharing.

@ EricH,
Thank you for your tests !
I’ll ask you some more help for the code cleaning when it’s done - or if you could send me the corrected file (on which beta wer you working ? I updated the code several times) this will show me how to improve the future public revision. My email adress is in my GHI profile.

I have put a lot of work into this code, and since last week (beta 3) I made a lot of improvements I haven’t published yet. I think I am coming to a point where it could almost be published on code.tinyclr.com

I will try to post the next beta very soon (within a few days).
The next beta has a nice improvement : it handles “tabs”. Now the network config (what you had in beta3) is inside a tab “network configuration”, but it also includes a tab “status” with several information on the hardware status of the board (uptime, etc); Further more, I added templates so it’s very easy for the user to add its own tabs. The time handling is improved (storing in RTC clock).

The tabs is great because it wil allow “plugins”. For an example, I am starting to think on a tab for “on site update”. Just a tab inside where the user can perform full software update, from within a web page (code will check if another release is available on the specified page, download it, apply it, or use a package available on an USB or SD card. In other some applications I will allow the user to configure sensor thresholds within its own tab.

I am working on beta3. I did not correct anything, just ‘prettied it up’. I’m happy to help with the next round. Sounds like you’ve been busy!

@ EricH,

For beta4,
I gave the class its own namespace (Wiz5100NetConfig) and file name;
Therefore, the “resources.” don’t work any more since they are now in a different namespace (lets call it “whateverprojectnamespace”)

I am not sure how to handle that cleanly with VS10 ::slight_smile: :

  • Make a resource file inside the Wiz5100NetConfig namespace ? I tryed but failed… using the CustomToolName property field and the “public” access modifier (getting plenty of errors like “System.CodeDom does not exist in the current namespace” in the file Resources.Designer.cs)
  • the user will have to add a “using whateverprojectnamespace” at the beginning of the Wiz5100NetConfig file ? ugly… ???
  • Furthermore, the user could choose to insert the resources inside a file that will not have the name “Resources”. Then the Wiz5100NetConfig file will have to be adapted everytime ?

Thank you in advance !
Nicolas

Where is the new beta4 code? The link you have above still looks to have beta3… this brings up another point I think I’ll make on a new thread - this forum could use some source control. Would be great if we had some codeplex like project space to share code. I’m not sure how much others collaborate on writing code, but it’s worth asking.

Eric

Eric,

I updated the link with beta4.
Removed the code from the forum. It was too long to fit, and anyway it is unreadable in a forum if it’s more than 100 lines…

Updates in beta 4 :

  1. The class now handles “tabs” and include by default network configuration + status tabs
  2. User can easyly add his own tabs handled by the same password
  3. Time is stored in RTC clock
  4. Code is started to be documented a little more
  5. The class has been put in a different file, separate from the example.

Updated code to beta5. We are coming close to a RC… :wink:

Updates :

  • ResetCfg pin is now optional
  • Added an optional Pin to loop from the link led on the Wiz5100 board (chip side) to be able to monitor for CableStatus (connected or not) and then to renew DHCP when the cable is coming back up. This is not mandatory, however advised for profesional network behavior ! (see picture below for an example)
  • Applying new configuration is not rebooting the board anymore.
  • NetworkInitialize function is now public (netconfig can be re init at any time by parent process).

Known problems :wall:

  • I can’t still figure out why the sockets stop accepting packets after a time between 12 and 48h, while the other process continue working fine and ICMP (pings) keep answering ok. I thought first my network monitoring threads where beeing GC, but it’s not the case. When I will have a spare FEZ board , I will try running a simple server with of 10 lines of code and see if the problem is the same…

Nicoas3,

[quote]

  • I can’t still figure out why the sockets stop accepting packets after a time between 12 and 48h, while the other process continue working fine and ICMP (pings) keep answering ok. I thought first my network monitoring threads where beeing GC, but it’s not the case. When I will have a spare FEZ board , I will try running a simple server with of 10 lines of code and see if the problem is the same…[/quote]

I have few FEZ board. Can I get the code that shows the problem to try it out too?

Hey Joe,

Thank you for your offer !
The full project is available here : http://opensource.grisambre.net/fez/NetConfig.zip

@ Nicolas - I’ve got an xml page up running your beta3 code at http://pandaii.interlocksoftware.net. This will give you the last time the board was initialized. You can also find out how cold it is in my basement! I’m slowly working towards getting this to automatically post a pachube feed. In the meantime I’m happy to run any code you have that might help us solve the problem.

@ Joe - Any help is appreciated. If we can all run the same code on several boards, hopefully odds will tilt in favor of squashing this bug.

[Update] I’ve now got a watchdog task on a PC doing a get to the panda every 30 minutes and logging uptime. It will email me when it fails so I can reset the board and start another round of logging.

Thank you Eric ! ;D

Gathering times up with configuration, I will add yours here, trying to find what’s wrong :

  • beta5, dhcp + netbios + linkmonitoring, lasted about 30 hours. Dhcp lease time is 1 week.
  • Actualy running another try with same config (been up 20 hours so far)

Next run I’ll switch to static ip and no netbios…

So far I have never seen any memory leaking. GC constant at giving back free memory between 31 and 34k, even after 24h run and plenty of network access.

PS : I ordered a panda II a while ago to make background tests, must be stuck as customs again, those are really a pain in Canada… :think: