Code Monkey home page Code Monkey logo

p0's Introduction

p0

Circle CI

Code Climate

This is a simple Socket.io based event server that stores and streams data from Particle.io sse's.

Getting setup

To run the app locally

  1. Install the dependencies

     npm install
    
  2. Create your own database.json and add in your local database settings

     cp knexfile.example.js knexfile.js
    
  3. Create your own secrets.json and add in your access token from particle.io

     cp config/secrets.example.json config/secrets.json
    
  4. Run the database migrations

     knex migrate:lastest
    
  5. Boot the server

     npm start
    

Adding your plants to the system

There is currently no interface for adding plants to the database, so to do so you'll need to add them via some sql or the bootstrap.json. To add plants via the bootstrap.json, run:

    cp tasks/bootstrap.example.json tasks/bootstrap.json

And then run the boostrap script

    NODE_ENV=production node tasks/bootstrap.js

This will insert the plants into the database.

Sample clientside js

Check out public/client.js for an example of how to set up a js client for the socket.io api. To see the code in action, fire up the server with:

    CLIENT_DEMO=true npm start

and visit localhost:3000.

Running the tests

To run the specs, first run the test database migrations:

    knex migrate:latest --env=test

And then run:

    npm test

Run migrations

API docs

There are two apis:

  • _ http api_

    Provides basic information about the plants on the system.

  • socket api

    Provides streaming data on each plants vitals (humidity, temperature, etc)

HTTP API

List all plants in the system

Request

GET /plants

Parameters

limit

integer, The number of plants to return, 3 by default

offset

integer, The index of of the plant to return as the first in the list

Response

status: 200 OK

{
  uuid: '8080UINNDSOUNSDUI879886NUISDNIUYSDNBISUDNSU',
  email: '[email protected]',
  access_token: {
    uuid: '20808UOFDUINIBNSFIDYNFIDBDFIDFBIYDU',
    token: 'SDFOIM98DSIUN329FDSN977893DSA89DASAS797AS7882',
    expires_at: 2013-05-23 00:12:02.000000000 Z
  }
}

Socket API

Stream plant vitals

namespace: /plants:$plant_id

($plant_id is a variable)

event: moisture data:

{
  "moisture":50
}

p0's People

Contributors

connorwarnock avatar

Watchers

 avatar  avatar

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.