Skip to content

Instantly share code, notes, and snippets.

@sammachin
sammachin / README.md
Last active April 22, 2024 14:45
Raspberry Pi PicoW MQTT-GPIO With Node-RED

This will require the umqtt.simple library on the PicoW,

You can install this with upip by running:

import upip
upip.install('umqtt.simple')

If you use a public MQTT broker such as test.mosquitto.org you should change the prefix value in line 8 of the micropython from MYNAME to something unique or you may recieve other peoples commands

# Launches a Node-RED Instance using the current path as users and nodes dir but using the global settings.js in ~/.node-red
location=$PWD
echo $location
openBrowser() {
sleep 2
open http://127.0.0.1:1880$1
}
@sammachin
sammachin / message.json
Created November 17, 2020 10:38
Glow Stick MQTT
{
"0702": {
"03": {
"01": "000001",
"05": "43",
"04": "9B",
"02": "0003E8",
"07": "22000134454XX", // MPAN
"08": "19P69009XX", // Meter Serial Number
"03": "43",
@sammachin
sammachin / main.py
Created July 27, 2020 10:01
Octopus Rating
import pickle
import requests
from datetime import datetime, timedelta, time
import csv
# Octopus Fixed Tarrif Rates (check for your region)
go_day = 14.5
go_night = 5
e7_day = 18.04
e7_night = 9.38
@sammachin
sammachin / slack-move.py
Last active January 29, 2019 12:20
some functions for getting slack users in a channel and adding them to a new channel
from slackclient import SlackClient
TOKEN = "xoxp-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
sc = SlackClient(TOKEN)
#get a dict of channel names to channel IDs
def get_channels():
channels = {}
data = sc.api_call("conversations.list", types='public_channel', exclude_archived=True, limit=1000)
@sammachin
sammachin / setup.sh
Last active December 21, 2018 12:06
PI Starter
#! /bin/bash
CARDPATH=$1
#Enable SSH
touch $CARDPATH/ssh
#Configure WiFi
cp wpa_supplicant.conf $CARDPATH/wpa_supplicant.conf
@sammachin
sammachin / howto.md
Last active November 2, 2018 11:51
Making API Requets using JWT and HTTPie

HTTPie is AWESOME! if you're still using cURL do yourself a favor and get this https://httpie.org/

Here's a quick guide to make requests to the nexmo API that need to be authenticated with JWT and have a JSON request body.

You will need:

  • The Nexmo CLI installed
  • The private key for your application stored in a local file named private.key
  • The applicaiton ID of your applicaiton
  • The payload of the request in a file called request.json (see example)
[
{
"endpoint": [
{
"uri": "wss://<your-server-address>/socket",
"type": "websocket",
"headers": {
"app": "demo"
},
"content-type": "audio/L16;rate=16000"
@sammachin
sammachin / playlist_titles.py
Last active September 14, 2018 11:11
Short script to print all the titles in a YouTube Playlist
import requests
playlist = "XXXXXXX" #Playlist ID from URL eg https://www.youtube.com/playlist?list=PL1Hr6VkuONaE4XM52ThiV-s3vXAUT0JCR
key = "XXXXXXXX" # Your YouTube API Key from https://console.developers.google.com/apis/credentials
params = {"part" : "snippet", "maxResults" : 50, "playlistId": playlist, "key" : key}
url = "https://www.googleapis.com/youtube/v3/playlistItems"
items = []
r = requests.get(url, params=params)
rdata=r.json()
@sammachin
sammachin / install.sh
Created April 30, 2018 13:25
Node building blocks webhook prereqs
npm install express
npm install body-parser