Hi there,
Im developing this project to help watering plants and I would ideally want to have it integrated with some IO platform.
Its my first time using ESP32 and such platforms, so bear with me please.
I managed to set up a dashboard with virtual pin VO (int <0, 255>) with a slider to control LED on ESP32 to check that connection.
I flashed mpy firmware to ESP32, managed to connect to internet (checked connecting to other websites as Google), used Thonny to upload Blynklib llibrary, wrote this quick script with the help of datasheet for mpy with Blynk and chatgpt:
import network
from time import sleep
from machine import Pin
import blynklib
import socket # For low-level socket connection debugging
import usocket
# not to leak my data but quadruple checked:
SSID = 'my ssid'
PASS='password to my network'
BLYNK_AUTH = 'blynk auth'
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect(SSID, PASS)
# check if board connected
while not wifi.isconnected():
sleep(1)
print('Wifi connect retry...')
if wifi.isconnected():
print('Wifi connected')
print('Wifi IP: ', wifi.ifconfig())
print('connecting to the blynk server:')
blynk = blynklib.Blynk(BLYNK_AUTH)
led = Pin(27, Pin.OUT)
@blynk.handle_event('write V0')
def write_virtual_pin_handler(pin, value):
led_value = int(value[0])
print(f"[WRITE_VIRTUAL_PIN_EVENT] Pin: V{pin} Value: {led_value}")
# Add more debug prints to ensure the handler is triggered
print("write_virtual_pin_handler called")
if led_value > 120:
led.value(1) # Turn on LED
print('LED ON')
else:
led.value(0) # Turn off LED
print('LED OFF')
def check_socket_connections():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1) # Set a timeout for testing
print("Testing connection to Blynk cloud...")
s.connect(("blynk-cloud.com", 8080)) # Check TCP connection to Blynk
print("Connected to Blynk on port 8080 (TCP).")
s.close()
# Optionally, test TLS/SSL connection (port 443 or 9443)
print("Testing connection to Blynk cloud (SSL)...")
s.connect(("blynk-cloud.com", 9443)) # SSL connection
print("Connected to Blynk on port 9443 (SSL).")
s.close()
except Exception as e:
print("Socket connection error: ", e)
while True:
try:
check_socket_connections() # Check connections before running Blynk
blynk.run()
except Exception as e:
print("Error in Blynk connection: ", str(e))
sleep(2) # Wait a bit before retrying
print("Running Blynk, checking WLAN status...")
print(wifi.ifconfig())
sleep(5) # Add a delay between status updates
This is what I get from ESP:
Wifi connected
Wifi IP: (‘', '’, ‘', '’)
connecting to the blynk server:
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ for Python v0.2.6
Testing connection to Blynk cloud…
Socket connection error: -202
Running Blynk, checking WLAN status…
(‘', '’, ‘', '’)
Testing connection to Blynk cloud…
Socket connection error: -202
I tried turning off firewall in router, enabling UPnP, adding vritual servers accordingy:
-
Entry 1:
-
Service Name: Blynk_HTTP
-
Remote Host: (leave blank)
-
WAN Port:
80 - 80
-
Device: (select your ESP32)
-
LAN IP Address:
192.168.8.X
-
LAN Port:
80
-
Entry 2:
-
Service Name: Blynk_HTTPS
-
Remote Host: (leave blank)
-
WAN Port:
443 - 443
-
Device: (select your ESP32)
-
LAN IP Address:
192.168.8.X
-
LAN Port:
443
-
Entry 3:
-
Service Name: Blynk_TCP
-
Remote Host: (leave blank)
-
WAN Port:
8080 - 8080
-
Device: (select your ESP32)
-
LAN IP Address:
192.168.8.X
-
LAN Port:
8080
-
Entry 4:
-
Service Name: Blynk_SSL
-
Remote Host: (leave blank)
-
WAN Port:
9443 - 9443
-
Device: (select your ESP32)
-
LAN IP Address:
192.168.8.X
-
LAN Port:
9443
I cant see my board as Online in Blynk and there is no data exchange.
Does someone maybe have a suggestion?