Skip to content

Instantly share code, notes, and snippets.

View TotallyInformation's full-sized avatar

Julian Knight TotallyInformation

View GitHub Profile
@TotallyInformation
TotallyInformation / app.coffee
Created April 25, 2012 08:49
Failing to find asset with Connect-assets, Express, CoffeScript
# app.coffee
# We will call this automatically via `node server.js`
# this instanstiates the CoffeeScript compiler and automatically runs app.coffee through it & runs the resulting app.js
# Using `forever server.js` will reload server.js whenever there is a change to a file in the applications folders so we don't have to stop and restart the server when something changes.
# @see http://blogs.planetsoftware.com.au/felix/archive/2012/03/08/coffeeeeeeee.aspx
# -- Require our libaries --
express = require 'express'
@TotallyInformation
TotallyInformation / index.html
Created October 23, 2013 09:19
Example of using Node.js to monitor serial output from an Arduino
<!doctype html>
<html lang="en"><head>
<meta charset="utf-8">
<title>Node/Ardiuno Listener</title>
<meta name="description" content="Node/Ardiuno Listener">
<meta name="author" content="Julian Knight">
<link rel="stylesheet" href="css/styles.css?v=1.0">
<style type="text/css">
@TotallyInformation
TotallyInformation / readVcc.c
Created October 23, 2013 11:14
Read the battery status of an Arduino
long readVcc() {
// Read 1.1V reference against AVcc
// set the reference to Vcc and the measurement to the internal 1.1V reference
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX = _BV(MUX5) | _BV(MUX0);
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX = _BV(MUX3) | _BV(MUX2);
#else
@TotallyInformation
TotallyInformation / CouchDb
Last active July 26, 2017 07:19
Example code illustrating the use of Tim Hall's Excel JSON classes in Microsoft Outlook
' Functions to read/write CouchDB on localhost
' @dependencies: Reference to 'Microsoft Scripting Runtime', RestHelpers (https://github.com/timhall/Excel-REST)
' VBA Ref: http://msdn.microsoft.com/en-us/library/gg251755%28v=office.15%29.aspx
' Outlook VBA Ref: http://msdn.microsoft.com/en-US/library/ee861520%28v=office.15%29.aspx
Option Explicit
' Replace back-ticks with double quotes for producing valid JSON
@TotallyInformation
TotallyInformation / README.md
Last active August 23, 2026 15:06
Templated Web Page with live updates

This example can be used to output a standardised web page template. I've used Zurb Foundation to provide the structure.

It also shows how to use both raw websockets and MQTT over websockets (via the Paho library) to send/receive live data between the web page and Node-Red.

There are a number of dependencies, flows, subflows and files so I've put all the code on Github rather than here.

https://github.com/TotallyInformation/node-red-example-liveupdates

Output Subflow

@TotallyInformation
TotallyInformation / README.md
Last active August 23, 2026 15:05
Better debugging

The current debugging capability of Node-Red leaves a lot to be desired. While there are plans to improve it, these will take some time to complete.

In the meantime, I've created an alternative that is fairly easy for anyone to implement and seems to work well. I'm now using it in my projects.

The approach is to create a subflow that outputs a msg to MQTT instead of debug. Then to create a flow that creates a debug web page that receives the MQTT debug messages. The page creates a section for each message TOPIC so it is important to set that correctly before sending the msg to the subflow. Then each topic shows a formatted display of the full msg object. The topic display is updated each time a message with the same topic is sent out. A timestamp is included to show when each topic was last updated.

As there is both a flow and a subflow & some example images, I've put the example on github.

https://github.com/TotallyInformation/node-red-example-debug

@TotallyInformation
TotallyInformation / Capture.PNG
Last active February 29, 2016 08:45
Post data to InfluxDB
Capture.PNG
@TotallyInformation
TotallyInformation / 02-hw-listen.PNG
Last active February 1, 2022 22:50
Failing test for flows.nodered.com
02-hw-listen.PNG
@TotallyInformation
TotallyInformation / README.md
Created June 12, 2016 20:05
Example reading file paths using native node.js modules

This example flow uses the native Node.JS fs and path modules to read a list of file names having a specified file extension from a given folder.

You can pass the folder and extension strings in via the msg.payload. Output is a single message for each file found. The payload will be the full file path. Everything other than the payload will be passed through to each output msg.

You would actually probably be better off using a 3rd party module as indicated in the main code but this may be a useful example of using modules in a Node-Red function node.

Note that function nodes run in a "sandbox" and have restricted syntax. As such, you cannot do:

var fs = require('fs');
@TotallyInformation
TotallyInformation / README.md
Created August 20, 2016 12:34
Node Dashboard: How to access the msg object in a Template script

Introduction

node-red-dashboard provides an easy to access web UI for Node-Red. It uses Angular, Angular Material and JQuery all of which are available to work with. Most of the available nodes are fairly simple to use but the Template node is available to use for those times when the simple nodes are not enough. Using the Template node can be easy, see the documentation. However, it can get difficult very quickly.

I put this flow together to illustrate how to access the msg object that is passed to the Template node from a JavaScript block within the template. This gives you access to the msg object in the browser.

How things work

Node that interactions with the Dashboards you create happen in two parts. The first is when you initially load the Dashboard UI. This is a single page app (SPA) so all of the Dashboard nodes you've used will all contribute to the UI. You will