Skip to content

Instantly share code, notes, and snippets.

View TotallyInformation's full-sized avatar

Julian Knight TotallyInformation

View GitHub Profile
@TotallyInformation
TotallyInformation / README.md
Created December 2, 2017 22:17
Send APC UPS data to MQTT

Here is an example flow that reads data from an APC UPS (Uninterruptible Power Supply). These are commonly used to keep PC's and servers powered up during short power outages and to allow them to gracefully shut down.

In this case, I have a low-cost APC UPS connected via a USB cable to the Raspberry Pi that is running Node-RED and a Mosquitto MQTT broker.

To get the latest data from the UPS, we are using a command-line Linux tool called apcaccess. This is part of apcupsd which you should be able to install directly from your distribution's software library.

There are 2 function nodes included in the flow. One that isn't wired in, that converts the text output from the tool into an object on the payload containing properties for everything returned by the query. The second one, that is in use, is very similar but throws out a new message for each property using topics that correspond roughly to the homie MQTT topic structure. Homie is simi

@TotallyInformation
TotallyInformation / README.md
Last active January 5, 2024 21:17
uibuilder dynamic SVG example - no framework needed

UPDATE Jan 2024: Looks like there is a problem on the Node-RED Flows site that messes up some flows. This one being a case in point. So I've made the Gist public, you can access the correct code at: https://gist.github.com/TotallyInformation/89487d20c635d54d9b98d963656ce429

UPDATE May 2023: There was a slight bug in the index.js file. It was using an internal function that is no longer visible to end-user code. Sorry about that. I've fixed the code so it works again.

I thought it was high-time I produced a better and updated version of an old favourite - uibuilder, VueJS and SVG: Quick floorplan IoT example (flow) - Node-RED (nodered.org).

That example requires VueJS to work which seems overkill for a simple requirement. So this version does not use any frameworks, just plain old HTML, SVG, CSS and a bit of JavaScript thrown in.

The bulb images are cloned from a template and are clickable. Clicking them toggles them on and off as expected.

@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
<!doctype html>
<html lang="en"><head>
<meta charset="utf-8">
<title>Web Component Test: nav-bar</title>
<script type="module" async >
import './nav-bar.js'
</script>
</head><body>
@TotallyInformation
TotallyInformation / index.html
Created May 25, 2022 17:35
Test web component
/** Define a new zero dependency custom web component ECMA module that can be used as an HTML tag
*
* TO USE THIS TEMPLATE: CHANGE ALL INSTANCES OF 'NavBar' and 'nav-bar' & change version below
*
* @version 0.1 2022-05-25 Pre-release
*
* See: https://web.dev/custom-elements-v1/, https://web.dev/shadowdom-v1/
*
* See https://github.com/runem/web-component-analyzer#-how-to-document-your-components-using-jsdoc on how to document
* Use `npx web-component-analyzer ./components/button-send.js` to create/update the documentation
@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 September 29, 2017 22:22
UIbuilder with MoonJS - simple, responsive UI

Here is a quick example using UIbuilder which is an alternative UI for Node-RED.

It demonstrates the use of a lightweight front-end library, MoonJS, which can be a lot faster and easier to work with than Node-RED's built-in Dashboard UI once you reach the point of needing to customise the UI beyond the standard capabilities of Dashboard.

This is a really quick demo of what you can do with uibuilder. MoonJS is a lightweight alternative to the likes of Angular (used by Dashboard), REACT, VueJS, etc. It is fast and really easy to use.

Here are the steps to set up (details given below):

  1. Install MoonJS & uibuilder using npm
@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
Last active December 17, 2020 22:29
Simple uibuilder flow (Quote of the Day)

This simple flow will deliver a random quote of the day to a web URL using uibuilder.

All of the front-end html, javascript and css is included in the flow so simply add the flow and edit the front-end code using uibuilder's built-in editor.

See if you can work out how to use the control outputs (output port #2 on the uibuilder node) to trigger a new quote when you reload the page. (Hint: See the GitHub page for this example as it has another flow attached).

The real purpose of this flow is to help you learn a little bit about VueJS which is the default front-end framework provided with uibuilder v2 and v3.

The front-end code is extremely simple so do take a look and see how it works.

/** Standardised data schema's for IoT Home Automation
*/
const schemas = {
/** network table
* A table of network devices (logical and physical)
* This schema uses a structure suitable for use with VueJS/bootstrap-vue `b-table` options.
* The table is an object of objects with the ID as the primary key
* It is periodically updated by an NMAP scan.