Skip to content
php-baremetal REGISTRY
Publish a package

php-baremetal/ext-wifi

bm-ext MIT

wifi_scan/connect/ap_start (STA + SoftAP from PHP), as a php-baremetal extension package. WiFi-capable SoCs only; the arch WiFi HAL is a separate package.

Wi-Fi from PHP: scan for networks, join one as a station, or open the board's own access point, with plain functions (wifi_scan(), wifi_connect(), wifi_ap_start(), ...), and with events on the event bus of ext-events in the event-driven runtime (wifi_events()). The firmware never connects to Wi-Fi by itself and stores no credentials in its configuration: your script decides when and where to connect, with credentials from wherever you keep them (a .env baked into the firmware, ext-store, a setup page).

ext-wifi is platform-neutral: it requires the virtual php-baremetal/wifi-hal, and conductor adds the HAL for your SDK platform (php-baremetal/esp32-wifi-hal on ESP32). Boards with a Wi-Fi radio only.

Install

In a project created with phpbm init:

bash
composer require php-baremetal/ext-wifi

Example

php
<?php
$ssid = getenv('WIFI_SSID') ?: '';
$pass = getenv('WIFI_PASSWORD') ?: null;   // null or '' for an open network

if (wifi_connect($ssid, $pass, 20000)) {
    printf("online: %s (%d dBm)\n", wifi_ip(), wifi_rssi());
} else {
    wifi_ap_start('my-board-setup', 'setup-1234');
    printf("no network; join my-board-setup and open http://%s/\n", wifi_ap_ip());
}

Without blocking, in the event-driven runtime:

php
<?php
use Baremetal\Events;
use Baremetal\Wifi\{Online, ConnectFailed};

wifi_events();
Events::listen(Online::class, fn (Online $e) => printf("online: %s\n", $e->ip));
Events::listen(ConnectFailed::class, fn (ConnectFailed $e) => printf("failed: %s\n", $e->reason->value));
wifi_connect(getenv('WIFI_SSID') ?: '', getenv('WIFI_PASSWORD') ?: null, wait: false, retries: -1);

Documentation

License

MIT.

Read the full documentation