importing data from mariadb into zway

Discussions about Z-Way software and Z-Wave technology in general
philippescholtes
Posts: 17
Joined: 01 Aug 2019 05:14

Re: importing data from mariadb into zway

Post by philippescholtes »

success! thank you very much seattleneil. you had it right: the correct syntax was ' + str(temperature) + '--I had been struggling for hours with all kinds of fancy symbols around the variable "temperature".
if anyone is interested, the entire python code is:
___________________________________
import Adafruit_DHT
import mariadb
import time
import requests

dht_sensor = Adafruit_DHT.DHT22
dht_pin = 4

humidity, temperature = Adafruit_DHT.read_retry(dht_sensor, dht_pin)

myurlt = 'http://192.168.0.70:8083/JS/Run/control ... _29\').set(\'metrics:level\','+str(temperature)+')'
myurlh = 'http://192.168.0.70:8083/JS/Run/control ... _30\').set(\'metrics:level\','+str(humidity)+')'

response = requests.get(myurlt, auth=('yyyyyyyy', 'xxxxxxxx'))
response = requests.get(myurlh, auth=('yyyyyyyy', 'xxxxxxxx'))

conn = mariadb.connect(
user='philippe',
password='xxxxxxxx',
host='localhost',
database='tempdb'
)
cur = conn.cursor()

datebuff = time.strftime('%Y-%m-%d %H:%M:%S')

cur.execute("INSERT INTO humidity (date, temperature, humidity) VALUES (?, ?, ?)", (datebuff, temperature, humidity))

conn.commit()
conn.close
___________________________________

To recap: I connected a Dallas DHT22 sensor to GPIO Pin 4 of a Raspberry Pi and downloaded the module Adafruit_DHT designed to read the DHT sensor. The above Python programme runs every x minutes as instructed by a crontab entry; it reads the values of temperature and humidity and appends them to a MariaDB table that I could read remotely in SQL. With today's significant improvement, the Python programme also pushes, with the frequency of the crontab instruction, the readings of temperature and humidity onto two virtual devices (Z-Way ID 29 and 30, respectively) on a Z-Way controller (a Razberry card) hosted on another Raspberry Pi (IP 192.168.0.70), and the values appear on my Z-Way dashboard.
Post Reply