kryten
A wrapper for johnny-five that lets you define/re-configure a board using JSON and then generates schemaform.io schema for controlling it.
Last updated 4 years ago by virgilvox .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install kryten 
SYNC missed versions from official npm registry.

kryten

A wrapper for johnny-five that lets you define/re-configure a board using JSON and then generates schemaform.io schema for controlling it.

This makes Kryten ideal for IoT. Just pick the messaging/m2m platform of your liking and use JSON to configure and control your board remotely without having to write out an interface.

Kryten is used for various hardware connectors for Octoblu

You can change what io it uses easily - see uncommented lines in example below.

CoffeeScript Example

Kryten = require './index.coffee'
kryten = new Kryten({})

#BLESerialPort = require('ble-serial').SerialPort;
#Firmata = require('firmata').Board;
#kryten = new Kryten({
# io: new Firmata(new BLESerialPort({}))
#})

testOptions =
'autoDetect': true
'port': ''
'interval': '500'
'components': [
  {
    'name': 'Led_Pin_13'
    'action': 'digitalWrite'
    'pin': '13'
  }
  {
    'name': 'some_sensor'
    'action': 'analogRead'
    'pin': '3'
  }
  {
    'name': 'Servo1'
    'action': 'servo'
    'pin': '6'
  }
]

kryten.configure(testOptions)

# You can do it this way too bc its funny if you get it
#kryten.spareHead(testOptions)

kryten.on 'ready', ->
  console.log 'ready to go dog'

  kryten.on 'data', (data)->
    console.log data

  kryten.on 'angular-schema-form', (schema)->
    console.log schema

  state = '1'

  setInterval ->
    kryten.onMessage({component: 'Led_Pin_13', state: state})
    if state == '1'
      state = '0'
    else
      state = '1'
  ,1000

Configure

Essentially you create an array of components to send to the board defining a name, action, and pin or address.

Available Components

'digitalWrite'
'digitalRead'
'analogWrite'
'analogRead'
'servo'
'PCA9685-Servo'
'oled-i2c'
'LCD-PCF8574A'
'LCD-JHD1313M1c'
'MPU6050'
'esc'

Set components

testOptions =
'port': 'auto-detect' #Can be used to specify port
'interval': '500' # Interval at which to send sensor readings
'components': [
  {
    'name': 'Led_Pin_13'
    'action': 'digitalWrite'
    'pin': '13'
  },
  {
    'name': 'Text Display'
    'action': 'oled-i2c'
    'address': '0x3C'
  }
]

Configure Board

kryten.configure(testOptions)

Generated Schema

schemaform.io Message Schema and Formschema
kryten.on 'angular-schema-form', (schema)->
  console.log schema
Schema collection
kryten.on 'config', (schema)->
  console.log schema

Returns collection of schemas for components that were created. So if you configured just one digitalWrite component you would get back this.

{
  "digitalWrite": {
    "title": "Digital Write",
    "type": "object",
    "properties": {
      "component": {
        "title": "Component Name",
        "type": "string",
        "enum": ["Some Component you named"]
      },
      "state": {
        "type": "string",
        "enum": [
          "1",
          "0"
        ]
      }
    }
  },
}

Send Command/payload

For components that take input like digitalWrite, analogWrite, et cetera.

kryten.onMessage({
  payload:
    {
      component: 'Led_Pin_13',
      state: '1'
    }
  })

Message Structure

digitalWrite

{ "payload":
  { "component": "Led_Pin_13",
    "state": "1" | "0"
    }
  }

analogWrite

{ "payload":
  { "component": "Some Analog Thing",
    "value": 0 - 255
    }
  }

Servo

to

{ "payload":
  { "component": "Servo 1",
    "servo_action": "to",
    "to_value": 0 - 180
    }
  }

sweep

{ "payload":
  { "component": "Led_Pin_13",
    "servo_action": "sweep",
    "sweep": {
      "min": 0 - 180,
      "max": 0 - 180
    }
   }
  }

stop

{ "payload":
  { "component": "Servo 1",
    "servo_action": "stop"
    }
  }

Servo Continuous

{ "payload":
  { "component": "Servo Name",
    "direction": "CW, CCW, STOP"
    }
  }

OLED/LCD

{ "payload":
  { "component": "Some display",
    "text": "Some text to display"
    }
  }

ESC

{ "payload":
  { "component": "The Esc",
    "speed": 0 - 255
    }
  }

Kryten

Kryten says don't be a smeg head! Always give credit where credit is due! Open source is awesome, this library is awesome because of awesome people who worked on johnny-five, I just wrapped that awesomeness in bacon.

Current Tags

  • 2.0.4                                ...           latest (4 years ago)

21 Versions

  • 2.0.4                                ...           4 years ago
  • 2.0.3                                ...           4 years ago
  • 2.0.2                                ...           4 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.0.18                                ...           4 years ago
  • 1.0.17                                ...           4 years ago
  • 1.0.16                                ...           4 years ago
  • 1.0.15                                ...           4 years ago
  • 1.0.14                                ...           4 years ago
  • 1.0.13                                ...           4 years ago
  • 1.0.12                                ...           4 years ago
  • 1.0.10                                ...           4 years ago
  • 1.0.9                                ...           4 years ago
  • 1.0.8                                ...           4 years ago
  • 1.0.7                                ...           4 years ago
  • 1.0.6                                ...           4 years ago
  • 1.0.5                                ...           4 years ago
  • 1.0.4                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dev Dependencies (0)
None

Copyright 2014 - 2016 © taobao.org |