# iothing

> A Node Framework for IoT

Latest version **0.2.0** (published 2016-06-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install iothing
pnpm add iothing
yarn add iothing
bun add iothing
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2016-06-14 |
| First published | 2016-01-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Flavien Rodrigues |
| Maintainers | rflavien |
| Keywords | IoT |

## Links

- npm: https://www.npmjs.com/package/iothing
- Repository: https://github.com/rflavien/iothing
- Homepage: https://github.com/rflavien/iothing#readme
- Issues: https://github.com/rflavien/iothing/issues
- npm.io page: https://npm.io/package/iothing

## Dependencies (3)

- [cron](https://npm.io/package/cron.md) ^1.1.0
- [slug](https://npm.io/package/slug.md) ^0.9.1
- [express](https://npm.io/package/express.md) ^4.13.4

## Recent versions

- 0.2.0 (latest) — 2016-06-14
- 0.1.0 — 2016-02-05
- 0.0.6 — 2016-01-28
- 0.0.5 — 2016-01-27
- 0.0.4 — 2016-01-27
- 0.0.3 — 2016-01-27
- 0.0.2 — 2016-01-27
- 0.0.1 — 2016-01-27

## README

# iothing
A Node Framework for IoT

```js
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
```bash
$ npm install iothing
```

## Getting started
Create the app :
```bash
$ mkdir -p /var/app/config && cd /var/app
$ touch index.js ./config/thing.js
```

Configuration in __config/thing.js__ :
```js
module.exports = [
    {
        id: 'id_1'
        name: 'my object',
        ip: '127.0.0.1',
        gpios: [
            {name: 'light', pin :1}
        ]
    }    
]
```
Bootstrap in __index.js__ :
```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
- [Documentation page](http://rflavien.github.io/iothing)
- [GitHub repository](https://github.com/rflavien/iothing)

---
_Source: https://npm.io/package/iothing · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
