npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kryten

v2.0.4

Published

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

Downloads

56

Readme

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.