Skip to content

Instantly share code, notes, and snippets.

@janeadams
Created December 29, 2021 03:09
Show Gist options
  • Save janeadams/5c8a6dad9fc3a724477d1e2d2bb12cd0 to your computer and use it in GitHub Desktop.
Save janeadams/5c8a6dad9fc3a724477d1e2d2bb12cd0 to your computer and use it in GitHub Desktop.
Gas tracker
import requests
import datetime as dt
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
from time import sleep # Import the sleep function from the time module
GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
pins = [23,21,19]
for pin in pins:
GPIO.setup(pin, GPIO.OUT, initial=GPIO.LOW)
while True:
for pin in pins:
GPIO.output(pin, GPIO.LOW)
resp = requests.get(url='http://ethgas.watch/api/gas')
data = resp.json()
last = data['lastUpdated']
updated = dt.datetime.utcfromtimestamp(last/1000).strftime('%Y-%m-%d %H:%M:%S')
gwei = data['normal']['gwei']
print(f'Gwei: {gwei} Updated {updated}')
if gwei < 100:
out = pins[0]
elif gwei < 150:
out = pins[1]
else:
out = pins[2]
GPIO.output(out, GPIO.HIGH)
sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment