kaluma-project / kaluma

A tiny JavaScript runtime for RP2040 (Raspberry Pi Pico)
https://kalumajs.org
Apache License 2.0
647 stars 37 forks source link

[pico-w] http server freeze after few requests #589

Closed dreanmer closed 1 year ago

dreanmer commented 1 year ago

I've made a simple server to test the functionality but the server only accept 2 to 3 requests then die. This is the code I'm using:

try {
    const {WiFi} = require('wifi');
    const http   = require('http');

    const wifi = new WiFi();
    wifi.connect({
        ssid    : 'SSID',
        password: 'password'
    }, (err, info) => {
        if (err) {
            throw err;
        }
        console.log('connected');
    });

    const server = http.createServer((req, res) => {
        let message = "{\"success\": true,\"message\": \"success message\"}";
        console.log('Request path: ' + req.url);
        res.writeHead(200, 'OK', {
            'Content-Type'  : 'application/json',
            'Content-Length': message.length
        });
        res.write(message);
        res.end();
    });

    server.on('error', (err) => {
        console.log('http server error: ' + err.message);
        throw err;
    });

    server.listen(80, () => {
        console.log('HTTP server listening on port: ' + 80);
    });

} catch (err) {
    console.log('caught error: ' + err.message);
    console.log('end');
}

never caught any error on the catch, also wifi.on('connected' is not being triggered. if you point me out to info on how can i debug, see memory usage, etc... I can try to help a bit more.

communix commented 1 year ago

@dreanmer I found that dns code has issue and it make system freeze. So I temporarily disable it and I don't think http server need dns feature. So could you please try it with the attached test FW? wifi.on('connected', callback) feature is also fixed in this FW. kaluma-rp2-pico-w-1.1.0-beta.2_disable_dns_0702.uf2.zip

dreanmer commented 1 year ago

I'll try it as soon as my new boards arrives! thanks!