Skip to content

Instantly share code, notes, and snippets.

@cyrus007
Created June 16, 2015 07:55
Show Gist options
  • Save cyrus007/59fde9569258bb9468b4 to your computer and use it in GitHub Desktop.
Save cyrus007/59fde9569258bb9468b4 to your computer and use it in GitHub Desktop.
Node-Red module to use ezChronos in INPUT pallette
<!-- Swapan Sarkar <swapan@yahoo.com> -->
<script type="text/x-red" data-template-name="chronos">
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="Topic">
</div>
<br/>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="chronos">
<p>Chronos input node. It gets accelerator and button data from the
ez430-chronos watch using the USB dongle attached to the RPi running
NODE-RED.</p>
<p>Outputs an object called <b>msg</b> containing <b>msg.topic</b> and
<b>msg.payload</b>. msg.payload has the JSON object {"b":value, "x":
value, "y":value, "z":value}.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('chronos',{
category: 'input', // the palette category
defaults: { // defines the editable properties of the node
name: {value:""}, // along with default values.
topic: {value:""}
},
inputs:0, // set the number of inputs - only 0 or 1
outputs:1, // set the number of outputs - 0 to n
// set the icon (held in icons dir below where you save the node)
icon: "myicon.png", // saved in icons/myicon.png
color: "#3FADB5",
label: function() { // sets the default label contents
return this.name||this.topic||"chronos";
},
labelStyle: function() { // sets the class to apply to the label
return this.name?"node_label_italic":"";
}
});
</script>
// Node-RED node file for ezChronos
module.exports = function(RED) {
"use strict";
var chronos = require("ez430");
function ChronosNode(n) {
RED.nodes.createNode(this,n);
this.topic = n.topic;
var node = this;
try {
node.chronos = new chronos();
var msg = {};
msg.topic = this.topic;
msg.payload = "Hello from ezChronos module !"
this.send(msg);
// respond to inputs....
//this.on('input', function (msg) {
// node.warn("I saw a payload: "+msg.payload);
// node.send(msg);
//});
this.chronos.on('chronosData', function (b, x, y, z) {
msg.payload = {'b':b, 'x':x, 'y':y, 'z':z};
node.send(msg);
});
} catch (err) { node.warn("can't open Chronos device."); }
this.on("close", function() {
node.chronos.close();
});
};
// Register the node by name. This must be called before overriding any of the
// Node functions.
RED.nodes.registerType("chronos",ChronosNode);
}

node-red-contrib-ezChronos

A Node-RED node to capture data from ez430-chronos watch.

Usage

ezChronos post.

The msg.payload will contain 4 values if available. They are 1) button pressed code 2) accelerometer X value 3) Y value and 4) Z value in JSON object e.g. { "b":value, "x":value, "y":value, "z":value }

{
"name": "node-red-contrib-ezChronos",
"version": "0.0.1",
"description": "A Node-RED node to capture data from the ez430-chronos watch.",
"dependencies": {
"ez430": "0.0.x"
},
"license": "MIT",
"keywords": [ "node-red", "ezChronos" ],
"node-red": {
"nodes": {
"ezChronos": "89-chronos.js"
}
},
"author": {
"name": "Swapan Sarkar",
"email": "swapan@yahoo.com",
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment