with netduino, windows azure service bus, and windows phone 7 by mike linnen
Post on 19-Dec-2015
225 views
TRANSCRIPT
HOME AUTOMATIONwith Netduino, Windows Azure
Service Bus, and Windows Phone 7
By Mike Linnen
Introduction
Blog: http://www.protosystem.netTwitter: @mlinnenEmail: [email protected]
Outline
Home Automation Vision Netduino Azure AppFabric Service Bus Windows Phone 7 What’s Next
Vision
Lawn Sprinkler Goals
Replace legacy sprinkler Current system is overly complicated
Conserve on Water Never have to worry about setting the
clock Remotely control the sprinkler
Current Sprinkler
Demo
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
Data Flow – WP7 to Sprinkler
Data Flow – Weather Service to Sprinkler
Data Flow – Time Service to Sprinkler
Alarm Clock
Review the Hardware
Netduino Products
http://www.netduino.com/ 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
Extending Netduino Hardware
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
NetduinoSpeed 48 mhz
Flash Memory 128 kb
Ram 60 kb
Digital I/O 20
Interrupts 20
Analog 6 x 10 bit
PWM 4 x 16 bit
I2C 1
SPI 1
Ethernet No
SD Card No
USB 1
Serial 2 x TTL
User LED 1
User Switch 1
Netduino PlusSpeed 48 mhz
Flash Memory 64 kb
Ram 28 kb
Digital I/O 20
Interrupts 20
Analog 6 x 10 bit
PWM 4 x 16 bit
I2C 1
SPI 1
Ethernet 1 10/100
SD Card 1 Micro SD
USB 1
Serial 2 x TTL
User LED 1
User Switch 1
Netduino MiniSpeed 48 mhz
Flash Memory
152 kb
Ram 64 kb
Digital I/O 16
Interrupts 16
Analog 4 x 10 bit
PWM 4 x 16 bit
I2C 1
SPI 1
Ethernet No
SD Card No
USB No
Serial 1 x TTL 1 x RS232
User LED No
User Switch No
Why use Netduino?
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
Breadboard
Schematic
Driving High Current Loads
Driving High Current Loads
Pull Down Resistor Added
Netduino is 3.3v not 5v
3.3 Volts
5 Volts
1.2 Volts
5 – 3.3 = 1.7
Use 3.3v Instead of 5v
I need help with Electronics
Arduino focused resources Ladyada http://bit.ly/4JuEvR Tronixstuff http://bit.ly/donqS6
I need help with Programming
Getting Started with the Internet of Things http://oreilly.com/catalog/0636920013037
Netduino Forums http://netduinohelpers.codeplex.com/ Expert .Net Micro Framework Apres
Parts
Local parts Radio shack Frys Electronics (off of 85 on the way to
Atlanta) Jameco http://www.jameco.com Digikey http://www.digikey.com/ Adafruit http://www.adafruit.com/ Sparkfun http://www.sparkfun.com/ Servo City http://www.servocity.com/ MakerShed http://www.makershed.com/
Fritzing
Opensource Breadboard wiring Schematic Drawing Printed Circuit Board Design
Fritzing Demo
Create a breadboard design Review the schematic Review the Printed Circuit Board design
.Net Gadgeteer
http://netmf.com/gadgeteer/
Getting into Code
Debug Demo
Launch the Sprinkler Set breakpoints Walk through code
MF Testing Techniques
Unit Testing Mocking SpecFlow Integration Testing (Skip)
Unit Testing Frameworks
Limited options for .Net MF Nunitlite http://nunitlite.com/
Current Release 0.5 .Net MF Support coming in 0.9
Nunit (or any other testing framework) Using Linked files My Blog Post http://bit.ly/dM9nlf Moq (or any mocking framework) SpecFlow (or any BDD framework)
Design for Testability
Unit TestsSpecFlow
Mocks
Integration Tests
Demo Netduino Unit Testing
Project structure for Netduino code Unit Testing Harness
Link files SpecFlow execution Code Coverage Execution
Sprinkler
Web ServerSprinkler Scheduler
Demo Sprinkler Code
Home Connector
Service Bus HostMessage Processors
Azure AppFabric Service Bus 1.0
Service Registry (naming and discovery) Message Buffer (no reliability guarantees) Remoting HTTP REST Capable Traverses Firewall Expose on Premise Web Services or Data
Azure AppFabric Service Bus CTP
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
CTP Topics
P TOPIC
S
S
S
C
C
C
C
C
Cost
Azure Cost Calculator http://bit.ly/m9xGfz 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 $199.00 Pack of 500 connections $995.00
Cost
Getting Started
http://www.microsoft.com/windowsazure/sdk/
Access Control
Service BusCaching
Azure Platform
Azure Account
Sign up (use your MSDN) Access the Azure Management Portal Create a Service Namespace Get your Default Key
Code: Service Bus
3 Simple Steps 1. Define the Service Contract
What do you want to expose over the SB?
2. Implement the SC3. Host the Service
Done!!!Note: app.config
Home Connector MSG Processor
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
Remote Connector
HTTP/JSONService Bus Client
Exposing SB to WP 7
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
NancyFX
https://github.com/NancyFx/Nancy 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
Demo & Code
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
WP 7 Remote Controller
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
Home ServicesCloud Services
Date TimeWeather
Date Time Service
Get’s the current time Sends the time via Service Bus
Weather Service
Gets the current weather forecast Sends the forecast via Service Bus
Simple Service Bus Client
Show MessageBusClient Show Sprinkler.ConsoleClient Show App.Config
bindingExtensions are required when AppFabric SDK is not installed
What was hard
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 http://netduinohelpers.codeplex.com/ for a better solution
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
What was easy
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
Moving to a Service Based Model
Simplify Embedded LogicScheduling
Why Service Base Model
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
What is Next
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
Done
YOU CAN DO IT!
https://bitbucket.org/mlinnen/lawnsprinklerhttp://www.protosystem.net/