Hello together,
my name is Michael and I´m just getting stated with blynk on my raspi zero.
Please excuse my english- I´m not an native speaking.
Despite spending hours on the internet I just can´t find a solution for controlling an output on my PI using a python script, like turning an LED on and of by Button. So i either got much less understanding of the topic then i thought or it is just some case of misunderstanding.
So as mentioned i use a raspberry pi zero. I set it up as mentioned here: first installed it globally and later tried to create a new Node.js module with local Blynk library dependency.
Unfortunatly the example is written in java, which i don´t want to use.
So after all I got a script working for an DHT11 sensor fine (I know there might be a lot in it which is not necessary):
import Adafruit_DHT
class Counter:
cycle = 0
BLYNK_AUTH = 'XXXX'
blynk = blynklib.Blynk(BLYNK_AUTH)
T_CRI_VALUE = 20.0 # 20.0°C
T_CRI_MSG = 'Low TEMP!!!'
T_CRI_COLOR = '#c0392b'
T_COLOR = '#f5b041'
H_COLOR = '#85c1e9'
P_COLOR = '#a2d9ce'
A_COLOR = '#58d68d'
ERR_COLOR = '#444444'
T_VPIN = 7
H_VPIN = 8
P_VPIN = 9
A_VPIN = 10
GPIO_DHT11_PIN = 17
@blynk.handle_event('read V{}'.format(T_VPIN))
def read_handler(vpin):
# DHT22
dht11_sensor = Adafruit_DHT.DHT11 # possible sensor modifications .DHT11 .DHT22 .AM2302. Also DHT21 === DHT22
humidity, temperature = Adafruit_DHT.read_retry(dht11_sensor, GPIO_DHT11_PIN, retries=5, delay_seconds=1)
Counter.cycle += 1
# check that values are not False (mean not None)
if all([humidity, temperature]):
print('temperature={} humidity={}'.format(temperature, humidity))
if temperature <= T_CRI_VALUE:
blynk.set_property(T_VPIN, 'color', T_CRI_COLOR)
# send notifications not each time but once a minute (6*10 sec)
if Counter.cycle % 6 == 0:
blynk.notify(T_CRI_MSG)
Counter.cycle = 0
else:
blynk.set_property(T_VPIN, 'color', T_COLOR)
blynk.set_property(H_VPIN, 'color', H_COLOR)
blynk.virtual_write(T_VPIN, temperature)
blynk.virtual_write(H_VPIN, humidity)
else:
print('[ERROR] reading DHT22 sensor data')
blynk.set_property(T_VPIN, 'color', ERR_COLOR) # show aka 'disabled' that mean we errors on data read
blynk.set_property(H_VPIN, 'color', ERR_COLOR)
############################################################
infinite loop that waits for event
###########################################################
while True:
blynk.run()
So can you please advise me how to get an LED working which i can turn on and off?
Also tried to connect the output pin on raspi directly using digital pin gp18 in the app but despite the script (and in my understading also blynk) running on raspi it is not working.
Thanks for your help!