with netduino, windows azure service bus, and windows phone 7 by mike linnen

63
HOME AUTOMATION with Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Post on 19-Dec-2015

225 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

HOME AUTOMATIONwith Netduino, Windows Azure

Service Bus, and Windows Phone 7

By Mike Linnen

Page 2: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Introduction

Blog: http://www.protosystem.netTwitter: @mlinnenEmail: [email protected]

Page 3: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Outline

Home Automation Vision Netduino Azure AppFabric Service Bus Windows Phone 7 What’s Next

Page 4: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Vision

Page 5: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 6: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Current Sprinkler

Page 7: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 8: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Data Flow – WP7 to Sprinkler

Page 9: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Data Flow – Weather Service to Sprinkler

Page 10: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Data Flow – Time Service to Sprinkler

Alarm Clock

Page 11: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Review the Hardware

Page 12: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 13: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 14: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 15: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 16: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 17: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 18: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Breadboard

Page 19: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Schematic

Page 20: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Driving High Current Loads

Page 21: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Driving High Current Loads

Pull Down Resistor Added

Page 22: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Netduino is 3.3v not 5v

3.3 Volts

5 Volts

1.2 Volts

5 – 3.3 = 1.7

Page 23: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Use 3.3v Instead of 5v

Page 24: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

I need help with Electronics

Arduino focused resources Ladyada http://bit.ly/4JuEvR Tronixstuff http://bit.ly/donqS6

Page 25: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 26: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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/

Page 27: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Fritzing

Opensource Breadboard wiring Schematic Drawing Printed Circuit Board Design

Page 28: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Fritzing Demo

Create a breadboard design Review the schematic Review the Printed Circuit Board design

Page 30: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Getting into Code

Page 31: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Debug Demo

Launch the Sprinkler Set breakpoints Walk through code

Page 32: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

MF Testing Techniques

Unit Testing Mocking SpecFlow Integration Testing (Skip)

Page 33: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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)

Page 34: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Design for Testability

Unit TestsSpecFlow

Mocks

Integration Tests

Page 35: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Demo Netduino Unit Testing

Project structure for Netduino code Unit Testing Harness

Link files SpecFlow execution Code Coverage Execution

Page 36: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Sprinkler

Web ServerSprinkler Scheduler

Page 37: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Demo Sprinkler Code

Page 38: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Home Connector

Service Bus HostMessage Processors

Page 39: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 40: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 41: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

CTP Topics

P TOPIC

S

S

S

C

C

C

C

C

Page 42: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 43: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Cost

Page 44: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Getting Started

http://www.microsoft.com/windowsazure/sdk/

Access Control

Service BusCaching

Page 45: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Azure Platform

Page 46: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Azure Account

Sign up (use your MSDN) Access the Azure Management Portal Create a Service Namespace Get your Default Key

Page 47: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 48: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 49: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Remote Connector

HTTP/JSONService Bus Client

Page 50: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 51: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 52: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 53: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 54: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Home ServicesCloud Services

Date TimeWeather

Page 55: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Date Time Service

Get’s the current time Sends the time via Service Bus

Page 56: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Weather Service

Gets the current weather forecast Sends the forecast via Service Bus

Page 57: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Simple Service Bus Client

Show MessageBusClient Show Sprinkler.ConsoleClient Show App.Config

bindingExtensions are required when AppFabric SDK is not installed

Page 58: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 59: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 60: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

Moving to a Service Based Model

Simplify Embedded LogicScheduling

Page 61: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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

Page 62: With Netduino, Windows Azure Service Bus, and Windows Phone 7 By Mike Linnen

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