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 / 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

@TotallyInformation
TotallyInformation / README.md
Created September 3, 2016 17:15
Node-RED Process Details (Debugging, Linux)

This example flow will let you monitor the Operating System process details for your Node-RED instance.

To make this work, you need to know the PID (Process Identifier) of your Node-RED instance. The easiest way to do that is to grab it on startup and add it to the global variables from settings.js. Add the following to your settings.js file & restart NR:

...
functionGlobalContext: {
    'pid': process.pid
},
...
@TotallyInformation
TotallyInformation / README.md
Created December 21, 2016 23:38
Simple Windows Text to Speech

Windows from certainly at least version 7+ and the equivalent server versions have an excellent built-in Speech engine that does both text-to-speech and speech recognition.

The speech engine is written as a system library and so is easily called from PowerShell.

This flow makes use of that feature and uses the exec node to shell out to PowerShell, calling the speech engine using a one-line PowerShell script.

You send the text into the exec node and it passes it through.

See the comment node for some details. This is exactly the way that the popular say.js library works.