Coder Social home page Coder Social logo

connected-wearables's Introduction

Connected Wearables

The connected wearables project was created for an Etherios hackathon in order to connect data from wearable devices to the Device Cloud by Etherios. The project was created by 3 engineers from Etherios Wireless Design Servies: Paul Osborne (posborne), Tom Manley (tpmanley), and Stephen Stack (swstack).

System Architecture

High Level

The basic architecture for the connected wearables system is pretty simple overall as shown in this architecture diagram.

Architecture Diagram

Notable things from the overall architecture:

  • System consists of two processes. One is just responsible for doing web interface things and the other runs in the background and synchronizes data between the device cloud and humanapi.
  • The two applications share state via a PostgreSQL database with a few simple relations. Data from humanapi is not stored in this database.
  • The web interface allows for configuration of multiple "applications" so that synchronization can happen between multiple humanapi and device cloud accounts.
  • Great care is taken to perform the humanapi -> device cloud synchronization with great efficiency. During the poll period for each logical application, the human api is polled for changes to data for all associated users since the last time we checked -- in turn, those changes are batched in web service calls of up to 250 datapoints and are written to streams on the device cloud.

Implementation Highlights

Cloud Streams Design

Choosing a proper path for data streams based on the data being received from the HumanAPI was a challenge. As there did not seem to be one-size-fits-all solution for all potential consumers of data out of the device cloud, we attempted to provide a few options to that implementor.

For all cases, the following basic stream path format is used:

/human/<userid>/<endpoint>/<field/key>

An example which would include the "steps" for a user over time being:

human/537ac6902f143657390c766e/activities/steps

Mapping from HumanAPI -> Device Cloud Streams

The actual mapping of data from the humanapi data sources to streams in the device cloud is done in an elegant and streamlined fashion. Rather than having loads of code for each endpoint (e.g. activities, blood_glucose, etc.) a generic way to describe the form of the data from HumanAPI and those parts that we want to map to the Device Cloud is used.

This mapping can be found in humanapi_mapping.yml

An example of how the mapping is done for blood_oxygen information is shown here:

# Property	Type	Description
# -----------------------------
# id	    String	The id of the blood oxygen measurement
# userId    String	The global Id of the user
# timestamp Date	The original date and time of the measurement
# source    String	The source service for the measurement, where
it was created
# value	    Number	The value of the measurement in the unit
specified
# unit	    String	The unit of the measurement value
# createdAt Date	The time the measurement was created on the
Human API server
# updatedAt	Date	The time the measurement was updated on the
Human API server
blood_oxygens:
  timestamp_field: timestamp
  forward_fields:
    source: string
    value:
      type: float
      unit_field: unit
    createdAt: datetime
    updatedAt: datetime

Based on this, we know to do things like take the "value" field from humanapi data received on this endpoint and send it along to the device cloud with the stream unit for that stream set to be the "unit" field from the JSON document received from humanapi. This makes changing what gets sent extremely simple.

Developer's Guide

The connected wearables is written for Python 2.7 and is designed to run on Heroku.

System Dependencies

  • Python 2.7
  • Pip
  • Virtualenv
  • PostgreSQL

Install these for your sytem. To setup a virtualenv and install dependencies for development you can do the following:

$ virtualenv env
$ source env/bin/activate
(env) $ pip install -r requirements.txt

Development Database Setup

Although it is possible to tell SQLAlchemy to use sqlite during development, we find it preferrable to install postgresql to minimize difference between production and development platforms.

Create a postgresql user and database:

postgres=# create user cwear password 'cwear';
postgres=# create database cwear owner cwear;

Run the latest migrations:

$ alembic upgrade head

Deploying to Production

As mentioned, heroku is used for deployment. Follow the basic instructions online and things should mostly just work.

If a new version includes changes to the database (captured in an alembic migration) then you will need to run the following to ensure that the migraton happens on the production database.

$ heroku run alembic upgrade head

Other Notes

Limitations

There are a few small issues that are known and probably a bunch that are unknown:

  • No Security on login... Login the first time and an account is created
  • No ability to add devices directly from web app (need to go to human api site)
  • Probably not super robust at this point (but some work done on this)

Underlying Costs

  • Dyno worker costs ~$34/month

Prove it Works

We don't have separate functionality for this. You can view it on the Device Cloud directly.

connected-wearables's People

Contributors

llarntson avatar posborne avatar tpmanley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

llarntson

connected-wearables's Issues

All data points pushed into "/dummy" stream... oops!

So, I was preparing for the demo and it appears that my optimization to batch points from multiple streams is not quite working like I thought it was working... I must have seen old data in the other streams and thought it was recent. This is painfully obvious on a fresh device cloud account.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.