3. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Chi siamo
• Fabio Cozzolino
• Chief Software Architect presso CompuGroup Medical Italia
• Microsoft MVP
• Presidente di DotNetSide
• Pasquale Fersini
• Developer presso CompuGroup Medical Italia
4. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Agenda
• Introduzione alla Xamarin Platform
• Monkey Robotics
• Robotics Mobile Stack
• Robotics Micro Stack
6. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Cos’è Xamarin?
• Un framework per lo sviluppo cross-platform su iOS e Android basato
su C#
• Binding alle API native della piattaforma
• Sempre aggiornato
• Il nuovo SDK viene rilasciato entro le 24 ore successive
• Sviluppo su Mac e Windows
• Xamarin Studio
• Visual Studio con Xamarin Plugin
7. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Xamarin Approach
Shared App
Logic
Native UI
C#
Native UI
C#
Shared C# App Logic Shared C# App Logic
Shared App
Logic
Shared
UI
Code
Android
UI Code
Window
s
UI Code
in C#
Shared App
Logic
Shared App
Logic
iOS
UI
Andro
id
UI
Wind
ows
UI Shared UI Code
iOS UI
Android
UI
Windows
UI
Shared App Logic
Shared App
Logic
Native UI
C#
Native UI
C#
Native UI
C#
Shared C# App Logic Shared C# App Logic
Shared App
Logic
Shared
UI
Code
Android
UI Code
Window
s
UI Code
in C#
Shared App
Logic
Shared App
Logic
iOS
UI
Andro
id
UI
Wind
ows
UI Shared UI Code
Model
View and ViewModel
(UI and controller)
Traditional
(80% code reuse)
MVVM con Xamarin.Forms
(99,9% code reuse)
8. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Cos’è Xamarin.Forms?
• UI condivisa
• 40+ Pages, Layouts, Controls
• Compilazione nativa
• Programmazione (anche) dichiarativa con XAML (standard 2009)
• Two-way Data binding
• Commands
• Converters
9. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Xamarin, sensori e l’IoT
• Accesso ai devices
• Bluetooth 4.0 LE? WiFi? NFC?
• Ogni sistema operativo gestisce in maniera differente
• Es. NFC su iOS è limitato, su Windows Phone è invece accessibile
• BLE 4.0 LE è supportato su tutte e tre le principali piattaforme (ma non su tutti
i dispositivi)
• Bluetooth 4.0 Low Energy come protocollo “standard” per la
condivisione di informazioni tra devices
10. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Bluetooth 4.0 LE (aka BLE)
• Tecnologia nata per supportare applicazioni legate alle attività
quotidiane:
• healthcare, fitness, beacons, security e home entertainment
• Riduzione dei consumi a parità di efficienza
• Stessa potenza e range di comunicazione
• Le specifiche definiscono un’implementazione hardware e software
• Nessuna compatibilità con il modello classico (Bluetooth Classic)
11. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
How the Bluetooth works: protocol stack
12. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
How the Bluetooth works: GATT protocol
• Client un device che avvia richieste GATT e
accetta risposte
• Server un device che riceve comandi e richieste
GATT e ritorna risposte
• Characteristic un dato/valore trasferito tra
client e server
• Service una collezione di caratteristiche
correlate che operano insieme per eseguire
una particolare funzionalità
• Descriptor fornisce informazioni addizionali
sulle caratteristiche
13. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Identifiers
• I servizi e le caratteristiche vengono identificati con degli UUID
• Esiste un range riservato di UUID
• https://www.bluetooth.org/en-us/specification/assigned-numbers
• xxxxxxxx-0000-1000-8000-00805F9B34FB
• E’ possibile definire i propri UUID
14. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Servizi e caratteristiche
"00001810-0000-1000-8000-00805f9b34fb":"Blood Pressure"
"00002a49-0000-1000-8000-00805f9b34fb":"Blood Pressure Feature",
"00002a35-0000-1000-8000-00805f9b34fb":"Blood Pressure Measurement",
serviziocaratteristiche
15. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Monkey.Robotics
a.k.a. Xamarin Robotics
16. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Cos’è Monkey.Robotics
• Una libreria open source per la comunicazione con i dispositivi basati
sul .NET Micro Framework
• Progetto di Xamarin Labs
• Formato da due stack:
• Mobile Stack: Supporto per iOS e Android
• Microcontroller Stack: .NET Microframework on Netduino (o schede
compatibili)
• Plug-in per Xamarin Studio
• Utilizzabile anche per la comunicazione con piattaforme non-.NET MF
come Arduino
• Astrazione del protocollo GATT
17. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Monkey.Robotics Overview
18. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Mobile Stack
• Low-level Bluetooth LE (BLE) API
• Cross-platform API (iOS e Android al momento) per la comunicazione con
device BLE
• Low-level WiFI API (in progress)
• Cross-platform API (iOS e Android al momento) che supporta la connessione a
dispositivi WiFi
• Messaging Framework
• High-level cross-platform protocol per l’invio dei messaggi via BLE o WiFi
• Peripheral Libraries
• Strongly typed libraries per la comunicazione con le periferiche specifiche dei
vendors come health monitoring devices, smart watchers, etc…
19. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Mobile Stack: GATT protocol
IAdapter
IDevice IService
ICharacteristic
Scan and Connect to devices
Discover Services
Enumerate Characteristic
Read and Write data
20. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Messaging Framework
HEADER
Magic = 1byte ‘M’
Operation = 1byte
Data Size =1byte
BODY
Data = max 255byte
Checksum = 1byte
21. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
DEMO
Temperatura e umidità
23. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Microcontroller Stack
• Low-level Hardware abstraction
• Modular/compositable basata sul concetto di Blocks and Scopes che
rappresenta devices e listeners
• Sensor and Peripheral Library
• Librerie strongly-typed che semplificano e astraggono l’integrazione con
centinaia di sensori come Alcohol Sensors o 3-axis Accelerometers
25. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Scopes & Blocks
BLOCKS
Rappresentano l'astrazione
di oggetti attivi
(devices, convertitori, etc.)
ed espongono
OutputPort ed InputPort
SCOPES
Rappresentano gestori di
output
27. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
What drivers ?
5 gruppi:
• Base Devices
• Generators
• Motors
• Sensors
Gruppo speciale:
• Specialized Blocks
28. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Protocol Matrix
• Tabella protocolli di comunicazione per piattaforme embedded
29. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Base Devices
Costituiscono il "cuore" della board e sono:
• DigitalInputPin
• DigitalOutputPin
• AnalogInputPin
• PwmOutputPin
30. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Generators
Sono i generatori di onda e l'implementazione attuale ne prevede due tipi:
• Sine Wave
• PWM (Pulse Width Modulation)
Motors
Astraggono il funzionamento dei motori elettrici per due modelli di hardware:
• AdafruitMotorShield
• HBridgeMotors
31. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Sensors
• Button -> Pulsanti, Switch, ...
• LightSensor -> Fotoresistenze, ...
• Location -> Bussole digitali, barometri, ...
• Motion -> Accelerometri, ...
• Proximity -> Sensori ad infrarossi, ...
• Temperature -> Termometri digitali, sonde ntc, ...
32. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Specialized Blocks
Ereditano dalla classe Block
• PollingBlock
• Scambio di dati tra periferiche ad intervalli di tempo regolari.
• I2CPollingBlock
• Scambio di dati tra periferiche I2C ad intervalli di tempo regolari.
• Wrapper delle "consuete" chiamate ai dispositivi i2C.
• Prossimo futuro -> SPIPollingBlock ???
33. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Netduino
● STMicro 32-bit CPU - STM32F405RG
● Speed: 168MHz
● Code Storage: 384 KB
● SRAM: 192 KB
● digital pins 0-1: UART 1 RX, TX
● digital pins 2-3: UART 2 RX, TX/PWM
● digital pins 5-6: PWM, PWM
● digital pins 7-8: UART 3 RX, TX
● digital pins 9-10: PWM, PWM
● digital pins 11-13: PWM/MOSI, MISO, SPCK
● digital pin SD/SC: SDA/SCL
34. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Adafruit Motor Shield
● 2 servomotori da 5V;
● 2 Ponti-H: Toshiba TB6612 per motori da 1.2A;
● Protezione termica dall'overload;
● 4 motori DC bidirezionali;
● 2 motori passo passo;
● protezione termica della polarità.
35. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
BLE 4 Mini - RedbearLab
● Semplice interfaccia RS232 per piattaforme embedded;
● Texas Intruments's CC2540 (CPU indipendente);
● Firmware upgradabile via USB;
● Predisposizione per collegare un'antenna esterna;
● Alimentabile da 3.4V a 11V o con batteria esterna da 3.7V.
36. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
DHT22
● Tensione di lavoro: 3-5V;
● Umidità rilevabile: 0%-100%, accuratezza 2-5%;
● Temperatura rilevabile: -40° to 125°C, ±0.5°C accuracy;
● Comunicazione a lunga distanza (oltre 50 m);
● Protocollo OneWire proprietario.
37. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Recap
• Monkey.Robotics per astrarre la comunicazione tra mobile e micro
• Monkey.Robotics per lo sviluppo embedded multipiattaforma
• Monkey.Robotics per lo sviluppo embedded rapido
• Su GitHub
• https://github.com/xamarin/Monkey.Robotics
• @xamarinrobotics
38. #CDays14 – Milano 25, 26 e 27 Febbraio 2014
Q&A
Tutto il materiale di questa sessione su
http://www.communitydays.it/
Lascia subito il feedback su questa sessione,
potrai essere estratto per i nostri premi!
Seguici su
Twitter @CommunityDaysIT
Facebook http://facebook.com/cdaysit
#CDays15
Hinweis der Redaktion
Slide da mostrare prima di iniziare la sessione – non rimuovere!
GENERIC ATTRIBUTE PROFILE
The GATT protocol provides a number of commands for the client to discover information about the server. These include:
Discover UUIDs for all primary services
Find a service with a given UUID
Find secondary services for a given primary service
Discover all characteristics for a given service
Find characteristics matching a given UUID
Read all descriptors for a particular characteristic
Commands are also provided to read (data transfer from server to client) and write (from client to server) the values of characteristics:
A value may be read either by specifying the characteristic's UUID, or by a handle value (which is returned by the information discovery commands above).
Write operations always identify the characteristic by handle, but have a choice of whether or not a response from the server is required.
'Long read' and 'Long write' operations can be used when the length of the characteristic's data exceeds the MTU of the radio link.
Finally, GATT offers notifications and indications. The client may request a notification for a particular characteristic from the server. The server can then send the value to the client whenever it becomes available. For instance, a temperature sensor server may notify its client every time it takes a measurement. This avoids the need for the client to poll the server, which would require the server's radio circuitry to be constantly operational.
An indication is similar to a notification, except that it requires a response from the client, as confirmation that it has received the message.