I am making get requests in my program. If the ESP32 is not connected to the Blynk server, everything works fine, but as soon as it connects to Blynk, get requests do not work.
I am working with the ESP32 and Micropython. Below is the code and the errors I am getting.
import machine
import time
import BlynkLib # https://github.com/vshymanskyy/blynk-library-python/blob/master/examples/03_sync_virtual.py
from BlynkTimer import BlynkTimer
import network
import urequests as requests
BLYNK_AUTH = 'VeGkFg63Yi23wrwAUDctKaAjZgUC'
TIEMPO_ESPERAR_CONEXION_WIFI=25
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect("INFINITU242_2.4","CNC917MDE")
tiempoInicialPeriodo = time.time()
while not wifi.isconnected() and time.time()-tiempoInicialPeriodo<TIEMPO_ESPERAR_CONEXION_WIFI:
time.sleep(5)
print('WiFi IP:', wifi.ifconfig()[0])
data = requests.get(url='https://api.open-meteo.com/v1/forecast?latitude=22.28519&longitude=-97.87777¤t=temperature_2m').text
print("Here 1 -OK: ",data)
print("Connecting to Blynk server...")
blynk = BlynkLib.Blynk(BLYNK_AUTH,server="ny3.blynk.cloud")
data = requests.get(url='https://api.open-meteo.com/v1/forecast?latitude=22.28519&longitude=-97.87777¤t=temperature_2m').text
print("Here 2 -Error: ",data)
`MicroPython v1.20.0 on 2023-04-26; 4MB/OTA module with ESP32
Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ for Python v1.0.0 (esp32)
WiFi IP: 192.168.1.79
Here 1 -OK: {"latitude":22.25,"longitude":-97.875,"generationtime_ms":0.017762184143066406,"utc_offset_seconds":0,"timezone":"GMT","timezone_abbreviation":"GMT","elevation":21.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C"},"current":{"time":"2025-08-30T19:15","interval":900,"temperature_2m":33.9}}
Connecting to Blynk server...
Connecting to ny3.blynk.cloud:443...
Traceback (most recent call last):
File "<stdin>", line 32, in <module>
File "urequests.py", line 180, in get
File "urequests.py", line 93, in request
OSError: [Errno 12] ENOMEM
>>>
Here is the program and output without using Blynk:
import machine
import time
import network
import urequests as requests
TIEMPO_ESPERAR_CONEXION_WIFI=25
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect("INFINITUM2426_2.4","CNnC917MDE")
tiempoInicialPeriodo = time.time()
while not wifi.isconnected() and time.time()-tiempoInicialPeriodo<TIEMPO_ESPERAR_CONEXION_WIFI:
#desplegarMensajeVisual(1)
time.sleep(5)
#if not wifi.isconnected():
#desplegarMensajeVisual(2)
#desplegarMensajeVisual(3)
print('WiFi IP:', wifi.ifconfig()[0])
data = requests.get(url='https://api.open-meteo.com/v1/forecast?latitude=22.28519&longitude=-97.87777¤t=temperature_2m').text
print("Here 1 -OK: ",data)
# CICLO INFINITO EN ESPERA POR EVENTOS
while True:
try:
data = requests.get(url='https://api.open-meteo.com/v1/forecast?latitude=22.28519&longitude=-97.87777¤t=temperature_2m').text
print("Here 2 -OK: ",data)
time.sleep(5)
except KeyboardInterrupt:
break
wifi.disconnect()
time.sleep(1)
if not wifi.isconnected():
print("WiFi disconnected")
else:
print("WiFi connected. Can't disconnect")
print("Programa terminado")
OUTPUT
WiFi IP: 192.168.1.79
Here 1 -OK: {"latitude":22.25,"longitude":-97.875,"generationtime_ms":0.013113021850585938,"utc_offset_seconds":0,"timezone":"GMT","timezone_abbreviation":"GMT","elevation":21.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C"},"current":{"time":"2025-08-31T04:00","interval":900,"temperature_2m":28.5}}
Here 2 -OK: {"latitude":22.25,"longitude":-97.875,"generationtime_ms":0.015020370483398438,"utc_offset_seconds":0,"timezone":"GMT","timezone_abbreviation":"GMT","elevation":21.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C"},"current":{"time":"2025-08-31T04:00","interval":900,"temperature_2m":28.5}}
Here 2 -OK: {"latitude":22.25,"longitude":-97.875,"generationtime_ms":0.021219253540039062,"utc_offset_seconds":0,"timezone":"GMT","timezone_abbreviation":"GMT","elevation":21.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C"},"current":{"time":"2025-08-31T04:00","interval":900,"temperature_2m":28.5}}
Here 2 -OK: {"latitude":22.25,"longitude":-97.875,"generationtime_ms":0.027894973754882812,"utc_offset_seconds":0,"timezone":"GMT","timezone_abbreviation":"GMT","elevation":21.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C"},"current":{"time":"2025-08-31T04:00","interval":900,"temperature_2m":28.5}}
Here 2 -OK: {"latitude":22.25,"longitude":-97.875,"generationtime_ms":0.0152587890625,"utc_offset_seconds":0,"timezone":"GMT","timezone_abbreviation":"GMT","elevation":21.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C"},"current":{"time":"2025-08-31T04:00","interval":900,"temperature_2m":28.5}}
Here 2 -OK: {"latitude":22.25,"longitude":-97.875,"generationtime_ms":0.012278556823730469,"utc_offset_seconds":0,"timezone":"GMT","timezone_abbreviation":"GMT","elevation":21.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C"},"current":{"time":"2025-08-31T04:00","interval":900,"temperature_2m":28.5}}
Here 2 -OK: {"latitude":22.25,"longitude":-97.875,"generationtime_ms":0.02396106719970703,"utc_offset_seconds":0,"timezone":"GMT","timezone_abbreviation":"GMT","elevation":21.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C"},"current":{"time":"2025-08-31T04:00","interval":900,"temperature_2m":28.5}}
Traceback (most recent call last):
File "<stdin>", line 36, in <module>
KeyboardInterrupt:
The output is fine.