Connection without a router

Hi,

I’m testing the blynk-python-library 2.0 on an ESP32 with OLED.

The code shown below works well but I cannot understand how. Nowhere in the code I’m mentioning my router’s credentials so, technically, should not connect to Internet but, it is.
Can someone shine some light to my obscured brain?
TIA

P.S.
I can only think that the ESP is getting the network credentials from memory and not from the variables.

import BlynkLib
#from BlynkTimer import BlynkTimer
import machine, ssd1306, gc
from machine import Pin, I2C
#import network
import urequests
#from time import sleep
import esp
esp.osdebug(None)

#oled connections
i2c = I2C(scl=machine.Pin(4), sda=machine.Pin(5))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)

ext_ip = ''
my_ip = ''

# Initialize Blynk
blynk = BlynkLib.Blynk('****')

#***  not used ****
def wifi_conn():
    station = network.WLAN(network.STA_IF)
    station.active(True)
    station.connect(ssid, password)
    while station.isconnected() == False:
        pass
    
def display_txt():
    gc.collect() #clear memory
    oled.fill(0)
    oled.text('MicroPython on', 0, 0)
    oled.text('an ESP32 with an', 0, 10)
    oled.text('attached SSD1306', 0, 20)
    oled.text('OLED display', 0, 30)
    oled.show()
   
def display_ips():
    gc.collect() #clear memory
    oled.fill(0)
    oled.text('my ip:', 0, 0)
    oled.text(my_ip, 0, 10)
    oled.text('my ext ip:', 0, 20)
    oled.text(ext_ip, 0, 30)
    oled.show()
    
def get_extip():
    global ext_ip
    r = urequests.get('http://mydomain/myip.php')
    #print(int(r.status_code)) #should be 200
    if(int(r.status_code) == 200):
        ext_ip = r.text
    r.close()

# Register Virtual Pins
@blynk.VIRTUAL_WRITE(1)
def my_write_handler(value):
    if(value[0] == '1'):
        get_extip()
        display_txt()
        print('External IP: {}'.format(ext_ip))

@blynk.VIRTUAL_READ(2)
def my_read_handler():
    # this widget will show some time in seconds..
    blynk.virtual_write(2, ext_ip)

try:
    while True:
        blynk.run()
        #timer.run() #TODO
except OSError as e:
    print('Failed to read/publish.')
    print()
    print(e)

i found this.

ESP32 saves the last used credentials (SSID and password) in flash automatically and will attempt to use them upon next boot.

1 Like