Skip to content

Instantly share code, notes, and snippets.

View jpwsutton's full-sized avatar

James Sutton jpwsutton

View GitHub Profile
@jpwsutton
jpwsutton / node_red_owntracks_database
Created March 18, 2014 18:05
Sanitised Owntracks packet for being stored in mongoDB
// The received message is stored in 'msg'
// It will have at least a 'payload' property:
// console.log(msg.payload);
// The 'context' object is available to store state
// between invocations of the function
// context = {};
var date = new Date().toISOString().slice(0, 19).replace('T', ' ');
var user = 'james';
@jpwsutton
jpwsutton / isNumber
Last active August 29, 2015 14:19
Javascript Is something a number?
function isNumber(object){
return ! isNaN (object-0) && object !== null && object !== "" && object !== false;
}
@jpwsutton
jpwsutton / propertyInObject
Created April 24, 2015 10:14
Does an Object contain a property
// There is probably a nicer way of doing this...
function propertyInObject(property, object){
try {
if(property in object){
return true;
}
} catch (e) {
return false;
}
}
@jpwsutton
jpwsutton / paho_march.md
Last active March 9, 2016 15:58
Eclipse Paho Plan for work in March

Planned work for Paho in March

#define WARN Serial.println
#define MQTTCLIENT_QOS2 1
#include <ESP8266WiFi.h>
#include <IPStack.h>
#include <Countdown.h>
#include <MQTTClient.h>
int arrivedcount = 0;
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
"City (en)";"City (de)";"Country (en)";"Country (de)";"Country code";"Population";"Latitude";"Longitude"
"Shanghai";"Shanghai";"China";"China";"CN";22315500;31.22222;121.45806
"Karachi";"Karachi";"Pakistan";"Pakistan";"PK";13052000;24.9056;67.0822
"Mumbai";"Mumbai";"India";"Indien";"IN";12691800;19.07283;72.88261
"Beijing";"Peking";"China";"China";"CN";11716600;39.9075;116.39723
"Istanbul";"Istanbul";"Turkey";"Türkei";"TR";11174300;41.01384;28.94966
"Guangzhou";"Guangzhou";"China";"China";"CN";11071400;23.11667;113.25
"Delhi";"Delhi";"India";"Indien";"IN";10928000;28.65195;77.23149
"Lagos";"Lagos";"Nigeria";"Nigeria";"NG";10404100;6.45407;3.39467
"Moscow";"Moskau";"Russia";"Russland";"RU";10381200;55.75222;37.61556
@jpwsutton
jpwsutton / glowOrb.ino
Created October 3, 2017 16:32
Glow Orb
/*
Rehau VOC Glow Orb
Gas visual alert using a Rehau VOC, WeMoS D1 ESP-8266 board and IBM Bluemix Quickstart.
Expects to receive a number, in ASCII, over MQTT, which it compares to a threshold to decide whether
to display red or green. e.g. "400"
by Andy Stanford-Clark - with embellishments by Lucy Rogers
@jpwsutton
jpwsutton / eventbutton.ino
Created October 3, 2017 16:34
Event button alternate using HTTP
/*
Debounce
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
a minimum delay between toggles to debounce the circuit (i.e. to ignore
noise).
The circuit:
* LED attached from pin 13 to ground
@jpwsutton
jpwsutton / nr-mqttsn-bridge.json
Created March 25, 2018 19:35
Node-red-at-mqttsn-udb-bridge
[{"id":"305d953b.4abf6a","type":"tab","label":"Robot","disabled":true,"info":""},{"id":"910d848f.a215b8","type":"tab","label":"AT Commands","disabled":false,"info":""},{"id":"8a4dab5a.1db6c8","type":"tab","label":"Network","disabled":false,"info":""},{"id":"2cd98bfb.5a9a54","type":"mqtt-broker","z":"","broker":"jit4q3.messaging.internetofthings.ibmcloud.com","port":"1883","clientid":"d:jit4q3:GlowOrbControl:bce8-ff91","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":""},{"id":"d4571afa.2a9fa8","type":"mqtt-broker","z":"","name":"Personal IoT","broker":"wdwf42.messaging.internetofthings.ibmcloud.com","port":"1883","clientid":"a:wdwf42:red","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"2f2480a5.7e57b","type":"ui_tab","z":"","name":
@jpwsutton
jpwsutton / instax-flow.js
Last active May 30, 2018 07:53
Node-Red flow for controlling and connecting to a Fujifilm INSTAX Printer
[
{
"id": "5e4a70ef.bac7a",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": ""
},
{
"id": "17f15d16.6e3143",