How to Install Mono on a Raspberry Pi
How to Install Mono on a Raspberry Pi
Join the DZone community and get the full member experience.Join For Free
- This post exists to help with an MSDN Magazine article that I am authoring
- It provides some of the low-level details for the article
- How to install Mono and root certificates on a raspberry pi
- How to create an Azure mobile service
- How to create a Custom API inside Azure mobile services that the raspberry pi can call into
- How to create an Azure storage account
MONO - HOW TO INSTALL ON A RASPBERRY PI
- Why Mono?
- How to install Mono on a raspberry pi
- Installing trusted root certificates on to the raspberry pi
- An open source, cross-platform, implementation of C# and the CLR that is binary compatible with Microsoft.NET
- Mono is a free and open source project led by Xamarin (formerly by Novell) that provides a .NET Framework-compatible set of tools including, among others, a C# compiler and a Common Language Runtime
- Because it lets us write .net code compiled on Windows
- We can simply copy the binary files from Windows to Linux and run it as is
- From a raspberry pi device, it is possible to use a .net application to take a photo and upload it to Windows Azure storage
HOW TO INSTALL ON A RASPBERRY PI RUNNING LINUX
You will issue the following commands:
pi@raspberrypi ~ $ sudo apt-get update pi@raspberrypi ~ $ sudo apt-get install mono-complete
The first command makes sure all the local package index are up to date with the changes made in repositories. Second command installs the complete Mono tooling and runtime.
MAKING SURE THAT YOUR MONO APPLICATIONS CAN MAKE A HTTPS REST-BASED CALLS
This command downloads the trusted root certificates from the Mozilla LXR web site into the Mono certificate store. Once complete, the Raspberry PI will be capable of making web requests using HTTPS requests within Mono.
pi@raspberrypi ~ $ mozroots --import --ask-remove --machine
CREATING A NEW AZURE MOBILE SERVICES ACCOUNT
- The mobile services account is needed to host a Node.js application that provides shared access signatures to raspberry pi devices
- The shared access signature is needed by the raspberry pi, so that it can directly and securely upload photos to Azure storage
STEPS TO CREATE AN AZURE MOBILE SERVICE
- The steps below will create an Azure mobile service
- The service will be used to host a Node.js application interacting with a raspberry pi devices
- We will provision a SQL database, although it will not be used initially
FOLLOW THESE STEPS TO CREATE THE MOBILE SERVICE
- Login into the Azure Portal
- Select MOBILE SERVICES from the left menu pane at the Azure Portal.
- In the lower left corner select "+NEW" to create a new Azure Mobile Service.
- Make sure you've selected, "COMPUTE / MOBILE SERVICE / CREATE."
- You will now enter a url. We will call this service raspberrymobileservice.
- For the DATABASE, we will choose "Create a new SQL database instance."
- The REGION we chose is "West US."
- Click the "->" arrow to proceed to the next screen.
- In this screen you will "Specify database settings."
- The NAME of your database will based on the URL you entered previously.
- In this case, the database is called "raspberrymobileservice_db."
- You will need to choose a SERVER. We will choose "New SQL database server" from the drop-down list.
- You will need to provide a SERVER LOGIN NAME and a SERVER LOGIN PASSWORD.
- Take note of the login you provided as it will be needed later
CREATING A CUSTOM API
- This custom API is really just a Node.js application running in the server
CREATING THE API TO RESPOND TO THE DEVICE TRYING TO UPLOAD PHOTOS
- Now that the service is established, we will turn our attention to creating an API that the device can call into to upload a photo.
- Login into the Azure Portal
- Your mobile service will take a few minutes to complete, and you should see the "Ready" flag as the "Status" for your service.
- Once it is ready you can drill into your service to customize its behavior. Just to the right of the service name, click the right arrow key "->" to drill into the service details.
- The top menu bar will offer many options, but we are interested in the one titled "API."
- The API allows you to create a series of node.JS API calls that a device can call into using rest-based approaches.
- Click on "API." from there, select "CREATE A CUSTOM API." You will be asked to provide an API name. Type in "photos" for the API name.
- Below you will see a series of drop-down combo boxes that relate to permission.
- We will keep the default value of "Anybody with the application key."
- This might not be the best option for all scenarios.
- You can read more about this here. http://msdn.microsoft.com/en-us/library/azure/jj193161.aspx.
- Click the checkmark to complete the process.
- The name of the AP you just created, "Photos," should be visible on the portal interface.
- To drill into the photos API click on the right arrow key "->". The right arrow key will be just to the right of the name of the API "Photos".
- At this point you should see a basic script that has been provided by default. We will overwrite this default script with our own script as described in the MSDN Magazine article.
CREATING A STORAGE ACCOUNT TO STORE THE PHOTOS
- Navigate to the portal and create a storage account
- Create a container for the photos
- Obtain the:
- Storage Account Name (you will provide a name)
- Storage Account Access key (generated for you)
- Container Name (you will create)
CREATING A STORAGE ACCOUNT
- We will need a storage account so that we can upload photos to it.
- The steps are well documented here: http://azure.microsoft.com/en-us/documentation/articles/storage-create-storage-account/
- In our case we call the storage account raspberrystorage.
- This means that the URL that the device will use to upload photos is https://raspberrystorage.blob.core.windows.net/.
- As you complete these steps make sure that you choose the storage account location to be the same location as was used for your mobile services account.
- This avoids any unnecessary latency or bandwidth costs between data centers.
- Once the storage account is created, we will need to create a container within it.
- Photos or any blob for that matter, are always stored within a container. To create a container drill into your newly created storage account and select CONTAINERS from the top menu. From there, select CREATE A CONTAINER. The new container dialog box will ask for a name for your container. Take note of the name you provide. We are calling our container ?photocontainer.?
- When the raspberry pi device uploads photos to the storage account, it will target a specific container, such as the one we just created. You will next be asked to indicate ACCESS rights. To keep things simple we will select access rights of Public Blob.
ENTERING APP SETTINGS
- This post also discusses it well:
- ?The idea of application settings is a set of key-value pairs which can be set for the mobile service (either via the portal or via the command-line interface), and those values could be then read in the service runtime.?
NAVIGATING TO APP SETTINGS
- Navigate to the Azure Mobile Services section of the portal. Drill into the specific service by hitting the arrow below
- Select from the Configure Menu at the top
- Scroll down to the very bottom to see app settings
- Note that we need to enter: - We need to get this from Azure Storage - PhotoContainerName - AccountName - AccountKey
- We get this information from the Azure Storage Section of the Portal. Note that you need to have provisioned a Storage Account to have this information.
- How to get the AccountKey with Azure Storage Services
- Now you can get the access keys
HOW NODE.JS WILL ACCESS THE APP SETTINGS
You will create a Node.js application inside of Azure Mobile Services
- See previous steps
THE NODE.JS APPLICATION READING APP SETTINGS
- You will starting by going back to Azure Mobile Services and drill down into your newly minted service
- We called ours raspberrymobileservice
Published at DZone with permission of Bruno Terkaly , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.