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;
}
}

Keybase proof

I hereby claim:

  • I am jpwsutton on github.
  • I am jsutton (https://keybase.io/jsutton) on keybase.
  • I have a public key ASDkSwirSkrdxpkIDRbs7euFgnNf0q96P6m-aACVdUilBgo

To claim this, I am signing this object:

#define WARN Serial.println
#define MQTTCLIENT_QOS2 1
#include <ESP8266WiFi.h>
#include <IPStack.h>
#include <Countdown.h>
#include <MQTTClient.h>
int arrivedcount = 0;
@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

@jpwsutton
jpwsutton / printByteArray.java
Created November 17, 2016 11:15
Prints a byte array in binary, hex and dec.
private void printByteArray(byte[] bytes){
for (byte b1 : bytes){
String s1 = String.format("%8s", Integer.toBinaryString(b1 & 0xFF)).replace(' ', '0');
s1 += " " + Integer.toHexString(b1);
s1 += " " + b1;
System.out.println(s1);
}
}
@jpwsutton
jpwsutton / example.html
Created November 30, 2016 11:45
Paho Javascript new Publish Example
<html>
<head>
<title>Eclipse Paho MQTT JavaScript Client Example</title>
<!-- Source Paho MQTT Client-->
<script src="../src/paho-mqtt.js"></script>
<!--<script src="../src/paho-mqtt.js"></script>-->
<!-- Utility Javascript -->
<script src="example.js"></script>
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 / MQTTWemosButton.ino
Created June 4, 2017 13:44
MQTT Wemos Button
/***************************************************
MQTT Button on Wemos
James Sutton 2017 - jsutton.co.uk
****************************************************/
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
/************************* WiFi Access Point *********************************/