Skip to content

Instantly share code, notes, and snippets.

@beikeland
beikeland / umqttscript.txt
Created December 30, 2019 23:22
OpenEVSE current sharing over MQTT
on init
do
setvar $leaf=1 %leaf state
setvar $tesla=1
setvar $pn=0 %pilot new
setvar $teslamp=""
subscribe local "ev/+/state"
subscribe local "ev/+"
on topic local "ev/+"
@beikeland
beikeland / tesla-token-from-bash.sh
Created December 25, 2019 00:19
Fetches Tesla OAUTH token to use with API from shell. Also spits out refresh token and expiry information.
#!/bin/bash
echo -n "USERNAME: "; read uname
echo -n "PASSWORD: "; stty -echo; read passwd; stty echo; echo
OAUTH=$(curl -s -i -X POST -H 'Content-Type: application/json' -d "{\"grant_type\": \"password\", \"client_id\": \"81527cff06843c8634fdc09e8ac0abefb46ac849f38fe1e431c2ef2106796384\", \"client_secret\": \"c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3\", \"email\": \"$uname\",\"password\": \"$passwd\"}" "https://owner-api.teslamotors.com/oauth/token")
if [[ "$OAUTH" =~ \"access_token\":\ ?\"([0-9a-f]+)\" ]]; then
access_token=${BASH_REMATCH[1]}
else
echo "Error, no access token received:"
echo $OAUTH
exit 1
#include <WiegandNG.h> //https://github.com/jpliew/Wiegand-NG-Multi-Bit-Wiegand-Library-for-Arduino
//needs https://github.com/jpliew/Wiegand-NG-Multi-Bit-Wiegand-Library-for-Arduino/pull/6
WiegandNG wg;
void PrintAR6182(WiegandNG &tempwg) {
volatile unsigned char *rawData=tempwg.getRawData();
uint8_t rawSize = tempwg.getBufferSize();
uint8_t countedBits = tempwg.getBitCounted();
uint8_t pinDigits = 0;
@beikeland
beikeland / door.php
Last active June 27, 2019 18:10
door token
<?php
require_once __DIR__.'/vendor/autoload.php';
use Hashids\Hashids;
$hashids = new Hashids('somerandomtext', 6, 'abcdefghijklmnopqrstuvwxyz');
$db = new SQLite3('door.db');
$db->busyTimeout(5000);
$db->exec('CREATE TABLE IF NOT EXISTS tokens (id INTEGER PRIMARY KEY AUTOINCREMENT, refrence TEXT(64), count INTEGER, valid_from DATETIME, valid_to DATETIME)');