0.2.0 • Published 8 years ago

iothing v0.2.0

Weekly downloads
1
License
ISC
Repository
github
Last release
8 years ago

iothing

A Node Framework for IoT

var iothing = require('iothing')
var thing_service = iothing.get('thing')
var thing = thing_service.get('id_1')

thing.action('turn-on-garden-lights', function() {
    console.log('garden lights on !!')
})

thing.cron('nights', '00 * * * * *', function () {
    thing.emit('night')
})

thing.on('night', function () {
    thing.run('turn-on-garden-lights')
})

Installation

$ npm install iothing

Getting started

Create the app :

$ mkdir -p /var/app/config && cd /var/app
$ touch index.js ./config/thing.js

Configuration in config/thing.js :

module.exports = [
    {
        id: 'id_1'
        name: 'my object',
        ip: '127.0.0.1',
        gpios: [
            {name: 'light', pin :1}
        ]
    }    
]

Bootstrap in index.js :

// Loading the Framework
var iothing = require('iothing')
// Loading some services
var thing_service = iothing.get('thing')
var message_service = iothing.get('message')

// Getting a thing instance
var thing = thing_service.get('id_1')

// You can manage you gpio by overriding the value function
thing.gpio({"pin":1}).value = function(value) {
    if (typeof value === 'undefined') {
        return "light is off"
    }
    return "light is on"
}

// Then access your gpios value
message_service.publish('log', thing.gpio({"pin":1}).value())

// You can attach actions to your thing
thing.action('turn-on-garden-lights', function() {
    message_service.broadcast(thing.gpio({"pin":1}).value(1))
})

// You can attach crons to your thing
thing.cron('nights', '00 * * * * *', function () {
    // the thing can emit events
    thing.emit('night')
})

// You can attach listeners to your thing
thing.on('night', function () {
    thing.run('turn-on-garden-lights')
})

Documentation

0.2.0

8 years ago

0.1.0

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago