Cozie

Cozie

    ›Creating your own Cozie

    Getting Started with Cozie Basic

    • Introduction
    • Picking a Fitbit
    • Installing and using Cozie Basic
    • Extracting Data from Cozie Basic
    • Troubleshooting Cozie Basic
    • Example of an Experimental Methodology

    Creating your own Cozie

    • Creating your own Cozie App
    • Installation and setup
    • Fitbit SDK
    • Uploading to the AppStore
    • Datatransfer between the phone and the Fitbit
    • Interacting with GUI elements
    • Switching between screens
    • Sending data to the cloud

    Sending data to the cloud

    We are sending the data from the Cozie application to our cloud database using an AWS Lambda function. The Lambda function listens for any incoming POST requests, checks that the sender has the right API key, process the data and send it to our cloud database.

    We are using AWS Lambda functions, however, valid alternatives are:

    • Google Cloud Functions
    • Node-RED

    You can also use any other cloud database out there, and you are not required to use InfluxDB.

    Please find below the Python code we are currently using in the Lambda function to send the data to our cloud database. Please edit the following line and add your information InfluxDBClient("hostname", 8086, "username",'password', "datatbase", ssl=True, verify_ssl=True).

    from __future__ import print_function
    from influxdb import InfluxDBClient
    import json
    
    
    def lambda_handler(event, context):
        client = InfluxDBClient("hostname", 8086, "username",
            'password', "datatbase", ssl=True, verify_ssl=True)
        try:
    
            print(event["body"])
    
            body = json.loads(event["body"])
    
            fields = {}
    
            for key in body.keys():
                # Check if the key value is an integer or a float
                if isinstance(body[key], int) or isinstance(body[key], float):
                    fields[key] = body[key]
    
            json_body = [{
                'time': body['endFeedback'],
                'measurement': 'fitbitAPI',
                'tags': {'userid': body['user_id'],
                         'experimentid': body['experiment_id']},
                'fields': fields,
                }]
    
            client.write_points(json_body)  # write to InfluxDB
    
            return {
                "statusCode": 200,
                "headers": {
                    "Content-Type": "application/json"
                    },
                "body": "Success"
                }
        except Exception as e:
    
            print(e)
    
            return {
                "statusCode": 500,
                "headers": {
                    "Content-Type": "application/json"
                    },
                "body": e
                }
    
    ← Switching between screensNext →
    Website
    Github
    Twitter
    Copyright © 2020 BUDS-Lab, National University of Singapore