kaluma-project / kaluma

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

any plan of support rasberry-pi-pico-w board ? #513

Closed jjpark78 closed 1 year ago

jjpark78 commented 2 years ago

rasberry pi just released their new board that support wifi.

https://www.raspberrypi.com/news/raspberry-pi-pico-w-your-6-iot-platform/

do we have any plan of support this new board ??

niklauslee commented 2 years ago

Sorry I have no time to do it at this time. I want to encourage voluntary contributions. 😅

dwyschka commented 2 years ago

I've got 3 of them. The Basic Image is working, but we need some other pin definitions. Because the onboard-LED is on the wifi-chip, not on the pico board anymore.

I havent testet wifi yet. (but i got problems to compile kaluma). I'm a beginner with it, but would try my best

sergeychernov commented 2 years ago

I have a problem to compile/build kaluma too. I have tried this way: node ./build.js --target rp2 --board pico And received: make: *** No targets specified and no makefile found. Stop.

communix commented 2 years ago

@sergeychernov please find the below link and try it. https://github.com/kaluma-project/kaluma/wiki/Build

adrian-burlacu-software commented 1 year ago

@communix Thanks for updating the driver recently🥲 https://github.com/kaluma-project/kaluma/tree/pico-w The code that I have so far:

const Cyw43 = require('pico_cyw43');
// Cyw43.PicoCYW43.prototype.close()
new Cyw43.PicoCYW43();
const ieee80211dev = new Cyw43.PicoCYW43WIFI();
global.__ieee80211dev = ieee80211dev;
const netdev = new Cyw43.PicoCYW43Network();
global.__netdev = netdev;

const { WiFi } = require('wifi');
const wifi = new WiFi();

wifi.scan((err, scanResults) => {
  if (err) {
    console.error(err);
  } else {
    console.log(scanResults);
  }
});

I have found the following issues that can be reproduced using this:

  1. After initializing the cyw43 with this line: new Cyw43.PicoCYW43();
  2. Then, do a soft reset after that very same line using Ctrl-D
  3. I think I reproduced this another way by re-flashing.

Results: Now, that same line hangs: new Cyw43.PicoCYW43();. Sometimes, this goes away after a hard reset, sometimes not. If the hard reset is an issue, I resolve it using Cyw43.PicoCYW43.prototype.close() before initializing the cyw43 again.

Expectations: maybe clean up and close the cyw43 state in the constructor so that it's idempotent - I can run it as many times as I need? Or maybe get rid of the requirement to initialize the cyw43 altogether and handle it without user input like in the documentation. This made debugging hard because I keep having to unplug the device and wasting flash cycles sometimes.

During those tests I also got this other small issue somehow when attempting to scan.

F2 not ready [CYW43] do_ioctl(2, 263, 82): timeout scan results: []

Expectation: Create an error instead of successful empty results.

The following are integration issues with the Kaluma JS code:

  1. I can't actually get wifi to connect without the enforce flag and with the credentials from storage because ieee80211dev.get_connection function obviously still needs to be implemented but that should be easy. Silly that the driver software is even responsible for this, it should be the Kaluma JS firmware that gets those items, but this is a larger change...
const { WiFi } = require('wifi');
const wifi = new WiFi();

// So I have to pass in credentials directly
wifi.connect({ ssid: 'MyWifi', password: 'passw0rd', enforce: true }, (err, connection) => {if (err) {console.log('error');} else {console.log('connected');}});
  1. The likely easy but BIG issue: I skipped over the Net part, I tried the HTTP module, where neither the request or the createServer functions work.
    
    var http = require('http');

var req = http.get({ host: 'http://jsonplaceholder.typicode.com', path: '/todos/1' }, function (response) {response.on('data', function (chunk) {console.log('received: ', chunk);});});

var message = '

Hello

'; var port = 80; var server = http.createServer((req, res) => {console.log('Request path: ' + req.url);response.writeHead(200, 'OK', {'Content-Type': 'text/html','Content-Length': message.length,});response.write(message);response.end();});

I think the this line `var fd = this._dev.socket(null, 'STREAM');` in the `src/modules/net/net.js` file is the problem. From your driver, this returns undefined. Then, it gets silently ignored here on line 60:

if (this._dev) { // Your network driver returns undefined!! var fd = this._dev.socket(null, 'STREAM');

**// Not sure why this is even called early...**
if (connectListener) {
  this.on('connect', connectListener);
}

**// This ignores the empty response and doesn't call the connect method on the Network driver?**
if (fd > -1) {
  this._socket(fd);
  this._dev.connect(this._fd, options.host, options.port, (err) => {
    if (err) {
      this.emit('error', new SystemError(this._dev.errno));
    } else {
      this.emit('ready');
    }
  });
}

} else { this.emit('error', new SystemError(6)); // ENXIO } return this; }



**Now that I peeked at your driver commit I realize that I didn't know enough C so I probably won't be able to help you fix the driver issues.**. I tried to deal with the Kaluma JS code for this last Network and HTTP part, and definitely would appreciate any guidance. I don't know how to fix what's failing and I don't have the setup to simulate the firmware(barely building in a VM Ubuntu server instance). I can debug now through that, but it's very slow.

Thank you again kindly!!
communix commented 1 year ago

@adrian-burlacu-software Thank you for your feedback.

The first issue is known issue #531. Let me check the other issues and fix it soon.

And let's discuss this topic in this link (https://github.com/kaluma-project/kaluma/discussions/515)

I'll close this issue since we already have a plan to support pico-W.

communix commented 1 year ago

@adrian-burlacu-software Please create issue with the [PICO-W] prefix when you find any issue. Thank you so much for your help.