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
@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) |
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
[ | |
{ | |
"location": "Garage", | |
"temperature": "73.67", | |
"humidity": "37.48", | |
"date": "2022-02-20T22:41:38.783012" | |
}, | |
{ | |
"location": "Garage", | |
"temperature": "73.32", |
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
[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 |
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
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 |
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
@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'): |
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
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 |
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
# 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: |
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
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 |
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
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 |
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
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 |
OlderNewer