当前位置: 首页 > 工具软件 > Espruino > 使用案例 >

Espruino 断网后重连wifi

程磊
2023-12-01

var wifi;
var ssid = 'ssid';
var password = 'password';
function initWifi(){
    print('trying to connect wifi...');
    wifi = require('Wifi');
    wifi.connect(ssid, {password: password}, function() {
        console.log('Connected to Wifi.IP address is:', wifi.getIP().ip);
    });
}

function connectWifiAgain(){
    if((require('Wifi').getStatus().ssid=='') || !(require('Wifi').getStatus().ssid)){
        console.log('lost connect, trying to connect wifi again...');
        wifi.connect(ssid, {password: password}, function() {
            console.log('Connected to Wifi.IP address is:', wifi.getIP().ip);
        });        
    }
}

function onInit(){
    initWifi();
    setInterval(connectWifiAgain,10000);
}

onInit();
save();

 类似资料: