with Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen
Blog:
Home Automation Vision Netduino Azure AppFabric Service Bus Windows Phone 7 What’s Next
Replace legacy sprinkler Current system is overly complicated Conserve on Water Never have to worry about setting the clock Remotely control the sprinkler
Manual operation of Sprinkler Windows Phone 7 operation of Sprinkler Weather Service Sprinkler Scheduled to go on but rain is in the forecast Sprinkler Scheduled to go on but rain is not in the forecast Time Service Powershell
Alarm Clock
Open-source Hardware Open-source.Net Micro Framework 4.1 Released 4.2 Beta Atmel based processor 3 Products Netduino – Pin compatible with Arduino Netduino Plus – Pin compatible with Arduino Netduino Mini – Pin compatible with BS2
Use Arduino Shields to bolt on hardware solutions Stackable Shields Prototype/Breadboard Shield Data logging Shield Ethernet Shield Motor Shield Relay Shield Build your own Shield Joystick Shield
Speed48 mhz Flash Memory128 kb Ram60 kb Digital I/O20 Interrupts20 Analog6 x 10 bit PWM4 x 16 bit I2C1 SPI1 EthernetNo SD CardNo USB1 Serial2 x TTL User LED1 User Switch1
Speed48 mhz Flash Memory 64 kb Ram28 kb Digital I/O20 Interrupts20 Analog6 x 10 bit PWM4 x 16 bit I2C1 SPI1 Ethernet1 10/100 SD Card1 Micro SD USB1 Serial2 x TTL User LED1 User Switch1
Speed48 mhz Flash Memory 152 kb Ram64 kb Digital I/O16 Interrupts16 Analog4 x 10 bit PWM4 x 16 bit I2C1 SPI1 EthernetNo SD CardNo USBNo Serial1 x TTL 1 x RS232 User LEDNo User SwitchNo
One language (C# or VB.Net) across all devices Visual Studio IDE Unit Testing or SpecFlow Debug code that is running on the device Mostly compatible with Arduino Shields
Pull Down Resistor Added
3.3 Volts 5 Volts 1.2 Volts 5 – 3.3 = 1.7
Arduino focused resources Ladyada Tronixstuff
Getting Started with the Internet of Things Netduino Forums Expert.Net Micro Framework Apres
Local parts Radio shack Frys Electronics (off of 85 on the way to Atlanta) Jameco Digikey Adafruit Sparkfun Servo City MakerShed
Opensource Breadboard wiring Schematic Drawing Printed Circuit Board Design
Create a breadboard design Review the schematic Review the Printed Circuit Board design
Launch the Sprinkler Set breakpoints Walk through code
Unit Testing Mocking SpecFlow Integration Testing (Skip)
Limited options for.Net MF Nunitlite Current Release 0.5 .Net MF Support coming in 0.9 Nunit (or any other testing framework) Using Linked files My Blog Post Moq (or any mocking framework) SpecFlow (or any BDD framework)
Unit Tests SpecFlow Mocks Integration Tests
Project structure for Netduino code Unit Testing Harness Link files SpecFlow execution Code Coverage Execution
Web Server Sprinkler Scheduler
Service Bus Host Message Processors
Service Registry (naming and discovery) Message Buffer (no reliability guarantees) Remoting HTTP REST Capable Traverses Firewall Expose on Premise Web Services or Data
Reliable Message Delivery Load Balancing/Partitioning Queues (deprecating Message Buffers) REST interface Groups, Sessions, Dead-lettering, No TTL 1 GB Queue and 256 k Message Size Topics Publish/Subscribe Subscriptions can have Filters and Actions Multiple Subscribers Relies on AppFabric Access Control for securing endpoints Claims based security
PTOPIC S S S C C C C C
Azure Cost Calculator NOTE: This info might not be up to date $3.99 per connection on a “pay-as-you-go” basis (max # connections in a day) Pack of 5 connections $9.95 Pack of 25 connections $49.75 Pack of 100 connections $ Pack of 500 connections $995.00
/ Access Control Service Bus Caching
Sign up (use your MSDN) Access the Azure Management Portal Create a Service Namespace Get your Default Key
3 Simple Steps 1. Define the Service Contract What do you want to expose over the SB? 2. Implement the SC 3. Host the Service Done!!! Note: app.config
Forwards messages to specific devices 1 or more devices might receive the same message Example: Set Clock goes to sprinkler and alarm clock Service Bus ConfigurationRepository places sensitive connection info in a runtime file to keep it out of source control Needs more work to be a Pub/Sub model
HTTP/JSON Service Bus Client
Why? Service Bus cannot be used directly on WP 7 Maybe Message Buffer REST API? More Clients (like iPhone or Android) Expose Service Bus using HTTP REST Intro to RemoteConnector.Web Simple JSON msg processor that calls the Service Bus Can be hosted multiple ways Azure Self Host Shared Hosting Provider
Alternative Light weight Web Framework Can be used in place of ASP.NET MVC Is not dependent on ASP.NET Easy to get up and running fast Easy to configure routes
Sprinkler Status via Browser Review the SprinklerModule and NancyFX Review how the Service Bus is called Show Web.Config bindingExtensions are required when AppFabric SDK is not installed
Sends HTTP Requests to the RemoteConnector Web Site HttpWebRequest Uses Caliburn Micro as the MVVM Framework Watch out for web request/response caching Your request to the RemoteConnector will be cached on the phone if you don’t change query string parms for every request. Keep the messages small
Cloud Services Date Time Weather
Get’s the current time Sends the time via Service Bus
Gets the current weather forecast Sends the forecast via Service Bus
Show MessageBusClient Show Sprinkler.ConsoleClient Show App.Config bindingExtensions are required when AppFabric SDK is not installed
JSON Parsing between.Net Frameworks DateTime in particular Instead of using native DateTime I used a string with a special format MF JSON parsing is painful Look at for a better solutionhttp://netduinohelpers.codeplex.com/ Figuring out WP 7 UI Design Getting the Service Bus working on a Non Development machine. Config settings Building a stand alone sprinkler complete with an LCD and Keyboard and all the menus associated with it for setting up the schedule
Getting the Service bus going in Development Nancy as a Web Framework Debugging Sprinkler Code on Netduino as opposed to other embedded alternatives Having Unit Tests and SpecFlow Tests for the Sprinkler
Simplify Embedded Logic Scheduling
Changing software on the embedded device is time consuming This is especially true after the device is deployed Complex business logic is easier to do in the Full.Net Framework The scheduling logic could be enhanced to support a lot more options The scheduling service could be used by other Home Automation Enthusiasts
Secure the communications Install the sprinkler and let it run Remove the continuous DateTime updates The sprinkler should be able to request DateTime update on power up The service sends the update less frequently and only when daylight savings changes Remove the continuous Weather updates The sprinkler should be able to request the forecast update on power up The weather service should send new forecast when it changes
YOU CAN DO IT!