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

cylon-api-socketio

v0.4.0

Published

Socket.io API add-on module for Cylon.JS

Downloads

17

Readme

Cylon.js API Plugin For Socket.io

Cylon.js (http://cylonjs.com) is a JavaScript framework for robotics, physical computing, and the Internet of Things using Node.js

API plugins are separate from the Cylon.js main module, to make everything more modular and at the same time make Cylon.js lighter.

This repository contains the Cylon API plugin for Socket.io

For more information about Cylon, check out the repo at https://github.com/hybridgroup/cylon

Build Status Code Climate Test Coverage

How to Install

$ npm install cylon cylon-api-socketio

How to Use

Make sure you have Cylon.js installed, then we can add Socket.io support to cylon programs as follows:

'use strict';

var Cylon = require('cylon');

Cylon.robot({
  name: 'rosie',

  connections: {
    arduino: { adaptor: 'firmata', port: '/dev/ttyACM0' }
  },

  devices: {
    led: { driver: 'led', pin: 13 }
  },

  work: function() {
    // for this example with sockets
    // we are going to be interacting
    // with the robot using the code in
    // ./**-client.html
  }
});

// ensure you install the API plugin first:
// $ npm install cylon-api-socket-io
Cylon.api('socketio',
{
  host: '0.0.0.0',
  port: '3000'
});

Cylon.start();

How to Connect

Once you have added the api to your Cylon.js code, and your robots are up and running, you can connect to them using Socket.io using the following code:

<!doctype html>
<html>
  <meta charset="utf-8">
  <head>
    <title>Simple Device Example</title>
    <style>
      * { margin: 0; padding: 0; box-sizing: border-box; }
      body { font: 13px Helvetica, Arial; }
      form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
      form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
      form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
      #messages { list-style-type: none; margin: 0; padding: 0; }
      #messages li { padding: 5px 10px; }
      #messages li:nth-child(odd) { background: #eee; }
    </style>
  </head>
  <script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
  <script src="http://code.jquery.com/jquery-1.11.1.js"></script>
  <script type="text/javascript">
    var device;

    window.onload = function() {
      console.log('Setting up socket connections:');

      // We use the robot nsp (namespace) to connect to one of the devices
      // in this case the led we added in our cylon robot code
      device = io('http://127.0.0.1:3000/api/robots/rosie/devices/led');
      setInterval(function() {
        // There are two ways to send commands to a device,
        // The first one (we preffer this one) is by emitting
        // an event using the name of the command for the event,
        // and passing the params as regular function args.
        // eg. device.emit('angle', 180[, param2, param3, ...]);
        device.emit('toggle');

        /*
        // In the second one you emit a 'command' event and
        // pass the command specifics inside an object.
        device.emit(
          'command',
          {
            name: 'angle',
            args: [180, 'arg2', 'arg3']
          }
        );'
        */
      }, 1000);

      device.on('message', function(payload) {
        console.log('On Device');
        console.log('  Event:', payload.event);
        console.log('  Data:', payload.data);
        $('#messages').append($('<li>').text('On Device:'));
        $('#messages').append($('<li>').text('  Event:' + payload.event.toString()));
        if (!!payload.data) {
          $('#messages').append($('<li>').text('  Data:' + payload.data.toString()));
        }
        $('#messages').append($('<hr />'));
      });

      msg = 'You have been subscribed to Cylon sockets:' + device.nsp;

      $('#messages').append($('<li>').text(msg));
    };
  </script>
  <body>
    <ul id="messages"></ul>
  </body>
</html>

Documentation

We're busy adding documentation to cylonjs.com. Please check there as we continue to work on Cylon.js.

Thank you!

Contributing

For our contribution guidelines, please go to https://github.com/hybridgroup/cylon/blob/master/CONTRIBUTING.md.

Release History

For the release history, please go to https://github.com/hybridgroup/cylon-api-socketio/blob/master/RELEASES.md.

License

Copyright (c) 2014-2015 The Hybrid Group. Licensed under the Apache 2.0 license.