Skip to content

Instantly share code, notes, and snippets.

@dk2ro
Created January 23, 2019 17:03
Show Gist options
  • Save dk2ro/6e116072e056e0d324b96cebe7723731 to your computer and use it in GitHub Desktop.
Save dk2ro/6e116072e056e0d324b96cebe7723731 to your computer and use it in GitHub Desktop.
Quick and dirty script for plotting the JSON output of rtl_433
from pylab import *
from drawnow import drawnow, figure
import random
import time
import fileinput
import json
import datetime
sensors = []
values = {}
def draw_fig():
for s in sensors:
vals = values[s]
plot_date(vals["time"],vals["val"],".-")
legend(sensors)
for line in fileinput.input():
vals = json.loads(line)
if "temperature_C" not in vals:
continue
t = datetime.datetime.fromisoformat(vals["time"])
mid = vals["model"]+" "+str(vals["id"])
if "channel" in vals:
mid += "_"+str(vals["channel"])
if "rid" in vals:
mid += "_"+str(vals["rid"])
if mid not in sensors:
sensors.append(mid)
values[mid]={"time":[],"val":[]}
values[mid]["time"].append(t)
values[mid]["val"].append(vals["temperature_C"])
#print(values)
drawnow(draw_fig)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment