GithubHelp home page GithubHelp logo

marinehero / microserver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bytewizer/microserver

2.0 2.0 0.0 6.87 MB

MicroServer IoT is a moduler MVC HTTP, DHCP, DNS, NTP server built for Microsoft .NETMF

Batchfile 0.06% C# 59.23% CSS 1.29% HTML 36.19% JavaScript 3.23%

microserver's Introduction

MicroServer

MicroServer is a modular server built for Microsoft .NET Micro Framework (NETMF).

HTTP Web Service (MVC style)

Based on jgauffin's MVC Web Server framework .

  • Regex Routing Module
  • Model Binding (coming soon)
  • Views with Token Replacement
  • Controller Handling
  • Action Results (View, JSON, Content, Files, Redirects and Errors)
  • Basic Authentication
  • Extendable Modules
  • Form/File Handling
  • Static File Handling with File Listing
  • Body Decoding (Multipart and UrlEncoded)
  • Header Decoding
  • Cookie Encoding/Decoding

DHCP Service

  • Custom Pool Range
  • Custom Reservations
  • Add/Remove Options
  • Simple Packet Debugging

SNTP Service

  • Local (Hardware) Time Source
  • Remote (relay) NTP Server Time Source
  • Client Synchronize
  • Simple Packet Debugging

DNS Service

  • Local Zone File Lookup
  • Remote Relay Lookup
  • Supported Resource Records (A, CNAME, MX, NB, NS, PTR, SOA, TXT)
  • Simple Packet Debugging

Requirements

Software: Microsoft .NET Micro Framework 4.3 or higher.
Hardware: In addition to the emulator console application example projects, this project was developed using GHI Electronics Raptor and Cobra II mainboards.

Example Micro Framework Console Application

This project contains the following simple example (see 'example' folder) project demonstrating how to implement a basic server with all modules loaded. Modules can be enabled or disabled.

Nuget

Available through Nuget

PM> Install-Package MicroServer.ServiceManager

Start a new emulator console application, install MicroServer Service Manager package and create a Program.cs file with the following source code:

Using Service Manager

using System;

using MicroServer.Service;
using MicroServer.Net.Http.Mvc;
using MicroServer.Net.Http.Routing;

namespace MicroServer.Example
{
    public class RouteConfig : HttpApplication
    {
        public override void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                name: "Default",
                regex: @"^[/]{1}$",
                defaults: new DefaultRoute { controller = "example", action = "gethello", id = "" }
            );

            routes.MapRoute(
                name: "Allow All",
                regex: @".*",
                defaults: new DefaultRoute { controller = "", action = "", id = "" }
            );
        }
    }

    public class ExampleController : Controller
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
        }

        public override void OnException(ExceptionContext filterContext)
        {
            base.OnException(filterContext);
        }

        // Any public IActionResult method inherited from Controller is made available as an endpoint
		public IActionResult GetHello(ControllerContext context)
        {
            string response = "<doctype !html><html><head><title>Hello, world!</title>" +
                "<style>body { background-color: #111 }" +
                "h1 { font-size:3cm; text-align: center; color: white;}</style></head>" +
                "<body><h1>" + DateTime.Now.ToString() + "</h1></body></html>\r\n";

            return ContentResult(response, "text/html");
        }
    }

    public class Program
    {
        public static void Main()
        {
            using (ServiceManager Server = new ServiceManager(LogType.Output, LogLevel.Debug, @"\winfs"))
            {
                //INITIALIZING : Server Services
                Server.InterfaceAddress = System.Net.IPAddress.GetDefaultLocalAddress().ToString();
                Server.ServerName = "example";
                Server.DnsSuffix = "iot.local";

                // SERVICES:  Enable / disable additional services
                Server.DhcpEnabled = false; // disabled by default as this could be disruptive to existing dhcp servers on the network.
                Server.DnsEnabled = true;
                Server.SntpEnabled = true;

                //SERVICE:  Enable / disable directory browsing
                Server.AllowListing = false;

                //SERVICE: DHCP
                Server.DhcpService.PoolRange("172.16.10.100", "172.16.10.254");
                Server.DhcpService.GatewayAddress = "172.16.10.1";
                Server.DhcpService.SubnetMask = "255.255.255.0";

                //SERVICES: Start all services
                Server.StartAll();
            }
        }
    }
}

Access the controller endpoint by launching a web browser using: http://[emulator ipaddress]/example/gethello

Using Protocol Modules Individually

If your project only needs to support one or two of the protocols, each protocol service can be loaded without using the service manager.

*Http Service

*Dhcp Service

*Dns Service

*Sntp Service

Contributions

Any contribution to this project are welcome.

License

Licensed under Apache License 2.0

In the case where this code is a modification of existing code under a separate license, the separate license terms remain in effect. The modifications to the code are licensed under the Apache license.

microserver's People

Contributors

microcompiler avatar

Stargazers

Lucas avatar ShaykhullinSergey avatar

Watchers

James Pereira avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.