Skip to content

Instantly share code, notes, and snippets.

View jarrodbell's full-sized avatar

Jarrod Bell jarrodbell

View GitHub Profile
@jarrodbell
jarrodbell / main.js
Last active January 8, 2018 22:35
Simple buffering and processing of CFLink packets
var cflinkRegex = /\xF2([\s\S])\xF3([QCTR])(\w{3})(\w{3})\xF4([\s\S]*?)\xF5\xF5/g; // Capture groups: ID, Command Type, Device, Command, Data
var rcvBuffer;
function incomingData(fbName, rcv) {
// Append new incoming data to buffer
rcvBuffer += rcv;
var matches;
var matchedData = "";
// Loop through any complete CFLink packets
@jarrodbell
jarrodbell / ipSymcon.js
Created July 25, 2017 23:34
Integrate IP-Symcon with CommandFusion iViewer
// Change these variables to suit your setup
var username = "admin";
var password = "password";
var ipAddress = "192.168.0.100";
// Call this function from your button press like this:
// sendToIPSymcon("SetValue", [12345, 42]);
// sendToIPSymcon("SetValue", [12346, false]);
function sendToIPSymcon(method, params) {
CF.request("http://" + username + ":" + password + "@" + ipAddress + ":3777/api/", "POST", {"Content-Type": "application/json"}, {"jsonrpc": "2.0", "id": "0", "method": method, "params": params}, function (status, headers, body) {
@jarrodbell
jarrodbell / main.js
Last active February 21, 2016 23:58
Cisco Telepresence call history processing example
// Create an object that we can update as we get data in, before adding a complete entry to a list
var currentCallData = {};
CF.userMain = function() {
// The regex for this feedback item should be: CallHistoryRecentResults Entry (\d+)
CF.watch(CF.FeedbackMatchedEvent, "TELEPRESENCE", "HISTORY_CALL_FEEDBACK", function(fbName, data) {
// We get three rows of data for each actual call:
// CallHistoryRecentsResult Entry 0 CallbackNumber: "sip:555...@domain.com"
// CallHistoryRecentsResult Entry 0 DisplayName: "5557777"
@jarrodbell
jarrodbell / gist:6631f2ff6268ac36659a
Created May 1, 2015 00:08
Heatmiser Data Processing
// Code to run on startup
CF.userMain = function() {
// watch the feedback coming from the system, adjust the values to match the system name and feedback name in your guiDesigner project
CF.watch(CF.FeedbackMatchedEvent, "HeatmiserWired", "Capture", function(fbName, data) {
dataBuffer += data; // Append the incoming data to the buffer, now process it
var MessageCount = 0;
while ((matches = dataRegex.exec(dataBuffer)) !== null) {
if (matches) {
var length = matches[1].charCodeAt(0); // Get the length decimal value
if (dataBuffer.length >= (length + lengthAdd)) {
@jarrodbell
jarrodbell / gist:6b0078091eb398f081ab
Last active August 29, 2015 14:10
Fibaro device ID value processing
// Map a Fibaro device ID to a join number
// The join number should be prefixed by the join type (a = analog, d = digital, s = serial, etc)
var joinIDMap = {
"12": "a1002",
"1": "a1015",
"45": "a1043",
"23": "a1008"
};
// Eg. doCommand("callAction", 168, "turnOn");

Typography

Headings

Headings from h1 through h6 are constructed with a # for each level:

# h1 Heading
## h2 Heading
### h3 Heading
@jarrodbell
jarrodbell / main.js
Last active December 29, 2015 05:59
JavaScript example for using CommandFusion iViewer to process data returned from a HTTP Request to a Z-Wave MiCasaVerde Vera Lite system
var myJSON, baseURL = "http://192.168.1.90:3480/data_request?id=lu_status2&DataVersion=1&DeviceNum=";
function requestData(deviceNum) {
CF.request(baseURL + deviceNum, function(status, headers, body) {
if (status == 200) {
// OK response received, now grab the JSON string from body and turn it into an object
myJSON = JSON.parse(body);
// Now assign one of the known state variables to a serial join (if it will always be at a certain index in the state array)
@jarrodbell
jarrodbell / makeReadable.js
Last active December 25, 2015 18:19
Convert byte array (or string) to a readable "\xFF" formatted string for any bytes outside the printable ascii range (32-127 decimal)
function makeReadable(bytes) {
var readable = "", i;
for (i = 0; i < bytes.length; i++) {
var byteVal = bytes.charCodeAt(i);
if (byteVal < 32 || byteVal > 127) {
readable += "\\x" + ("0" + byteVal.toString(16).toUpperCase()).slice(-2);
} else {
readable += bytes[i];
}
}
@jarrodbell
jarrodbell / JSON_Parse
Last active December 23, 2015 07:59 — forked from ronnie72/JSON_Parse
var WTH={
weather: {},
setup: function (){
CF.log("Weather Module setup function has been called");
},
getData: function(url, dataReceivedCallback) {
// to be able to access our variable, we need to keep a reference to
@jarrodbell
jarrodbell / feedback-parsing-example.js
Last active December 21, 2015 03:59
How to parse data using JavaScript in iViewer, step by step guide.
// To listen to feedback in JS, you need to use CF.watch within the userMain function, like this:
// Note: "Incoming Alarm Data" is the name of the feedback item in guiDesigner, replace these with whatever name you are using in your GUI.
// The regex you use in your feedback item determines WHEN the FeedbackMatchedEvent is triggered, but has no affect on the data sent to JavaScript.
// Instead your script will be sent the full string of data that was received from your external system, so long as it matches the regex.
// So if you wanted ALL data to be processed in JavaScript, you could use a "catch all" RegEx as simple as: (.*)
CF.userMain = function() {
CF.watch(CF.FeedbackMatchedEvent, "System Name", "Incoming Alarm Data", function(feedbackName, matchedString) {
// Code for using the matched data goes here...
});