Good afternoon, I can’t figure out how to write the code. We read the value from the database, if it exceeds, say, 2000, then we turn on the relay via GPIO.
How to read - I understood.
How to turn on the relay - too.
But I can’t figure out how to connect this together. :-(
How to read - I understood.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import struct import sys import time import datetime import pymysql.cursors import wiringpi from wiringpi import GPIO connection = pymysql.connect(host = '127.0.0.1' , user = 'root' , password = '2548695542' , db = 'sd' , charset = 'utf8mb4' , cursorclass = pymysql.cursors.DictCursor) with connection: cur = connection.cursor() cur.execute( "SELECT * FROM ddd1 ORDER BY id DESC LIMIT 1" ) rows = cur.fetchall() for row in rows: print (row[ "weight" ]) |
1 2 3 4 5 6 7 |
NUM2 = 2 # (wPi-2) orange pi zero 2 wiringpi.wiringPiSetup() wiringpi.pinMode(NUM2, wiringpi.GPIO.OUTPUT); wiringpi.digitalWrite(NUM2, GPIO.HIGH); |