0.2.0 • Published 10 years ago

iothing v0.2.0

Weekly downloads
1
License
ISC
Repository
github
Last release
10 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

10 years ago

0.1.0

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago