Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Quantified Self: Android Apps for Self Tracking...

Quantified Self: Android Apps for Self Tracking with Wearables and Health-Monitoring Devices

droidcon Berlin 2014 (08.05.2014)

http://bit.ly/1fwME9h

Andreas Schreiber

May 08, 2014
Tweet

More Decks by Andreas Schreiber

Other Decks in Technology

Transcript

  1. 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
  2. Slide 2 www.medando.de Droidcon Berlin 2014, 08.05.2014 My Humble Self

    Scientist, Head of department Co-Founder, CEO Co-Founder
  3. 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
  4. 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
  5. Slide 6 www.medando.de Droidcon Berlin 2014, 08.05.2014 Other Terms •

    Self Tracking • Life Hacking • Life Logging • …
  6. Slide 12 www.medando.de Droidcon Berlin 2014, 08.05.2014 Technologies for Self-Tracking

    0% 10% 20% 30% 40% 50% 60% 70% Mobile phones and apps Web- and desktop applications Self-tracking hardware Self-made desktop 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)
  7. Slide 18 www.medando.de Droidcon Berlin 2014, 08.05.2014 Activity & Location

    (Moves) Source: WDR/Servicezeit, http://bit.ly/DigitaleSelbstvermessung
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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)
  13. 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
  14. 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
  15. 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
  16. 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()
  17. 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)
  18. 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();
  19. 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
  20. 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
  21. 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 developer@med ando.de
  22. 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()
  23. 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"}
  24. 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 }
  25. 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