So, would it be possible to add a basic realtime chart? There are many nice chart libraries for example Dislin is one I like:
https://www.mps.mpg.de/dislin or Gnuplot
Currently I am trying to use Python to graph the output in real time but the charts are blocking, in other words after ploting a set of points, it won't return.
My current goal is to save data and into a MySQL database and plot it live on a chart. I would like to chart the barometric pressure in particular to get a basic barograph indicating weather trends.
Example code writing to MySQL database is the rtl_433_wrapper.py posted in this forum.
Here are some Python codes I stiched togheter from examples:
This script is passed to rtl_433 command line and transmits data over tcp to another client:
*****************************************************************************************************************
# import the socket library
import socket
# next create a socket object
s = socket.socket()
print "Socket successfully created"
# reserve a port on your computer in our
# case it is 12345 but it can be anything
port = 43261
# Next bind to the port
# we have not typed any ip in the ip field
# instead we have inputted an empty string
# this makes the server listen to requests
# coming from other computers on the network
s.bind(('', port))
print "socket binded to %s" %(port)
# put the socket into listening mode
s.listen(5)
print "socket is listening"
# a forever loop until we interrupt it or
# an error occurs
while True:
# Establish connection with client.
c, addr = s.accept()
print 'Got connection from', addr
# send a thank you message to the client.
c.send('Thank you for connecting')
# Close the connection with the client
c.close()
#loads a line from rtl_433 console
tjson = json.loads(line)
dt = datetime.datetime.strptime(tjson['time'], '%Y-%m-%d %H:%M:%S')
print (dt)
if 'id' in tjson:
sensorID = int(tjson['id'])
print(sensorID)
if sensorID == 231: #my sensors I want to process
print('Found sensor 231')
temp = float(tjson['temperature_F'])
pressure = float(tjson['pressure_inHg'])
x1 = [dt]
y1 = [temp]
x2 = [dt]
y2 = [pressure]
if sensorID == 243:#my sensors I want to process
print('Found sensor 243')
temp = float(tjson['temperature_F'])
pressure = float(tjson['pressure_inHg'])
x3 = [dt]
y3 = [temp]
x4 = [dt]
y4 = [pressure]
if sensorID == 15454:#my sensors I want to process
print('Found sensor 15454')
temp = float(tjson['temperature_F'])
humid = float(tjson['humidity'])
x5 = [dt]
y5 = [temp]
x6 = [dt]
y6 = [humid]
if 'temperature_F' in tjson:
temp = "%.3f" % tjson['temperature_F']
print('temp %s' % temp)
#to do chart data
else:
print("no temp data")
if 'humidity' in tjson:
humidity = "%.3f" % tjson['humidity']
print('humidity %s' % humidity)
#to do chart data
else:
print("no humidity data")
*****************************************************************************************************************
This is the listening client script:
*****************************************************************************************************************
import socket # for socket
import sys
import sqlite3
import json
# Create a TCP/IP socket
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print ("Socket successfully created")
except socket.error as err:
print ("socket creation failed with error %s" %(err))
sys.exit()
# Bind the socket to the port
server_address = ('127.0.0.1', 43261)
try:
sock.bind(server_address)
print ('starting up on %s port %s' % server_address)
except:
print ('Cant bind to %s port %s' % server_address)
sys.exit()
# Listen for incoming connections
sock.listen(10)
FullMsg = ''
# Wait for a connection
Processing = True
while Processing:
print ('waiting for a connection')
(connection, client_address) = sock.accept()
print ('connection from', client_address)
Processing = True
while True:
data = connection.recv(4096).decode()
print (data)
if data == 'Exit':
Processing = False
break
if data:
print ('sending data back to the client')
#FullMsg = FullMsg % data #cocantenate
print (FullMsg)
else:
print(FullMsg, client_address)
print ('no more data from', client_address)
break
Processing = False
print ("Exitin the listening thread")
# Clean up the connection
connection.close()
*****************************************************************************************************************