-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Running Nancy on your Raspberry Pi
This page describes how to get up and running with Nancy using Mono and selfhosting on your Raspberry Pi. The install/configuration described below was successfully performed on 12th-14th of April 2013.
Due to the need for also running Mono, you currently need to install the soft-float Debian “wheezy” (2012-08-08-wheezy-armel.zip) on your Raspberry Pi. This is due to the fact that Mono currently does not work correctly with the hard-float version of the Raspbian OS (which is the default and latest one). Read more on this issue here. The soft-float OS can be downloaded from here.
You might also get it up and running with hard-float Raspbian using these instructions, so if you feel like experimenting, do go ahead and try it out :)
To install the soft-float OS to your SD card, use the instructions on:
http://elinux.org/RPi_Easy_SD_Card_Setup
The "Linux + ImageWriter" way of writing the image to SD card has worked excellent, but any method should work just fine.
Perform the following commands in a shell on your Raspberry Pi:
sudo apt-get update
sudo apt-get upgrade
After upgrade you should have something similar to the following:
pi@raspberrypi ~ $ uname -a
Linux raspberrypi 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l GNU/Linux
In a shell run the command:
sudo /usr/bin/raspi-config
Set the following settings:
-
Memory-split: 16MB
-
Overclock: Modest 800 MHz (or just leave it at 700 MHz if you're afraid of burning off your Pi)
-
Boot to GUI: No (uses extra resources, but might still work if booting to GUI)
-
Upgrade raspi-config
Then perform a reboot from within raspi-config after setting the above settings.
After reboot verify you have the full 512 MB of RAM available by running the command:
top
and verify you have almost 500 MB of RAM (on the top left part of page).
Mono is required for running Nancy, so go ahead and perform the following commands in a shell in order to get Mono installed:
sudo apt-get update
sudo apt-get install mono-complete
Note: Last step takes a long time, 25+ min.
This final section describes how to get up and running with Nancy on your Raspberry Pi.
First we need to install dependencies, restrieve Nancy source and finnaly compile Nancy in order to get the dll's we are going to reference in our application later on. So in a shell perform the following commands:
mkdir /home/pi/code (or any other directory you prefer)
cd /home/pi/code
sudo apt-get install git ruby rake
sudo gem install albacore
git clone https://github.com/NancyFx/Nancy.git
cd Nancy
rake mono
Note: final step takes a long time. (optionally you might be able to only run 'rake compilemono')
Now we are ready to create our first self-hosted Nancy app, so go ahead and save the following code:
using Nancy;
using System;
namespace Example
{
public class Program:Nancy.NancyModule
{
static void Main(string[] args) {
Console.Write("Starting server...");
var server = new Nancy.Hosting.Self.NancyHost(new Uri("http://localhost:8282"));
server.Start();
Console.WriteLine("started!");
Console.WriteLine("press any key to exit");
Console.Read();
}
public Program()
{
Get["/"] = _ => { return "Nancy says hello!"; };
}
}
}
in a file mains.cs:
-
Write the Nancy app file using
nano main.cs
-
And then paste (right-click) + exit (CTRL-X) + Save
Finally we can compile our Nancy app using the following command:
dmcs -r:/home/pi/code/Nancy/src/Nancy/bin/MonoRelease/Nancy.dll -r:/home/pi/code/Nancy/src/Nancy.Hosting.Self/bin/MonoRelease/Nancy.Hosting.Self.dll main.cs
In order to run the app we must either copy the two Nancy dll's (Nancy.dll and Nancy.Hosting.Self.dll) into the directory of the executable so that they are placed beside the application or we must make sure they are all added to the path searched when resolving assemblies. As a start just place the Nancy dll's beside the executable file (the location of the Nancy dll's can be found in the previous command executed above).
Now run the Nancy application by issuing the following:
mono main.exe
And finally your should be able to invoke the service by pointing your favorite browser to the address http://localhost:8282 and you should be greeted by a "Nancy says hello!".
https://docs.google.com/document/d/1bzbRZFmrYOLh-ldUAcd3_3-o5ISAN7GtrLfOhJoj0qI/edit?usp=sharing
http://hubcitylabs.org/unlocking-your-new-raspberry-pis-512mb-of-memory/
http://mongopi.wordpress.com/2012/11/25/installation/
http://andyfelong.com/2013/02/raspberry-pi-meets-mongodb/
http://stackoverflow.com/questions/7948789/mongodb-mongod-complains-that-there-is-no-data-db-folder
- Introduction
- Exploring the Nancy module
- Routing
- Taking a look at the DynamicDictionary
- Async
- View Engines
- Using Models
- Managing static content
- Authentication
- Lifecycle of a Nancy Application
- Bootstrapper
- Adding a custom FavIcon
- Diagnostics
- Generating a custom error page
- Localization
- SSL Behind Proxy
- Testing your application
- The cryptography helpers
- Validation
- Hosting Nancy with ASP.NET
- Hosting Nancy with WCF
- Hosting Nancy with Azure
- Hosting Nancy with Suave.IO
- Hosting Nancy with OWIN
- Hosting Nancy with Umbraco
- Hosting Nancy with Nginx on Ubuntu
- Hosting Nancy with FastCgi
- Self Hosting Nancy
- Implementing a Host
- Accessing the client certificate when using SSL
- Running Nancy on your Raspberry Pi
- Running Nancy with ASP.NET Core 3.1