Prise en main
Copiez un prompt de configuration incluant les étapes d'installation et le guide markdown complet pour ce plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-wifi`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/wifi/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Installer
Section intitulée « Installation »Vous pouvez utiliser notre configuration assistée par IA pour installer le plugin. Ajoutez les skills Capgo à votre outil d'IA avec la commande suivante :
bunx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsUtilisez ensuite le prompt suivant :
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-wifi` plugin in my project.Si vous préférez une installation manuelle, installez le plugin en exécutant les commandes suivantes et suivez les instructions spécifiques à chaque plateforme ci-dessous :
bun add @capgo/capacitor-wifibunx cap syncImporter
Section intitulée « Import »import { CapacitorWifi } from '@capgo/capacitor-wifi';Démarrage rapide
Section intitulée « Démarrage rapide »import { CapacitorWifi, NetworkSecurityType } from '@capgo/capacitor-wifi';
await CapacitorWifi.addNetwork({ ssid: 'MyNetwork', password: 'mypassword', isHiddenSsid: false, securityType: NetworkSecurityType.WPA2_PSK});Exemple : connexion
Section intitulée « Exemple : connexion »import { CapacitorWifi, WifiConnectionErrorCode } from '@capgo/capacitor-wifi';
try { await CapacitorWifi.connect({ ssid: 'MyNetwork', password: 'mypassword', autoRouteTraffic: true, // Android only timeoutMs: 30000, });} catch (error: any) { switch (error.code) { case WifiConnectionErrorCode.WIFI_DISABLED: // Ask the user to enable Wi-Fi break; case WifiConnectionErrorCode.PERMISSION_DENIED: // Request the required permission break; default: // Generic connection error break; }}Exemple : disconnect
Section intitulée « Exemple : déconnexion »import { CapacitorWifi } from '@capgo/capacitor-wifi';
await CapacitorWifi.disconnect();Erreurs courantes
Section intitulée « Erreurs courantes »- Autorisations: appelez
checkPermissions()puisrequestPermissions()si nécessaire. - Écouteurs: supprimez les handles lors du démontage des écrans.
- Source de vérité : fiez-vous
src/definitions.tsau repo GitHub.
Aperçu de API
Section intitulée « Aperçu API »addNetwork
Section intitulée « addNetwork »Affiche une boîte de dialogue système pour ajouter un réseau Wi-Fi à l’appareil. Sur Android SDK 30+, cela ouvre les paramètres Wi-Fi système avec le réseau pré-rempli. Sur iOS, cela se connecte directement au réseau.
import { CapacitorWifi, NetworkSecurityType } from '@capgo/capacitor-wifi';
await CapacitorWifi.addNetwork({ ssid: 'MyNetwork', password: 'mypassword', isHiddenSsid: false, securityType: NetworkSecurityType.WPA2_PSK});Se connecte à un réseau Wi-Fi. Sur Android, cela crée une connexion temporaire qui ne route pas le trafic via le réseau par défaut. Définissez autoRouteTraffic sur true pour lier le trafic de l’app au réseau connecté (utile pour les AP locaux ou hébergés sur l’appareil). Pour une connexion persistante sur Android, utilisez addNetwork() à la place. Sur iOS, cela crée une connexion persistante.
import { CapacitorWifi } from '@capgo/capacitor-wifi';
await CapacitorWifi.connect({ ssid: 'MyNetwork', password: 'mypassword', autoRouteTraffic: true // Android only: route app traffic through this network});disconnect
Section intitulée « disconnect »Se déconnecte du réseau Wi-Fi actuel. Sur iOS, ne se déconnecte que des réseaux ajoutés via ce plugin.
import { CapacitorWifi } from '@capgo/capacitor-wifi';
await CapacitorWifi.disconnect();getAvailableNetworks
Section intitulée « getAvailableNetworks »Récupère la liste des réseaux Wi-Fi disponibles depuis la dernière analyse. Disponible uniquement sur Android.
import { CapacitorWifi } from '@capgo/capacitor-wifi';
const { networks } = await CapacitorWifi.getAvailableNetworks();networks.forEach(network => { console.log(`SSID: ${network.ssid}, Signal: ${network.rssi} dBm`);});getIpAddress
Section intitulée « getIpAddress »Récupérer l’adresse IP actuelle de l’appareil. Disponible sur Android et iOS.
import { CapacitorWifi } from '@capgo/capacitor-wifi';
const { ipAddress } = await CapacitorWifi.getIpAddress();console.log('IP Address:', ipAddress);Récupérer l’indicateur de force du signal reçu (RSSI) du réseau actuel en dBm. Disponible uniquement sur Android.
import { CapacitorWifi } from '@capgo/capacitor-wifi';
const { rssi } = await CapacitorWifi.getRssi();console.log('Signal strength:', rssi, 'dBm');Récupérer l’identifiant du jeu de services (SSID) du réseau actuel. Disponible sur Android et iOS.
import { CapacitorWifi } from '@capgo/capacitor-wifi';
const { ssid } = await CapacitorWifi.getSsid();console.log('Connected to:', ssid);getWifiInfo
Section intitulée « getWifiInfo »Récupérer des informations complètes sur le réseau WiFi actuellement connecté. Cette méthode fournit en un seul appel des informations détaillées sur le réseau : SSID, BSSID, adresse IP, fréquence, vitesse du lien et force du signal. Sur iOS, certains champs peuvent ne pas être disponibles et seront undefined.
import { CapacitorWifi } from '@capgo/capacitor-wifi';
const info = await CapacitorWifi.getWifiInfo();console.log('Network:', info.ssid);console.log('BSSID:', info.bssid);console.log('IP:', info.ip);console.log('Frequency:', info.frequency, 'MHz');console.log('Speed:', info.linkSpeed, 'Mbps');console.log('Signal:', info.signalStrength);isEnabled
Section intitulée « isEnabled »Vérifiez si le Wi-Fi est activé sur l'appareil. Disponible uniquement sur Android.
import { CapacitorWifi } from '@capgo/capacitor-wifi';
const { enabled } = await CapacitorWifi.isEnabled();console.log('WiFi is', enabled ? 'enabled' : 'disabled');startScan
Section intitulée « startScan »Lancez le scan des réseaux Wi-Fi. Disponible uniquement sur Android. Les résultats sont transmis via l'écouteur d'événement « networksScanned ». Note : peut échouer à cause du throttling système ou de problèmes matériels.
import { CapacitorWifi } from '@capgo/capacitor-wifi';
await CapacitorWifi.addListener('networksScanned', () => { console.log('Scan completed');});await CapacitorWifi.startScan();checkPermissions
Section intitulée « checkPermissions »Vérifiez l'état actuel des permissions d'accès à la localisation.\nL'autorisation de localisation est requise pour les opérations Wi-Fi sur les deux plateformes.
import { CapacitorWifi } from '@capgo/capacitor-wifi';
const status = await CapacitorWifi.checkPermissions();console.log('Location permission:', status.location);requestPermissions
Section intitulée « requestPermissions »Demandez l'autorisation de localisation à l'utilisateur. L'autorisation de localisation est requise pour les opérations Wi-Fi sur les deux plateformes.
import { CapacitorWifi } from '@capgo/capacitor-wifi';
const status = await CapacitorWifi.requestPermissions();if (status.location === 'granted') { console.log('Permission granted');}Référence de type
Section intitulée « Référence de type »AddNetworkOptions
Section intitulée « AddNetworkOptions »Options pour ajouter un réseau.
export interface AddNetworkOptions { /** * The SSID of the network to add * * @since 7.0.0 */ ssid: string;
/** * The password for the network (optional for open networks) * * @since 7.0.0 */ password?: string;
/** * Whether the network is hidden (Android only) * * @since 7.0.0 * @default false */ isHiddenSsid?: boolean;
/** * The security type of the network (Android only) * * @since 7.0.0 * @default NetworkSecurityType.WPA2_PSK */ securityType?: NetworkSecurityType;}ConnectOptions
Section intitulée « ConnectOptions »Options pour se connecter à un réseau.
export interface ConnectOptions { /** * The SSID of the network to connect to * * @since 7.0.0 */ ssid: string;
/** * The password for the network (optional for open networks) * * @since 7.0.0 */ password?: string;
/** * Whether the network is hidden (Android only) * * @since 7.0.0 * @default false */ isHiddenSsid?: boolean;
/** * Whether to automatically route app traffic through the connected Wi-Fi network (Android only) * When enabled, it binds the app process to the connected network using ConnectivityManager.bindProcessToNetwork() * This is useful for connecting to local/device-hosted APs (e.g., ESP32, IoT devices) that don't have internet access. * * @since 7.0.0 * @default false */ autoRouteTraffic?: boolean;}DisconnectOptions
Section intitulée « DisconnectOptions »Options pour se déconnecter d'un réseau.
export interface DisconnectOptions { /** * The SSID of the network to disconnect from (optional) * * @since 7.0.0 */ ssid?: string;}GetAvailableNetworksResult
Section intitulée « GetAvailableNetworksResult »Résultat de getAvailableNetworks().
export interface GetAvailableNetworksResult { /** * List of available networks * * @since 7.0.0 */ networks: Network[];}GetIpAddressResult
Section intitulée « GetIpAddressResult »Résultat de getIpAddress().
export interface GetIpAddressResult { /** * The device's IP address * * @since 7.0.0 */ ipAddress: string;}GetRssiResult
Section intitulée « GetRssiResult »Résultat de getRssi().
export interface GetRssiResult { /** * The signal strength in dBm * * @since 7.0.0 */ rssi: number;}GetSsidResult
Section intitulée « GetSsidResult »Résultat de getSsid().
export interface GetSsidResult { /** * The SSID of the current network * * @since 7.0.0 */ ssid: string;}WifiInfo
Section intitulée « WifiInfo »Informations WiFi complètes.
export interface WifiInfo { /** * The SSID (network name) of the current network * * @since 7.0.0 */ ssid: string;
/** * The BSSID (MAC address) of the access point. * Not available on iOS. * * @since 7.0.0 */ bssid?: string;
/** * The device's IP address on the network * * @since 7.0.0 */ ip: string;
/** * The network frequency in MHz. * Not available on iOS. * * @since 7.0.0 */ frequency?: number;
/** * The connection speed in Mbps. * Not available on iOS. * * @since 7.0.0 */ linkSpeed?: number;
/** * The signal strength (0-100). * Calculated from RSSI on Android. * Not available on iOS. * * @since 7.0.0 */ signalStrength?: number;}IsEnabledResult
Section intitulée « IsEnabledResult »Résultat de isEnabled().
export interface IsEnabledResult { /** * Whether Wi-Fi is enabled * * @since 7.0.0 */ enabled: boolean;}PermissionStatus
Section intitulée « PermissionStatus »Statut de l’autorisation.
export interface PermissionStatus { /** * Location permission state * * @since 7.0.0 */ location: PermissionState;}RequestPermissionsOptions
Section intitulée « RequestPermissionsOptions »Options pour demander les autorisations.
export interface RequestPermissionsOptions { /** * Permissions to request * * @since 7.0.0 */ permissions?: 'location'[];}NetworkSecurityType
Section intitulée « NetworkSecurityType »Types de sécurité réseau
export enum NetworkSecurityType { /** * Open network with no security * * @since 7.0.0 */ OPEN = 0,
/** * WEP security * * @since 7.0.0 */ WEP = 1,
/** * WPA/WPA2 Personal (PSK) * * @since 7.0.0 */ WPA2_PSK = 2,
/** * WPA/WPA2/WPA3 Enterprise (EAP) * * @since 7.0.0 */ EAP = 3,
/** * WPA3 Personal (SAE) * * @since 7.0.0 */ SAE = 4,
/** * WPA3 Enterprise * * @since 7.0.0 */ WPA3_ENTERPRISE = 5,
/** * WPA3 Enterprise 192-bit mode * * @since 7.0.0 */ WPA3_ENTERPRISE_192_BIT = 6,
/** * Passpoint network * * @since 7.0.0 */ PASSPOINT = 7,
/** * Enhanced Open (OWE) * * @since 7.0.0 */ OWE = 8,
/** * WAPI PSK * * @since 7.0.0 */ WAPI_PSK = 9,
/** * WAPI Certificate * * @since 7.0.0 */ WAPI_CERT = 10,}Source de vérité
Section intitulée « Source de vérité »Cette page est générée à partir de src/definitions.ts. Relancez la synchronisation lorsque l’API public change en amont.
Continuer depuis Getting Started
Section intitulée « Continuer après Prise en main »Si vous utilisez Prise en main pour planifier les opérations du dashboard et de API, connectez-l’avec Utiliser @capgo/capacitor-wifi pour la fonctionnalité native de la page Utiliser @capgo/capacitor-wifi, Aperçu de API pour les détails d'implémentation dans « Vue d'ensemble de API », Introduction pour les détails d'implémentation dans l'introduction, Clés API pour les détails d'implémentation dans « Clés API », et Appareils pour les détails d'implémentation dans Devices.