MVC web framework like web server experience on Netduino - Project Showcase - Netduino Forums
   
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

MVC web framework like web server experience on Netduino


  • Please log in to reply
7 replies to this topic

#1 Fredde

Fredde

    New Member

  • Members
  • Pip
  • 8 posts

Posted 23 December 2014 - 02:36 PM

I would like to share a project i have been working with for a long time, it gives you a MVC like developer experience on Netduino.

 

To initialize the server:

public class Program
{
    public static void Main()
    {
        var webServer = new WebServer();
        webServer.Start(80);
    }
}

To create your first controller:

public class MyFirstController : Controller
{
    public void Index()
    {
        SetHtmlResult("<!DOCTYPE html><html><body><h1>My page</h1></html>");        
    }
}

Then run http://192.168.1.100/MyFirst or similar.

 

The main features is:

  • Controller/Action based web request routing with model binding and HTML or JSON response types built in.
  • It support both GET and POST http methods.
  • Exception handling with generic error response that includes exception message and stack trace.
  • It support static files via an optional assembly(to save code space if not needed).
  • Filters on request and response for things like logging, authentication and other things. 

It is built with Dependency injection and has some Unit tests.

 

For source code with running examples and some more decumentation see 

https://github.com/Rinsen/WebServer

 

 

And for long running scenarios i really recommend adding some kind of hardware based watch guard. 

 


  • Frode , munderhill , bulletprooffool and 3 others like this

#2 bulletprooffool

bulletprooffool

    Member

  • Members
  • PipPip
  • 12 posts

Posted 10 February 2015 - 04:25 PM

That's very cool!
I'll have to see what I need to change to use this on an older version of NetMf (since 4.3 will seemingly never be supporter on my old Netduino plus 1s) - and since arduino clones now cost nothing and there are new offerings like the Raspberry Pi update available at about the same price point as the Netduino, I just can't see myself paying for an upgrade.

Irrespective, super work!!

#3 Frode

Frode

    Advanced Member

  • Members
  • PipPipPip
  • 202 posts
  • LocationNorway

Posted 15 February 2015 - 06:21 PM

Very cool! Nice job!

#4 Fredde

Fredde

    New Member

  • Members
  • Pip
  • 8 posts

Posted 26 February 2015 - 02:18 PM

Thanks!

 

I think this will run fine on any 4.x version without any larger modifications except the missing string builder in older versions, but that can be fixed with the one in this post:

http://forums.netdui...ngbuilder-class

 

The limited amount of memory will not be a problem for simpler applications. 



#5 Sukasa

Sukasa

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationNanaimo, BC

Posted 30 March 2015 - 08:11 PM

This is pretty awesome, I think I might have to make use of this in a reflow oven project I'm working on...



#6 cr0w5t3r

cr0w5t3r

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationUK

Posted 10 May 2015 - 09:05 PM

I work with MVC 4/5, Web Api on a daily basis so any linking to those types of frameworks makes me excited! 

 

I will have to test it this week and let you know how it goes  ^_^

 

Nick



#7 lancewmccarthy

lancewmccarthy

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationBoston, MA USA

Posted 02 June 2015 - 08:43 PM

This is very cool! I'm having a problem... although it shows as it is running, any attempt to connect to the server fails (on the Netduino 3 and confirm that the WiFi is connected w/network before starting server).

 

I've tried different ports, different controller endpoints and on a specially isolated wifi network I use for testing.  One thing I noticed is that there are two exceptions before the server spins up. 

 

Here is the output:

A first chance exception of type 'System.NotSupportedException' occurred in Microsoft.SPOT.IO.dll
A first chance exception of type 'System.IO.IOException' occurred in Microsoft.SPOT.IO.dll
Interface nr: 1
Is dhcp enabled: True
The thread '<No Name>' (0x1) has exited with code 0 (0x0).
Interface address: 192.168.100.103
Gateway address: 192.168.100.1
Physical address: 92-134-74-1-38-13
Subnet mask: 255.255.255.0
Selected interface: 192.168.100.103
Local endpoint, IP: 192.168.100.103 Port: 8500 

Any suggestions?


Lance McCarthy

Microsoft MVP (Windows Platform Development)


#8 Fredde

Fredde

    New Member

  • Members
  • Pip
  • 8 posts

Posted 05 December 2015 - 11:37 PM

Hi!

Sorry for the very very late answer, I don´t have any Netduino with Wifi so I have not tested it on that hardware.

But if you have an issue please file it on github so I will see it, I am not here that often now days but it´s really fun to see that you like it!
 

/Fredrik






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.