20140508 quantified self droidcon

49
www.medando.de Quantified Self Android Apps for Self Tracking with Wearables and Health- Monitoring Devices Andreas Schreiber <[email protected]> Droidcon Berlin, 08.05.2014

Upload: droidcon-berlin

Post on 11-Sep-2014

595 views

Category:

Documents


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: 20140508 quantified self droidcon

www.medando.de

Quantified Self Android Apps for Self Tracking with Wearables and Health-Monitoring Devices Andreas Schreiber <[email protected]>

Droidcon Berlin, 08.05.2014

Page 2: 20140508 quantified self droidcon

Slide 2 www.medando.de Droidcon Berlin 2014, 08.05.2014

My Humble Self

Scientist, Head of department

Co-Founder, CEO

Co-Founder

Page 3: 20140508 quantified self droidcon

Slide 3 www.medando.de Droidcon Berlin 2014, 08.05.2014

My Self Tracking

• With sensors

• With smartphone apps

Source: SAT.1/Weckup, http://bit.ly/10CEfUX

Page 4: 20140508 quantified self droidcon

Slide 4 www.medando.de Droidcon Berlin 2014, 08.05.2014

Page 5: 20140508 quantified self droidcon

Slide 5 www.medando.de Droidcon Berlin 2014, 08.05.2014

What is The Quantified Self?

Self-knowledge through numbers

• Analyze trends and set goals to improve yourself

Recording of daily activities

• Fitness, sleep, location, …

• Monitoring and display of information from various devices, services, and applications

Page 6: 20140508 quantified self droidcon

Slide 6 www.medando.de Droidcon Berlin 2014, 08.05.2014

Other Terms

• Self Tracking

• Life Hacking

• Life Logging

• …

Page 7: 20140508 quantified self droidcon

Slide 7 www.medando.de Droidcon Berlin 2014, 08.05.2014

Google Trends: “Quantified Self”

Page 8: 20140508 quantified self droidcon

Slide 8 www.medando.de Droidcon Berlin 2014, 08.05.2014

Google Trends: “Quantified Self”

Page 9: 20140508 quantified self droidcon

Slide 9 www.medando.de Droidcon Berlin 2014, 08.05.2014

Quantified Self Meetups

http://quantified-self.meetup.com

Page 10: 20140508 quantified self droidcon

Slide 10 www.medando.de Droidcon Berlin 2014, 08.05.2014

Objects of Tracking

Page 11: 20140508 quantified self droidcon

Slide 11 www.medando.de Droidcon Berlin 2014, 08.05.2014

Wearable Sensors, Devices, and Apps

Page 12: 20140508 quantified self droidcon

Slide 12 www.medando.de Droidcon Berlin 2014, 08.05.2014

Technologies for Self-Tracking

0%

10%

20%

30%

40%

50%

60%

70%

Mobile phonesand apps

Web- anddesktop

applications

Self-trackinghardware

Self-madedesktop tools(spreadsheets

etc.)

Pen and paper Other

Deployed technologies for self-tracking

Source: Marcia Nißen, Quantified Self – An Exploratory Study on the Profiles and Motivations of Self-Tracking, Bachelor Thesis (2013)

Page 13: 20140508 quantified self droidcon

Slide 13 www.medando.de Droidcon Berlin 2014, 08.05.2014

Steps (Fitbit)

Page 14: 20140508 quantified self droidcon

Slide 14 www.medando.de Droidcon Berlin 2014, 08.05.2014

Weight (Withings)

Page 15: 20140508 quantified self droidcon

Slide 15 www.medando.de Droidcon Berlin 2014, 08.05.2014

Stress (W/Me)

Page 16: 20140508 quantified self droidcon

Slide 16 www.medando.de Droidcon Berlin 2014, 08.05.2014

Sleep (Sleep as Android)

Page 17: 20140508 quantified self droidcon

Slide 17 www.medando.de Droidcon Berlin 2014, 08.05.2014

Blood Pressure (BloodpressureCompanion)

Page 18: 20140508 quantified self droidcon

Slide 18 www.medando.de Droidcon Berlin 2014, 08.05.2014

Activity & Location (Moves)

Source: WDR/Servicezeit, http://bit.ly/DigitaleSelbstvermessung

Page 19: 20140508 quantified self droidcon

Slide 19 www.medando.de Droidcon Berlin 2014, 08.05.2014

Activity & Location (Moves)

Page 20: 20140508 quantified self droidcon

Slide 20 www.medando.de Droidcon Berlin 2014, 08.05.2014

Car (Dash)

Page 21: 20140508 quantified self droidcon

Slide 21 www.medando.de Droidcon Berlin 2014, 08.05.2014

Mobile Phone Usage & Well-being (Menthal)

Page 22: 20140508 quantified self droidcon

Slide 23 www.medando.de Droidcon Berlin 2014, 08.05.2014

WeightCompanion

Page 23: 20140508 quantified self droidcon

Slide 24 www.medando.de Droidcon Berlin 2014, 08.05.2014

Analysis: Blood Pressure vs. Weight

Page 24: 20140508 quantified self droidcon

Slide 25 www.medando.de Droidcon Berlin 2014, 08.05.2014

Sharing

Page 25: 20140508 quantified self droidcon

Slide 26 www.medando.de Droidcon Berlin 2014, 08.05.2014

Connecting Devices & Apps

Page 26: 20140508 quantified self droidcon

Slide 27 www.medando.de Droidcon Berlin 2014, 08.05.2014

The Internet of Things

Page 27: 20140508 quantified self droidcon

Slide 28 www.medando.de Droidcon Berlin 2014, 08.05.2014

Internet of Things

Billions of devices, sensors, and chips

• Connected physical objects (devices)

• Embedded controllers, sensors, actuators

• Connected via the internet

• Uniquely identified

• They interact

Page 28: 20140508 quantified self droidcon

Slide 29 www.medando.de Droidcon Berlin 2014, 08.05.2014

Growth

Number of devices connected to the internet grow every day

50.000.000.000 “Things” by 2020

Page 29: 20140508 quantified self droidcon

Slide 30 www.medando.de Droidcon Berlin 2014, 08.05.2014

Communication

Internet of Things

Communication infrastructure

Page 30: 20140508 quantified self droidcon

Slide 31 www.medando.de Droidcon Berlin 2014, 08.05.2014

MQTT

MQ Telemetry Transport

• Machine-to-machine (M2M) connectivity protocol

• Publish/subscribe messaging

• Expect unreliable networks with low bandwidth and high latency

• Expect clients with limited processing resources

• Provides Quality of Service, if network allows

• Easy to implement

Page 31: 20140508 quantified self droidcon

Slide 32 www.medando.de Droidcon Berlin 2014, 08.05.2014

MQTT Broker

MQTT broker

MQTT broker

Client

Client

Client

Client

publish

subscribe topic/subtopic

(optional) bridge

Client

Page 32: 20140508 quantified self droidcon

Slide 33 www.medando.de Droidcon Berlin 2014, 08.05.2014

MQTT Protocol

• One-to-many message distribution over TCP/IP

• Notifies if clients disconnect abnormally

• Message format

• Fixed 2-byte header

• Variable header for some message type

• Payload (e.g., the topic or small pieces of data)

Page 33: 20140508 quantified self droidcon

Slide 34 www.medando.de Droidcon Berlin 2014, 08.05.2014

MQTT Topics

• Messages in MQTT are published on topics

• No need to configure, just publish on it

• Topics are hierarchical, with “/” as separator

my/home/temperature/kitchen my/home/temperature/livingroom my/server/temperature

Page 34: 20140508 quantified self droidcon

Slide 35 www.medando.de Droidcon Berlin 2014, 08.05.2014

MQTT Implementations

Server/Broker • Mosquitto • Eclipse Paho • IBM Websphere MQ • RSMB • MQTT.js • Apache ActiveMQ • RabittMQ • HiveMQ

Client Libraries for • C/C++ • Java • Python • Perl • PHP • Ruby • …

http://mqtt.org/wiki/software

Page 35: 20140508 quantified self droidcon

Slide 36 www.medando.de Droidcon Berlin 2014, 08.05.2014

Open Source Broker Mosquitto

Implemented in C. Fast. Small.

For testing: Publicly available Mosquitto MQTT broker

Page 36: 20140508 quantified self droidcon

Slide 37 www.medando.de Droidcon Berlin 2014, 08.05.2014

Subscribe

import import paho.mqtt.client as paho def on_message(mosq, obj, msg): print(msg.topic + ' ' + str(msg.payload)) mqtt_client = paho.Mosquitto() mqtt_client.on_message = on_message mqtt_client.connect('test.mosquitto.org') mqtt_client.subscribe('#', 0) # all topics return_code = 0 while return_code == 0: return_code = mqtt_client.loop()

Page 37: 20140508 quantified self droidcon

Slide 38 www.medando.de Droidcon Berlin 2014, 08.05.2014

Publish

import paho.mqtt.client as paho mqtt_client = paho.Mosquitto() mqtt_client.connect('test.mosquitto.org') mqtt_client.publish(‘droidcon/demo', 'hello world', 1)

Page 38: 20140508 quantified self droidcon

Slide 39 www.medando.de Droidcon Berlin 2014, 08.05.2014

MQTT on Android

Eclipse Paho (http://www.eclipse.org/paho)

import org.eclipse.paho.client.mqttv3.MqttClient; import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttMessage; . . . client = new MqttClient("tcp://localhost:1883", "myJavaClient"); client.connect(); MqttMessage message = new MqttMessage(); message.setPayload("Hello World".getBytes()); client.publish("droidcon/demo", message); client.disconnect();

Page 39: 20140508 quantified self droidcon

Slide 40 www.medando.de Droidcon Berlin 2014, 08.05.2014

Android Push Notifications

Getting data from Quantified Self gadgets to Android

• The Gadget sends data to “somewhere” in the Cloud

• Withings, Fitbit, etc. provide APIs to access the data

• Register for callbacks to get notifications

• We use a Django app that registers as callback listener and send MQTT messages on updates

• MQTT Java client on Android receives notifications

Page 40: 20140508 quantified self droidcon

Slide 41 www.medando.de Droidcon Berlin 2014, 08.05.2014

MQTT Push Notification Architecture

Django App

MQTT broker

Gadget Vendor

(API)

Gadget

Android phone

publish notification

measure- ments

register phone

register callback receives callbacks

send messages

Page 41: 20140508 quantified self droidcon

Slide 42 www.medando.de Droidcon Berlin 2014, 08.05.2014

Implementation & Deployment

• Implementation includes OAuth stuff

• Most complex part was the Java code on Android (error handling etc.)

• Deployment on Amazon Web Services

Django/Mosquitto

EC2 instance

User/Device registry

Apps

Withings

Elastic IP Amazon

CloudWatch Alarm

SNS [email protected]

Page 42: 20140508 quantified self droidcon

Slide 43 www.medando.de Droidcon Berlin 2014, 08.05.2014

Callback Implementation (Withings)

def callback(request): """ Callback function for Withings notifications. """ . . . # request parameter handling devices = RegisteredWithingsUser.objects.filter(user_id=user_id) mqtt_client = MosquittoHandler(len(devices)) for device in devices: device_id = device.device_id mqtt_topic = 'medando/weightcompanion/weights/%s/%s' % (user_id, device_id) payload = simplejson.dumps({'startdate': startdate, 'enddate': enddate}) mqtt_client.publish(mqtt_topic, payload, 2, True) mqtt_client.wait()

Page 43: 20140508 quantified self droidcon

Slide 44 www.medando.de Droidcon Berlin 2014, 08.05.2014

MQTT Messages

medando/weightcompanion/weights/1883073/34bae8cbe8dd92f3 0 {"startdate": "1371856646", "enddate": "1371856647"} medando/weightcompanion/weights/1791607/898efc38ac5d4211 0 {"startdate": "1372742400", "enddate": "1372742401"} medando/weightcompanion/weights/1527601/2ebcf034b8585668 0 {"startdate": "1368851117", "enddate": "1368851118"} medando/weightcompanion/weights/16121/f2a8ca66fd067954 0 {"startdate": "1372750563", "enddate": "1372750564"} medando/weightcompanion/weights/449599/4d701e076912648f 0 {"startdate": "1372751111", "enddate": "1372751112"} medando/weightcompanion/weights/642578/b33356881163a389 0 {"startdate": "1370585275", "enddate": "1370585276"} medando/weightcompanion/weights/2019258/33b1d416aeaec9ef 0 {"startdate": "1371377131", "enddate": "1371377132"} medando/weightcompanion/weights/2019258/61bdf242b37d8a29 0 {"startdate": "1371377131", "enddate": "1371377132"}

medando/weightcompanion/weights/2019258/61bdf242b37d8a29 0 {"startdate": "1371377131", "enddate": "1371377132"}

Page 44: 20140508 quantified self droidcon

Slide 45 www.medando.de Droidcon Berlin 2014, 08.05.2014

Notification on Android

Page 45: 20140508 quantified self droidcon

Slide 46 www.medando.de Droidcon Berlin 2014, 08.05.2014

Status Page

Page 46: 20140508 quantified self droidcon

Slide 47 www.medando.de Droidcon Berlin 2014, 08.05.2014

Sending MQTT from Android

WeightCompanion

• Experimental feature

• User defines MQTT topic

• Weight as Payload (JSON)

{ "unit":"kg", "weight":80.1 }

Page 47: 20140508 quantified self droidcon

Slide 48 www.medando.de Droidcon Berlin 2014, 08.05.2014

Page 48: 20140508 quantified self droidcon

Slide 49 www.medando.de Droidcon Berlin 2014, 08.05.2014

Conclusions

• Quantified Self community is growing

• Many devices and apps

• Mobile! Wearable!

• Communication in the IoT

• Messaging with MQTT

• Platform independent push notification services

Source: Kölner Stadt-Anzeiger, http://bit.ly/JsnQ3s

Page 49: 20140508 quantified self droidcon

Slide 50 www.medando.de Droidcon Berlin 2014, 08.05.2014

Questions?

[email protected]

@MedandoDE | @onyame