-
-
Save cfree/f307e13637b17acf689427fadf0a6048 to your computer and use it in GitHub Desktop.
Cold Snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dtoverlay=w1-gpio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh user@ngrokAddress.com -p12345 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
authtoken: <add_your_token_here> | |
tunnels: | |
ssh: | |
proto: tcp | |
addr: 22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To start | |
screen node . 50 1000 5000 | |
# To detach | |
# cmd+a, cmd+d | |
# To reattach | |
screen -r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shortcut for ssh'ing into the Pi
alias cs="ssh pi@x.x.x.x -p"
Use:
cs {port}
Ex:
cs 1234