
Como funciona
Esta bancada pode sair do simulador. O script é MicroPython comum (consulta DNS, socket TCP, HTTP GET para api.open-meteo.com), e o destino dessa requisição é decidido pela configuração de saída da placa. Em Sandbox (o padrão, e o único modo para bancadas sem login ou gratuitas), a requisição nunca sai da internet simulada e determinística dentro do núcleo, então a resposta não traz o tempo ao vivo e a tela mostra como ativá-lo. Mude o inspetor de Wi-Fi do ESP32 para Real internet (Pro com login, consentimento por circuito), e os mesmos bytes são capturados no gateway virtual e retransmitidos pelo serviço seguro de saída: o TLS é adicionado na borda, o destino precisa estar na lista de permissões selecionada, e cada requisição entra na cota e é auditada. O Open-Meteo não precisa de chave de API, então o JSON ao vivo volta direto ao firmware, que extrai current_weather e mostra a temperatura e o vento reais da cidade escolhida. No modo ao vivo, o laço busca os dados de novo uma vez por minuto, para respeitar a cota diária de saída.
O que está na bancada
- ESP32-C3
- OLED 1.5″ 128×128
Como está ligado
- furo a10→furo B-5
- furo a11→furo B+5
- furo a40→furo B-9
- furo a41→furo f10
- furo a42→furo g11
- furo a43→furo b20
- ESP32-C3 · gnd→furo e10
- ESP32-C3 · vin→furo e11
- ESP32-C3 · g8→furo e20
- ESP32-C3 · 3v3→furo i10
- ESP32-C3 · g9→furo i11
O código
Este script MicroPython roda na placa emulada a cada inicialização. Edite-o em “Code”.
from machine import I2C, Pin import framebuf, time i = I2C(0, scl=Pin(9), sda=Pin(8)) buf = bytearray(2048) fb = framebuf.FrameBuffer(buf, 128, 128, framebuf.MONO_VLSB) for c in b'\xae\x20\xa8\x7f\xd3\x00\xdc\x00\x81\x4f\xad\x8a\xa4\xa6\xaf': i.writeto(0x3d, bytes([0, c])) def show(): for p in range(16): i.writeto(0x3d, bytes([0x00, 0xb0 + p, 0x00, 0x10])) i.writeto(0x3d, b'\x40' + buf[p*128:(p+1)*128]) import network, socket, json # Pick your city (Open-Meteo needs no API key): CITY = 'London' LAT, LON = 51.5, -0.12 w = network.WLAN(network.STA_IF) w.active(True) fb.fill(0); fb.text('joining WiFi...', 0, 28); show() w.connect('BreadboardNet') while not w.isconnected(): time.sleep_ms(100) HOST = 'api.open-meteo.com' PATH = '/v1/forecast?latitude=%s&longitude=%s¤t_weather=true' % (LAT, LON) def fetch(): addr = socket.getaddrinfo(HOST, 80)[0][-1] s = socket.socket() s.connect(addr) s.send(('GET ' + PATH + ' HTTP/1.0\r\nHost: ' + HOST + '\r\n\r\n').encode()) r = b'' while True: c = s.recv(256) if not c: break r += c s.close() # Report the status too: a canned sandbox reply (200) and a refused # egress request (4xx/5xx) both fail to parse, but they mean different # things and deserve different advice. status = 0 try: head, body = r.split(b'\r\n\r\n', 1) status = int(head.split(b' ')[1]) except (ValueError, IndexError): return None, status try: return json.loads(body)['current_weather'], status except (ValueError, KeyError): return None, status # not live data n = 0 while True: cw, status = fetch() n += 1 fb.fill(0) if cw: print('live', n, CITY, cw['temperature'], 'C') fb.text('REAL INTERNET', 0, 2) fb.hline(0, 13, 128, 1) fb.text(CITY[:16], 0, 26) fb.text('%s C' % cw['temperature'], 0, 48) fb.text('wind %s km/h' % cw['windspeed'], 0, 66) fb.hline(0, 88, 128, 1) fb.text('open-meteo.com', 0, 96) fb.text('live via egress', 0, 108) fb.text('fetch #%d' % n, 0, 120) elif status >= 400: # Real internet IS on, but the gateway refused this request. The # bench notice says why (not Pro, quota spent, gateway offline). print('egress refused - HTTP %d. See the bench notice for the reason.' % status) fb.text('EGRESS REFUSED', 0, 2) fb.hline(0, 13, 128, 1) fb.text('HTTP %d' % status, 0, 26) fb.text('The gateway said', 0, 44) fb.text('no. Check the', 0, 56) fb.text('bench notice.', 0, 68) fb.hline(0, 88, 128, 1) fb.text('ESP32 > Wi-Fi >', 0, 100) fb.text('Sandbox to undo', 0, 116) else: print('sandbox reply - flip the ESP32 inspector Wi-Fi toggle to Real internet (signed-in Pro) for live data') fb.text('SANDBOX MODE', 0, 2) fb.hline(0, 13, 128, 1) fb.text('Canned sandbox', 0, 26) fb.text('data, not live.', 0, 38) fb.hline(0, 60, 128, 1) fb.text('For LIVE data:', 0, 68) fb.text('sign in (Pro),', 0, 84) fb.text('ESP32 > Wi-Fi >', 0, 100) fb.text('Real internet', 0, 116) show() time.sleep_ms(60000 if cw else 5000)
Experimente
- Execute primeiro sem login: o OLED mostra SANDBOX MODE com os passos para ativar. Essa tela é toda a história do controle de acesso.
- Entre com uma conta Pro, clique no ESP32 e mude o Wi-Fi de Sandbox para Real internet. A próxima busca mostra a temperatura real.
- Edite CITY/LAT/LON no topo do script em Code e execute de novo para buscar a sua cidade.
- Abra o Wi-Fi sniffer: os quadros 802.11 são idênticos nos dois modos. A troca entre internet de testes e internet real acontece no gateway, não no ar.



