Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Multithreaded Webserver and DataLogger


  • Please log in to reply
10 replies to this topic

#1 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 01 March 2012 - 12:49 PM

Hi all

As someone once said, "it's not ready for prime time" but I had a request from Mr EMG to upload it. So you get it early.

Here is my go at a Netduino Multithreaded Webserver and DataLogger.

I uploaded it to Codeplex.
Homelogger

It does work fine under certain conditions.
On a quiet LAN.
Me as the user.
For testing it once did 6000 page requests in 6 days via autorefresh, but since I opened the port to put it on the internet it crashes regularly.

I still have stability problem, when a user clicks the refresh button repeatedly, it will always crash.

One day if I have time I will fix it.

Another day I will put a watch dog on it. Based on a second Netduino that requests pages.
STEFF Shield High Powered Led Driver shield.

#2 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 01 March 2012 - 01:01 PM

I like the sound of it, especially the selectable thread count. However, I'm trying to browse the codeplex repo, and I'm just seeing folders, no files inside...

#3 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 01 March 2012 - 01:56 PM

Its there.
home logger change sets

there is a browse link on the right hand side.
STEFF Shield High Powered Led Driver shield.

#4 emg

emg

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 01 March 2012 - 02:21 PM

Thanks Magpie!

#5 Charles

Charles

    Advanced Member

  • Members
  • PipPipPip
  • 192 posts

Posted 01 March 2012 - 04:29 PM

For testing it once did 6000 page requests in 6 days via autorefresh, but since I opened the port to put it on the internet it crashes regularly.

I still have stability problem, when a user clicks the refresh button repeatedly, it will always crash.


Be sure not to use the standard web port - Use like 28731 or something else random facing the Internet (you don't have to change it in he N+, just redirect in the firewall). That will keep it from being hit by most automated attack code that's going after unpatched IIS servers.

#6 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 09 March 2012 - 05:11 AM

Be sure not to use the standard web port - Use like 28731 or something else random facing the Internet (you don't have to change it in he N+, just redirect in the firewall). That will keep it from being hit by most automated attack code that's going after unpatched IIS servers.


I suppose 8082 is not random enough


P.s I went over to codeplex and noticed that a few people had downloaded it.

If anyone wants to fix it, change it log bugs or even be the owner of the project they are welcome.

I haven't got the time to do much right now.

I will finish it one day, for my own sake at least.
STEFF Shield High Powered Led Driver shield.

#7 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 15 March 2012 - 12:27 PM

Just wanted to let you know Magpie, this is great code! I'm going to be using almost all of this for my Aquarium controller front end. I was raised on Git, so all this codeplex stuff is throwing me off, but I'll figure it out eventually.

#8 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 16 March 2012 - 08:11 AM

Thanks for that message H07R0D I''m really pleased you can use it, even in its unfinished state. If you see any bugs or improvements, then let me know. I saw your aquarium site, I noticed that you are using similar temperature sensors to me. I am thinking you might want a bit more accuracy. ie. using a ds1820 like many others are using. One thing I found with my LM135s (i think) was I got much better results when I put a voltage regulator output into the ARef pin to stabilise it and also a load resistor. I normally take just one look at git and (not github) and murmur WTF to myself. Normally all I want to do is Check in, check out, revert, update, I think I would need a wrapper around git to provide this. Maybe I have been using SVN too long.
STEFF Shield High Powered Led Driver shield.

#9 Frankie

Frankie

    Member

  • Members
  • PipPip
  • 16 posts
  • LocationArnhem, Netherlands

Posted 22 June 2012 - 02:25 PM

Hi Magpie, Thanks for posting you're code, it was great help in getting started. I'm building a multi-purpose application myself and integrated parts of youre webserver code as a service. Im using it to control stuff with a jquery mobile webapp. The webserver loads the mobile site and all actions go through url fragments like so: "baseURL/hardwareID/option/value" where the hardware ID is like Relays/relay1/open, its gonna return json for this webapp but for now just plain text. I've created some abstractions and the webserver is used as a singleton service. Ive created services for web, relayboard and other hardware, logging service, storage service (uses SD card for now but networkstorage is a todo but cant find a good starting point just yet) and a general purpose application service for stuff like changing settings on the n+. For handeling the webrequest that have no mimetype and are skipped by the webservice ive created a factory(mapper) that has all the availeble implementation for the hardware in the form of handlers stored in an hashtable. All i have now are a relay handler and a logginghandler loaded in the hashtable. I use a switch statement to find the correct handler based on the url fragments and then invoke doWork on the handler. I provide the doWork method with a string array of urlfragments. So all the implementation logic like calls to the hardware resides in the handlers. Ive created an interface for the handlers and a baseclass for the general work. anyway im at the point where im building the part to send back Json responses to the webapp and making it a complete package. Im still using youre code on talking to the SD card, but im gonna change it around a bit to more suit my needs. Still have to find a way to save the logging to the SD card in a faster way, now its hogging the app alot when i write all the debug statements to the SD card line by line. Gonna replace that by an inmemory buffer and write large chuncks to the SD at once. Biggest challenge so far was getting the multithreaded hardware calls synchonised to the hardware implementations, making sure the same relays doesnt get triggered by 2 requests at the same time. on the hardware part: im building a small board with the same formfactor as the n+. The plan is to stick 2 of these on it: Breakout Board for PCF8575 I2C Expander(sparkfun electronics) and have 16 more I/O for the n+ without too much hassl so long story short, thanks a lot for the code.. im really getting fired up with the n+.. its so much more my thing than the arduino ps. For those looking for Json and dont want to build it. I found some great Json classes build by Wouter Huysentruit in Neomika webserver project. psps: fixing the n+ crash when using too much requests is easy by upgrading the firmware.. theres a bug crashing the n+ with an outofmemory exception in the 4.1 firware when theres plenty of memory left ;) greetz, Frankie a Junior .NET/Java/Flex/Grails&Groovy developer and electronics noob from Holland

#10 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 22 June 2012 - 02:43 PM

Sorry in advance for beeing offtopic;

a Junior .NET/Java/Flex/Grails&Groovy developer and electronics noob from Holland


Hey! Welkom op de Netduino Forums :D
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#11 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 23 June 2012 - 01:01 PM

Hi Frankie
I'm really glad you managed to find some use for the code, hope you make something really good with your project.
I know how hard it is to use somebody elses code, so that fact that you can use code from an unfinished, poorly documented project, mean that at least my attempt to write reusable code must be partially working.

Here is my liability waiver, It was a work in progress that got stalled because I couldn't get it right, then ran out of program memory.
I didn't mean to put it out to general view until I had fixed the bugs, done the binary upload and rearranged it neatly.

4.2 RC5 should give that extra space. But I was a bit disappointed that I still have a memory leak, so maybe it is my code.

My logger is still actually running but I have to cycle power as it crashes every 10 days or so due to the memory leak. I am fairly sure it is to do with being on the Internet because it used to run for over a month before I opened my gateway for it.

I still cant finish the Webserver/Logger due to my limited amount of time, but if you want to mention any bug fixes you see in the code then go ahead.

Biggest challenge so far was getting the multithreaded hardware calls synchonised to the hardware implementations, making sure the same relays doesnt get triggered by 2 requests at the same time.


Just use a lock for Thread synchronisation. I view any hardware as a resource and therefore because you can have multiple callers on different threads one has to wait for the other to complete.
I do love the challenges of multithreaded apps, fun to debug.


For handeling the webrequest that have no mimetype and are skipped by the webservice ive created a factory(mapper) that has all the availeble implementation for the hardware in the form of handlers stored in an hashtable.
All i have now are a relay handler and a logginghandler loaded in the hashtable.
I use a switch statement to find the correct handler based on the url fragments and then invoke doWork on the handler. I provide the doWork method with a string array of urlfragments. So all the implementation logic like calls to the hardware resides in the handlers. Ive created an interface for the handlers and a baseclass for the general work.

You seem to be making a real webserver.
I know I should use JSON in projects but I tend to use XML due to my familiarity.

psps: fixing the n+ crash when using too much requests is easy by upgrading the firmware.. theres a bug crashing the n+ with an outofmemory exception in the 4.1 firware when theres plenty of memory left

I don't quite follow, I haven't really tried 4.1. I have tried 4.2 RC3,4 and 5 no joy for me here.

I love the language C# I just wish one day in the future we could have a Jit compiler on the Netduino.
STEFF Shield High Powered Led Driver shield.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.