Blynk não conecta

Eu achei um arquivo para alterar a versao, versao 1.0.0.
Agora esta aparecendo erro no @blynk.virtual_write.


Consegui fazer conectar uma vez, depois disso ele só apresenta erro no código e não se conecta mais. Quando se conecta, só apareceu que estava se conectando ao blynk e a porta, porém não mostrava mais nada. Como pode que não é mais fácil de fazer, que dificuldade.

Post your whole script so we can take a look at it.

@ronigass when you post your script, please do not post a screenshot.
Copy the text and paste it as text, and put triple backticks at the beginning and end so that it displays correctly.
Triple backticks look like this:
```

Pete.

import BlynkLib
import RPi.GPIO as GPIO
import Adafruit_DHT

# define o tipo de sensor
sensor = Adafruit_DHT.DHT11

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

#definição:
bomba = 4
entradacaixa = 17
saida1 = 27
saida2 = 22
linha1 = 16
linha2 = 18
linha3 = 25
linha4 = 5
linha5 = 6
linha6 = 12
pino_sensor = 13

# define as  gpio como saida
GPIO.setup(bomba, GPIO.OUT) # Bomba da Agua
GPIO.setup(linha4, GPIO.OUT) # linha 4
GPIO.setup(linha5, GPIO.OUT) # Linha 5
GPIO.setup(linha6, GPIO.OUT) #linha 6
GPIO.setup(linha1, GPIO.OUT) # linha 1
GPIO.setup(entradacaixa, GPIO.OUT) # entrada caixa da agua
GPIO.setup(linha2, GPIO.OUT) # linha 2
GPIO.setup(saida2, GPIO.OUT) # caixa 2
GPIO.setup(linha3, GPIO.OUT) # linha 3
GPIO.setup(saida1, GPIO.OUT) # caixa 1
 pino_sensor = 13 #Sensor DHT11 


# Inicializa Blynk

blynk = BlynkLib.Blynk('PS5k4e7DtZgKuzvwQPmwmpTdGDZvajQW')


# Registra os pinos virtuais
# Bomba da Agua
@blynk.VIRTUAL_WRITE(0)
def my_write_handler(value):
 print('Valor de V0: {}'.format(value[0]))
  if value[0] >= "1":
  GPIO.output(bomba, 1)
 else:
  GPIO.output(bomba, 0)


# entrada caixa da agua
@blynk.VIRTUAL_WRITE(1)
def my_write_handler(value):
 print('Valor de V1: {}'.format(value[0]))
 if value[0] >= "1":
  GPIO.output(entradacaixa, 1)
 else:
  GPIO.output(entradacaixa, 0)

# caixa 1
@blynk.VIRTUAL_WRITE(2)
def my_write_handler(value):
 print('Valor de V2: {}'.format(value[0]))
 if value[0] >= "1":
  GPIO.output(saida1, 1)
 else:
  GPIO.output(saida1, 0)

# caixa 2
@blynk.VIRTUAL_WRITE(3)
def my_write_handler(value):
 print('Valor de V3: {}'.format(value[0]))
 if value[0] >= "1":
  GPIO.output(saida2, 1)
 else:
  GPIO.output(saida2, 0)

# linha 1
@blynk.VIRTUAL_WRITE(4)
def my_write_handler(value):
 print('Valor de V4: {}'.format(value[0]))
 if value[0] >= "1":
  GPIO.output(linha1, 1)
 else:
  GPIO.output(linha1, 0)

# linha 2
@blynk.VIRTUAL_WRITE(5)
def my_write_handler(value):
 print('Valor de V5: {}'.format(value[0]))
 if value[0] >= "1":
  GPIO.output(linha2, 1)
 else:
  GPIO.output(linha2, 0)

# linha 3
@blynk.VIRTUAL_WRITE(6)
def my_write_handler(value):
 print('Valor de V6: {}'.format(value[0]))
 if value[0] >= "1":
  GPIO.output(linha3, 1)
 else:
  GPIO.output(linha3, 0)

# linha 4
@blynk.VIRTUAL_WRITE(7)
def my_write_handler(value):
 print('Valor de V7: {}'.format(value[0]))
 if value[0] >= "1":
  GPIO.output(linha4, 1)
 else:
  GPIO.output(linha4, 0)

# Linha 5
@blynk.VIRTUAL_WRITE(8)
def my_write_handler(value):
 print('Valor de V8: {}'.format(value[0]))
 if value[0] >= "1":
  GPIO.output(linha5, 1)
 else:
  GPIO.output(linha5, 0)

#linha 6
@blynk.VIRTUAL_WRITE(9)
def my_write_handler(value):
 print('Valor de V9: {}'.format(value[0]))
 if value[0] >= "1":
  GPIO.output(linha6, 1)
 else:
  GPIO.output(linha6, 0)


while True:
    blynk.run()

Eu não estou encontrando a pasta na qual fica as bibliotecas do python, não sei mais oque fazer. Proprio portal do Blynk nao tem nada sobre o Raspberry pi.
Meu dispositivo:
Raspberry py 3b+
Bliblioteca: blynklib = v0.2.6
Bliblioteca: BlynkLib = v0.2.0
fiz de tudo e nao conecta.

According to your picture in post number 21, you are using the right version of the library (1.0.0), so it should connect, but you should fix your script first. You should replace

@blynk.VIRTUAL_WRITE(0)
def my_write_handler(value):

With

@blynk.on("V0")
def v0_write_handler(value):

I’d suggest starting with a basic script to ensure everything is working properly.

Try this one for example

Consegui fazer funcionar. Obrigado a todos.
Como eu posso fazer para fazer a leitura de um dht11?

Estava testando, quando aciono no app o pino virtual, aparece isso.

>>> %Run catia101022.py

    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ for Python v1.0.0 (linux)

Connecting to blynk.cloud:443...
Valor de V0: 1
Traceback (most recent call last):
  File "/home/catia/Desktop/catia101022.py", line 134, in <module>
    blynk.run()
  File "/home/catia/lib-python/blynklib.py", line 264, in run
    self.process(data)
  File "/home/catia/lib-python/blynklib.py", line 197, in process
    self.emit("V"+args[1], args[2:])
  File "/home/catia/lib-python/blynklib.py", line 68, in emit
    self._cbks[evt](*a, **kv)
  File "/home/catia/Desktop/catia101022.py", line 48, in v0_write_handler
    if int(value) >= "1":
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

Ai eu estava tentando ler um sensor.

import blynklib
#from gpiozero import 
import RPi.GPIO as GPIO
import Adafruit_DHT as dht



GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

#definição:
bomba = 4
entradacaixa = 17
saida1 = 27
saida2 = 22
linha1 = 16
linha2 = 18
linha3 = 25
linha4 = 5
linha5 = 6
linha6 = 12
dht_pin = 13

# define as  gpio como saida
GPIO.setup(bomba, GPIO.OUT) # Bomba da Agua
GPIO.setup(linha4, GPIO.OUT) # linha 4
GPIO.setup(linha5, GPIO.OUT) # Linha 5
GPIO.setup(linha6, GPIO.OUT) #linha 6
GPIO.setup(linha1, GPIO.OUT) # linha 1
GPIO.setup(entradacaixa, GPIO.OUT) # entrada caixa da agua
GPIO.setup(linha2, GPIO.OUT) # linha 2
GPIO.setup(saida2, GPIO.OUT) # caixa 2
GPIO.setup(linha3, GPIO.OUT) # linha 3
GPIO.setup(saida1, GPIO.OUT) # caixa 1
GPIO.setup(dht_pin, GPIO.IN)


# Inicializa Blynk

blynk = blynklib.Blynk('PS5k4e7DtZgKuzvwQPmwmpTdGDZvajQW')


# Registra os pinos virtuais
# Bomba da Agua
@blynk.on("V0") 
def v0_write_handler(value):
 print('Valor de V0: {}'.format(value[0]))
 if int(value) >= "1":
   GPIO.output(bomba, 1)
 else:
   GPIO.output(bomba, 0)


# entrada caixa da agua
@blynk.on("V1") 
def v1_write_handler(value):
 if int(value) == 1:
   GPIO.output(entradacaixa, 1)
 else:
   GPIO.output(entradacaixa, 0)

# caixa 1
@blynk.on("V2") 
def v2_write_handler(value):
 if int(value) == 1:
   GPIO.output(saida1, 1)
 else:
   GPIO.output(saida1, 0)

# caixa 2
@blynk.on("V3") 
def v3_write_handler(value):
 if int(value) == 1:
   GPIO.output(saida2, 1)
 else:
   GPIO.output(saida2, 0)

# linha 1
@blynk.on("V4") 
def v4_write_handler(value):
 if int(value) == 1:
   GPIO.output(linha1, 1)
 else:
     GPIO.output(linha1, 0)

# linha 2
@blynk.on("V5") 
def v5_write_handler(value):
 if int(value) == 1:
   GPIO.output(linha2, 1)
 else:
   GPIO.output(linha2, 0)

# linha 3
@blynk.on("V6") 
def v6_write_handler(value):
 if int(value) == 1:
   GPIO.output(linha3, 1)
 else:
   GPIO.output(linha3, 0)

# linha 4
@blynk.on("V7") 
def v7_write_handler(value):
 if int(value) == 1:
   GPIO.output(linha4, 1)
 else:
   GPIO.output(linha4, 0)

# Linha 5
@blynk.on("V8") 
def v8_write_handler(value):
 if int(value) == 1:
   GPIO.output(linha5, 1)
 else:
   GPIO.output(linha5, 0)

#linha 6
@blynk.on("V9") 
def v9_write_handler(value):
 if int(value) == 1:
   GPIO.output(linha6, 1)
 else:
   GPIO.output(linha6, 0)


@blynk.on('read V10')
def v10_read_handler(value):
 
    humidity = Adafruit_DHT.read_retry(dht.DHT11, dht_pin, retries=5, delay_seconds=1)
    Counter.cycle += 1

while True:
    blynk.run()

desde ja agradeco quem for me ajudar.

you can’t convert an entire list into an integer. You should get an index from the list and convert that into an integer.

should be

if int(value[0]) == 1:

You can try the adafruit example

Consegui fazer funcionar, mas agora não consigo ler as informações do dht11 no blynk pelo raspberry, até o momento os exemplos que eu achei na internet não ajudaram

Check that the wiring is correct (Are ground and power connected? is the correct DHT pin pulled up to 3.3v?). Then, make sure you provided the dhtDevice with the correct physical pin number your board is connected to.

Ja fiz isso, porém não consigo fazer para ele mandar pro app.

So, everything is working properly, but you can’t send the data to the server, am I right ?
If so, post your full script.

Isso. não esta enviando os dados do sensor dht11. Os pinos virtuais funcionou. Tentei usar uns codigos mas nao deu certo.

import blynklib
#from gpiozero import 
import RPi.GPIO as GPIO
import Adafruit_DHT
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

#definição:
bomba = 7 #4
entradacaixa =  11 #17
saida1 = 13 #27
saida2 = 15 #22
linha1 = 36 #16
linha2 = 12 #18
linha3 = 22 #25
linha4 = 29 #5
linha5 = 31 #6
linha6 = 32 #12

pin= 3 #13
sensor = Adafruit_DHT.DHT11

# define as  gpio como saida
GPIO.setup(bomba, GPIO.OUT) # Bomba da Agua
GPIO.setup(linha4, GPIO.OUT) # linha 4
GPIO.setup(linha5, GPIO.OUT) # Linha 5
GPIO.setup(linha6, GPIO.OUT) #linha 6
GPIO.setup(linha1, GPIO.OUT) # linha 1
GPIO.setup(entradacaixa, GPIO.OUT) # entrada caixa da agua
GPIO.setup(linha2, GPIO.OUT) # linha 2
GPIO.setup(saida2, GPIO.OUT) # caixa 2
GPIO.setup(linha3, GPIO.OUT) # linha 3
GPIO.setup(saida1, GPIO.OUT) # caixa 1
#GPIO.setup(dht_pin, GPIO.IN)

GPIO.output(bomba, 0) # Bomba da Agua
GPIO.output(linha4, 0) # linha 4
GPIO.output(linha5, 0) # Linha 5
GPIO.output(linha6, 0) #linha 6
GPIO.output(linha1, 0) # linha 1
GPIO.output(entradacaixa, 0) # entrada caixa da agua
GPIO.output(linha2, 0) # linha 2
GPIO.output(saida2, 0) # caixa 2
GPIO.output(linha3, 0) # linha 3
GPIO.output(saida1, 0) # caixa 1

# Inicializa Blynk
blynk = blynklib.Blynk('PS5k4e7DtZgKuzvwQPmwmpTdGDZvajQW')

# Registra os pinos virtuais
# Bomba da Agua
@blynk.on("V0") 
def write_handler(value):
  if int(value[0]) == 1:
    GPIO.output(bomba, 1)
  else:
    GPIO.output(bomba, 0)

# entrada caixa da agua
@blynk.on("V1") 
def v1_write_handler(value):
 if int(value[0]) == 1:
   GPIO.output(entradacaixa, 1)
 else:
   GPIO.output(entradacaixa, 0)

# caixa 1
@blynk.on("V2") 
def v2_write_handler(value):
 if int(value[0]) == 1:
   GPIO.output(saida1, 1)
 else:
   GPIO.output(saida1, 0)

# caixa 2
@blynk.on("V3") 
def v3_write_handler(value):
 if int(value[0]) == 1:
   GPIO.output(saida2, 1)
 else:
   GPIO.output(saida2, 0)

# linha 1
@blynk.on("V4") 
def v4_write_handler(value):
 if int(value[0]) == 1:
   GPIO.output(linha1, 1)
 else:
     GPIO.output(linha1, 0)

# linha 2
@blynk.on("V5") 
def v5_write_handler(value):
  if int(value[0]) == 1:
   GPIO.output(linha2, 1)
  else:
   GPIO.output(linha2, 0)

# linha 3
@blynk.on("V6") 
def v6_write_handler(value):
  if int(value[0]) == 1:
   GPIO.output(linha3, 1)
  else:
   GPIO.output(linha3, 0)

# linha 4
@blynk.on("V7") 
def v7_write_handler(value):
  if int(value[0]) == 1:
   GPIO.output(linha4, 1)
  else:
   GPIO.output(linha4, 0)

# Linha 5
@blynk.on("V8") 
def v8_write_handler(value):
  if int(value[0]) == 1:
   GPIO.output(linha5, 1)
  else:
   GPIO.output(linha5, 0)

#linha 6
@blynk.on("V9") 
def v9_write_handler(value):
  if int(value[0]) == 1:
   GPIO.output(linha6, 1)
  else:
   GPIO.output(linha6, 0)

while True:
 
    h, t = Adafruit_DHT.read_retry(sensor, pin)
#    if t is None and h is None:
#         print("Erro")
#    else:
#         print("Temp={0:0.1f}*°C, Humidade={1:0.1f}*%".format(t,h))
         
         blynk.virtual_write(10, h)
         blynk.virtual_write(11, t)
    blynk.run()

Quando eu executo ele, mostra isso

Traceback (most recent call last):
  File "/usr/lib/python3.9/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "/home/catia/Desktop/catia121022.py", line 141
    blynk.virtual_write(10, h)
IndentationError: unexpected indent

An unexpected indentation error occurs when there is some misalignment in the code. This could be due to whitespace used in Python. Python is a structured programming language and follows proper indentations.

Also, I’d suggest that you keep the while loop as clean as possible when using Blynk (you might spam the Blynk server with too many messages). Creating a separate function and calling it using a blynk timer would be the best approach.

Top. Teria algum exemplo de como eu colocaria no código, para fazer a leitura do sensor de modo correto?

Is there a reason why you’re using a Pi and Python for this project?

You clearly don’t have any Python experience, and the Pi is a really bad platform to use for IoT projects like this for so many different reasons.

You’d be far better using a NodeMCU and C++ as your programming language. If you did this there are many ready-made examples of how to use this hardware with Blynk.

Pete.

Do you mean the blynk timer ?

O cliente tem o raspberry pi 3b+. Sim. Eu já fiz isso no nodemcu e funcionou perfeitamente. A questão pelo qual o meu cliente tem esse raspberry é que já tinha um projeto similar, aí os caras não quiseram prestar suporte. Então para nao deixar essa placa parada, queria fazer esse esquema, pois uma raspberry aqui no Brazil está em torno dos 1200 reais

@blynk.on('V11')
def read_handler(pin):
    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin, retries=5, delay_seconds=1)
    Counter.cycle += 1
    print('temperature={} humidity={}'.format(temperature, humidity))
#  if t is None and h is None:
#   print("Erro")
#  else:
#   print("Temp={0:0.1f}*°C, Humidade={1:0.1f}*%".format(t,h))
            #blynk.virtual_write(10, h)
    blynk.virtual_write(V11, temperature)