atmelino / MPPT

Maximum Power Point Tracking Solar Powered Computer
MIT License
1 stars 0 forks source link

MPPT app quits when web client closed #1

Open atmelino opened 5 years ago

atmelino commented 5 years ago

App should not quit. Add try-catch clause.

/home/pi/github/MPPT/version3_0/raspberryPi/MPPT/node_modules/ws/lib/websocket.js:320 throw err; ^

Error: WebSocket is not open: readyState 2 (CLOSING) at WebSocket.send (/home/pi/github/MPPT/version3_0/raspberryPi/MPPT/node_modules/ws/lib/websocket.js:314:19) at each (/home/pi/github/MPPT/version3_0/raspberryPi/MPPT/server.js:184:16) at Set.forEach () at broadcast (/home/pi/github/MPPT/version3_0/raspberryPi/MPPT/server.js:182:17) at Timeout.mainLoop [as _onTimeout] (/home/pi/github/MPPT/version3_0/raspberryPi/MPPT/server.js:310:9) at listOnTimeout (timers.js:324:15) at processTimers (timers.js:268:5)

function broadcast(data) { //debugMsgln("broadcast - number of clients " + wss.clients.size);

wss.clients.forEach(function each(client) {  //182
    //debugMsgln('sending to client');
    client.send(data);
});

}

atmelino commented 5 years ago
function broadcast(data) {
    try {
        wss.clients.forEach(function each(client) {
            client.send(data);
        });
    } catch (e) { console.log(e); }
}

seems to help; server did not quit.