Skip to content

Instantly share code, notes, and snippets.

@makvoid
makvoid / aht20-step-3.py
Created February 21, 2022 04:47
AHT20 collect method
@click.command()
@click.option('--location', required=True, help='Sensor location name')
def collect(location):
# Collect data and convert/round
temperature = round_num(c_to_f(sensor.temperature))
humidity = round_num(sensor.relative_humidity)
# Save entry
try:
save_entry(location, temperature, humidity)
@makvoid
makvoid / entries.json
Last active February 23, 2022 14:55
AHT20 entries.json
[
{
"location": "Garage",
"temperature": "73.67",
"humidity": "37.48",
"date": "2022-02-20T22:41:38.783012"
},
{
"location": "Garage",
"temperature": "73.32",
@makvoid
makvoid / climate-monitor.service
Created February 21, 2022 05:19
AHT20 Systemd files
[Unit]
Description=Climate Monitor using AHT20
After=network-online.target
[Service]
Type=oneshot
WorkingDirectory=/path/to/dir/containing/script
User=pi
ExecStart=python3 aht20.py --location some_location
@makvoid
makvoid / aht20.py
Created February 21, 2022 20:41
AHT20 initial script
import adafruit_ahtx0
import board
# Setup I2C Sensor
sensor = adafruit_ahtx0.AHTx0(board.I2C())
# Convert Celsius to Fahrenheit
def c_to_f(input):
return (input * 9 / 5) + 32
@makvoid
makvoid / aht20-step-5.py
Created February 27, 2022 02:16
AHT20 collect, export, cli methods
@click.group()
def cli():
pass
@cli.command()
@click.option('--chart-path', required=True, help='Path to store chart at')
@click.option('--location', required=True, help='Sensor location name')
def export(chart_path, location):
# Ensure the entries.json file is not missing
if not os.path.isfile('entries.json'):
@makvoid
makvoid / aht20-step-4.py
Last active March 10, 2022 04:42
AHT20 average_date, get_entries, plot_data methods
def average_date(date, entries):
# Get a list of all entries for this date
events = list(filter(lambda x: (x['date'][0:10] == date), entries))
return {
'date': pd.to_datetime(date),
'temperature': sum(float(e['temperature']) for e in events) / len(events),
'humidity': sum(float(e['humidity']) for e in events) / len(events)
}
# Returns entries as DataFrames
@makvoid
makvoid / aht20-step-2.py
Created February 27, 2022 02:18
AHT20 save_entry method
# Save climate information locally
def save_entry(location, temperature, humidity):
# Ensure the file exists before attempting to read
if not os.path.isfile('entries.json'):
pathlib.Path('entries.json').touch(exist_ok=False)
entries = []
else:
# Load any old entries
with open("entries.json", "r") as f:
try:
@makvoid
makvoid / sled-data-format.csv
Created March 6, 2022 00:29
Forza Telemetry V1 (Sled) format
position name python_type c_type
0 IsRaceOn int s32
4 TimestampMS int u32
8 EngineMaxRpm float f32
12 EngineIdleRpm float f32
16 CurrentEngineRpm float f32
20 AccelerationX float f32
24 AccelerationY float f32
28 AccelerationZ float f32
32 VelocityX float f32
@makvoid
makvoid / dash-data-format.csv
Created March 6, 2022 04:34
Forza Telemetry V2 (Dash) format
position name python_type c_type
232 PositionX float f32
236 PositionY float f32
240 PositionZ float f32
244 Speed float f32
248 Power float f32
252 Torque float f32
256 TireTempFrontLeft float f32
260 TireTempFrontRight float f32
264 TireTempRearLeft float f32
@makvoid
makvoid / fh4-data-format.csv
Last active March 7, 2022 15:01
Forza Telemetry V3 (FH4) format
position name python_type c_type notes
232 CarType int s32 Category of the car (ex. Hypercars)
236 ImpactX float f32 Changes when hitting objects in the environment
240 ImpactY float f32 Changes when hitting objects in the environment
323 Unknown ? ? Only 1 byte