230 likes | 490 Views
Mono on Raspberry Pi. Using C# and .NET in unexpected places. John Waters. @ john_k_waters john.waters@cto4hire.net www.cto4hire.net/blog. Background. University of Cambridge, UK Concerned about CS skills Wanted to recreate the hobbyist $35 dollar model B.
E N D
Mono on Raspberry Pi Using C# and .NET in unexpectedplaces
John Waters @john_k_waters john.waters@cto4hire.net www.cto4hire.net/blog
Background University of Cambridge, UK Concerned about CS skills Wanted to recreate the hobbyist $35 dollar model B Anyone remember the BBC Micro? And Defender? Frogger?
Basic setup • Connect keyboard to USB • HDMI out to screen • Ethernet connection • SD card with Raspbian • Power micro USB 700 mA • Lift off!
Running headless • SSH – on by default • Connect with PuTTy or Cygwin • Or Mac Terminal • Can combine with Xwindows • For instance cygwin
Where is my pi? • Static IP address? Conflicts • Dynamic? Yes, but where is it? • sudoapt-get install avahi-daemon
Remoting in • sudo apt-get install xrdp • Windows Remote Desktop • Methods can be combined • Multi user OS!
Sharing files • Set up FTP • apt-get install vsftpd • Edit vsftpd.conf Set up SMB (Samba) apt-get install samba samba-common-bin Edit smb.conf
Wireless connectivity • EDIMax Wireless Nano USB • Edit /etc/network/interfaces • Optionally set up static IP • Set SSID and pass phrase
GPS connectivity • GlobalSat BU-353 USB GPS • apt-get install gpsdgpsd-clients • sudokillallgpsd • sudogpsd /dev/ttyUSB0 –F /var/run/gpsd.sock • cpgs–s • xgps& • gpspipe -r
gpsd • Sockets, JSON • Multiple GPS devices • gpspipe –r > fake.txt • gpsfake –c 3 fake.txt
All set! • Custom solar panel • WiFi • GPS • FTP and Samba • SSH/Remote/XWindows • Let’s write some software!
Installing mono on RPi • apt-get install mono-complete • Interactive prompt, csharp • Compiler: mcs, xbuild • Run mono executable: mono • Demo: hello world! • Mono 2, Hard float, mono 3, armhf
C# on RPi • Let’s write a program that interfaces with GPSD using JSON • Demo program.cs
Adding references, parsing JSON What is JSON? Requesting JSON from gpsd with ?WATCH Deserializing with generics (manual Version class) The modified code cat Program2.cs Adding references for the compiler mcs -sdk:2 -r:System.Runtime.Serialization -r:System.ServiceModel.Web -r:System.Xml Program2.cs Running mono Program2.cs
The gpsd protocol • Handling each kind of JSON object from gpsd • Using JSON2CSharp to get type declarations • The modified Solution in Xamarin Studio • Add References • Copy to device • xbuild • But first…
Summary • What is the Rpi? How to get it set up, headless, file sharing • Wifi and GPS devices • What is Mono, installing it and using C# on Pi • Communication with gpsd, JSON • Calling a REST Service
Resources • Mono armhf 3: https://github.com/alexrp/mono/tree/armhf • Rpi Wiki: http://elinux.org/RPi_Hub • Bing Map Portal: https://www.bingmapsportal.com • JSON2CSharp: http://json2csharp.com • My blog: http://www.cto4hire.net/blog/