Skip to main content

MicroPython boards

The same iosignal as the Python package runs on MicroPython 1.28 or later. It has been checked on ESP32, ESP32-C3 and ESP32-S3. Boards connect to the server over the same TCP link (cong://) as Arduino boards; why, and the memory it saves, is in Transports.

  • The board as a device: a few lines of Python, or one line in a config file, make the board a device that appears in app.iosignal.net and remocon.kr.
  • Remote REPL: without a USB cable, iosignal-repl gives a REPL, code execution and file transfer. Sessions are sealed with the board's REPL key, so the server cannot read them. Anonymous boards are used from the same router; from another network, use remocon.kr device keys and login, or your own server.
  • Web IDE: edit and run the board's files and use its REPL from a browser, nothing to install: python.iosignal.net (English or Korean). See section 5.

1. Install on a board​

To do it all from a browser, open the USB setup page in desktop Chrome or Edge: it flashes MicroPython, then puts this package, Wi-Fi, the server and login, and a REPL key on the board.

From the command line, flash MicroPython on the board first (micropython.org/download). Then install in one of two ways.

From a computer over USB (the board needs no Wi-Fi):

pip install mpremote
mpremote mip install github:remocons/iosignal-python

On a board already on Wi-Fi, in its REPL:

import mip
mip.install("github:remocons/iosignal-python")

Ten files go to /lib/iosignal/. The board compiles them on the first import; with all of them loaded, an ESP32-C3 uses about 46 kB of memory.

2. Config files​

iosignal.board.start() reads its settings from files on the board. Copy them with mpremote cp or write them from the board's REPL.

FileContentExample
/iosignal.jsonserver, login ID, name (server is required){"server": "cong://io.iosignal.net:55488", "name": "Bench ESP32:Lab"}
/wifi.jsonWi-Fi{"ssid": "...", "password": "..."}
/device.jsondevice key of id (only when logging in){"key": "..."}
/repl.jsonthe remote REPL key's bytes (only when used){"key": "<hex>"}
  • Without id the board connects anonymously. Its CID changes on every connection, so this is for trying things out. Logged in, the CID stays the same and the link is encrypted with Boho (Ascon). Authentication
  • The board's main.py:
import iosignal.board
iosignal.board.start()

start() returns at once. Wi-Fi, the clock and the server connection come up one after another in a timer, and come back by themselves when lost. The REPL stays usable meanwhile. iosignal.board.status() shows the state.

3. The board as a device​

import iosignal.board
from machine import Pin

iosignal.board.start()
led = Pin(2, Pin.OUT)
lamp = iosignal.board.device(type="light.1", state="on=0",
on_change=lambda d: led.value(d.get("on") == "1"))
lamp.set(on="1") # changes from your own code show in the apps at once
  • One board is one CID and one device. Options: name (default: the configured name), type, state ("on=0;level=50", key order kept), buttons, panel, view, on_command(cmd, device), on_change(device)
  • Standard commands (on, off, toggle, all=, key=value) are handled, and every command is answered with $state.
  • Callbacks run in the link's timer: keep them short, such as setting pins. Their errors are kept in board.status() and the link keeps running.
  • The link runs on the chip's highest hardware timer (ESP32, ESP32-S3: Timer(3); ESP32-C3: Timer(1); since 0.2.3). Your code takes Timer(board.free_timer()) (usually 0). Re-initing or deiniting the link's timer stops the link silently until a reset.
  • A burst of commands (a dragged slider) is answered with at most one $state per 300 ms, always ending with the latest state.
  • A logged-in board without a name sends no $name, so the name registered for its CID shows.
  • More examples: board_iris.py (an iris.2 light with four RGB LEDs; hold button 2 to show the Wi-Fi signal and connection on the LEDs), and short scripts to run once: blink.py, button_read.py, board_info.py

Without code: pin devices​

A device entry in /iosignal.json makes start() create a pin device.

{"server": "cong://io.iosignal.net:55488", "name": "Relays:Yard",
"device": {"type": "relay4.1", "pins": [16, 17, 18, 19], "invert": true}}
TypePins
light.11
dimmer.11 (PWM)
relay4.14
switch2.1, switch3.1, switch4.1, switch8.12, 3, 4, 8

invert is for relay modules that switch on at LOW. All outputs start off.

Controlling other devices​

The board's code can follow another device's state and send it commands.

iosignal.board.subscribe("abc-123@$state", lambda tag, value: print(value))
iosignal.board.signal("abc-123@", "r1=1")

Subscriptions are sent again on every reconnect. Example: board_relay_buttons.py (two GPIO buttons toggle r1 and r2 of a relay4.1)

Wi-Fi on small boards​

Optional entries in /iosignal.json (from 0.1.2).

EntryMeaning
"txpower": 8.5Wi-Fi send power in dBm. Small ESP32-C3 boards (for example iris, C3 SuperMini) lose sent packets at full power until the connection stalls. 8.5 fixes that near the router; raise it (11, 15) in a far room
"wifi_mode": "b"802.11b only: slower, but it holds on a much weaker signal. The router must allow 802.11b
"linklog": falseturns off the drop log (/linklog.txt)
  • Wi-Fi power save is always off.
  • When sending stalls (no PONG to a ping, or nothing sent for 10 s), the link reconnects by itself, also while commands keep arriving. Every drop and reconnect is written to /linklog.txt with the UTC time, the reason and the signal (kept near 4 KB).

4. Remote REPL: iosignal-repl​

A board with a REPL key is used through the iosignal-repl command on a computer (included in pip install iosignal).

  1. Make a REPL key: tools/mpy_repl_key.py in the repository makes one and puts it on the board as /repl.json over USB and on the computer as ~/.iosignal/repl-<name>.key. The key is never printed and never sent to a server.
  2. Restart the board: the remote REPL is on.
  3. On the computer:
# REPL key (XXXXX-XXXXX-XXXXX-XXXXX-XXXXX, an older 64-digit hex key, or a passphrase of 10+ characters, from 0.2.4): paste it when asked (not shown), or export REPL_KEY=<key>, -k <key>, or a key file ~/.iosignal/repl-<board>.key
iosignal-repl find # boards on the same network
iosignal-repl repl # interactive (Ctrl-] leaves, Ctrl-C goes to the board)
iosignal-repl exec "print(1+1)" # streamed output, exit code 1 on an exception
iosignal-repl run app.py # run a local file without copying it
iosignal-repl put main.py # files: ls, cat, get, put, rm, mkdir, rmdir, mv
iosignal-repl info
iosignal-repl reset
  • The key is looked up as -k <key>, the REPL_KEY environment variable, a key file (REPL_KEY_FILE or ~/.iosignal/repl-<board>.key), and if none is found it is asked for on the terminal. A key given with -k stays in the shell history, so the prompt or REPL_KEY is better (from 0.1.2; up to 0.1.1 only key files).
  • Server: -s or IOSIGNAL_SERVER (default wss://io.iosignal.net/ws). Board: -b or IOSIGNAL_BOARD; without it, the only board on the network.
  • Sessions are sealed with the REPL key and one-time X25519 keys. Even if the REPL key leaks later, past sessions cannot be opened (forward secrecy).
  • Files travel apart from the REPL and are saved only when their SHA-256 matches.
  • A board with a remote REPL adds r=1 to its $ui. Control screens ignore it. iosignal-repl find and the web IDE use it to find boards, and remocon.kr adds a REPL button to the card. A board that is not made into a device sends t=micropython.1;r=1.
  • Without a REPL key, or with "repl": false in /iosignal.json, the board works as a device only, without a remote REPL.

5. Web IDE​

python.iosignal.net opens the same sealed session as iosignal-repl, in a browser (English or Korean, from the browser language or ?lang=en). The board's files are on the left, the editor in the middle, the REPL below. Examples open and run at once; files dropped from the computer go to the board.

  • Without an account, boards are anonymous and used from the same router as the board. An anonymous board's ID changes every time it reconnects and "find" works only on the same network, so for another network get device keys from remocon.kr (members) or run your own IOSignal server.
  • It needs the board ID and the REPL key. To open a board of your account from another network, log in with the key of another device of that account (id.key) (delivery policy).
  • The REPL key and the login key are kept in this browser only and never sent to the server.
  • Signed-in remocon.kr users open the same IDE at remocon.kr/ide or from the REPL button on a board card.
  • Keys, first setup and connecting are explained with pictures on the guide page.

6. When stuck​

  • If the board does not come online, connect to its REPL over USB and run import iosignal.board; print(iosignal.board.status()). It shows where it stopped: Wi-Fi, the clock or the server connection.
  • If the link drops often, read /linklog.txt for the time, reason and signal of each drop, and on a small board try a lower txpower.
  • If iosignal-repl find does not list the board, check that the board and the computer share a public IP (home channel) and that the board has a REPL key. On another network, name the board with -b <CID>. An account-owned board is reachable only after logging in with a device key of the same account or widening its delivery policy (delivery policy).
  • When a login ID is set but /device.json has no key, start() does not start and prints why.