Skip to content

Instantly share code, notes, and snippets.

@cfree

cfree/config.txt Secret

Last active November 2, 2019 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfree/f307e13637b17acf689427fadf0a6048 to your computer and use it in GitHub Desktop.
Save cfree/f307e13637b17acf689427fadf0a6048 to your computer and use it in GitHub Desktop.
Cold Snap
dtoverlay=w1-gpio
ssh user@ngrokAddress.com -p12345
const { join } = require('path');
const { readFileSync, readdirSync, statSync } = require('fs');
const pathPrefix = '/sys/bus/w1/devices';
function getSensors() {
try {
const results = readdirSync(pathPrefix)
.filter(file => statSync(join(pathPrefix, file)).isDirectory())
.filter(directory => directory !== 'w1_bus_master');
return results;
} catch (e) {
console.error(`Cannot Get Sensor: ${e}`);
return [];
}
}
function readData(sensor) {
try {
const results = readFileSync(`${pathPrefix}/${sensor}/w1_slave`, 'utf-8');
return results;
} catch (e) {
console.error(`Cannot Read Sensor: ${e}`);
return null;
}
}
function parseData(data) {
if (data) {
const [, secondLine] = data.split('\n');
const values = secondLine.split(' ');
const celsiusTemp = values[9].slice(2) / 1000;
return {
celsius: celsiusTemp || null,
fahrenheit: celsiusTemp ? parseInt((celsiusTemp * 1.8) + 32, 10) : null,
};
}
return null;
}
function getTemperature(sensor) {
const data = readData(sensor);
return parseData(data);
}
authtoken: <add_your_token_here>
tunnels:
ssh:
proto: tcp
addr: 22
# To start
screen node . 50 1000 5000
# To detach
# cmd+a, cmd+d
# To reattach
screen -r
exports.handler = function(context, event, callback) {
context.getTwilioClient().messages.create({
to: process.env.RECIPIENT_PHONE_NUMBER,
from: process.env.SENDER_PHONE_NUMBER, // Twilio phone number
body: `Cold snap! The current temperature is ${event.temp || ''}deg F, which is at or below your threshold of ${event.threshold || ''}deg F`
}).then(msg => {
callback(null, msg.sid);
}).catch(err => callback(err));
};
@cfree
Copy link
Author

cfree commented Nov 2, 2019

Shortcut for ssh'ing into the Pi
alias cs="ssh pi@x.x.x.x -p"

Use: cs {port}
Ex: cs 1234

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment