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

Incorrect socket details for 'net' and 'http' on pico-w board #549

Closed c6fc closed 1 year ago

c6fc commented 1 year ago

Using the kaluma-rp2-pico-w-1.1.0-beta.1.uf2 release, the 'createServer' method for 'net' and 'http' modules shows incorrect details for connected sockets:

image

In both cases, calls to '.write()' methods fail to deliver the data back to the client, but no errors are returned and the callbacks for both '.write()' and '.end()' execute normally. I haven't been able to verify what the outbound packet from the pico-w look like (so I don't know if injecting the correct raddr and rport will cause the data to be delivered), but at the moment it seems that the incorrect socket details are preventing server responses from reaching the client.

communix commented 1 year ago

@c6fc Could you share the source code you tested? I want to reproduce the same issue on my setup.

c6fc commented 1 year ago

Sure thing. These are both after a lot of iterations during testing, so they're super ugly, but it should be reproducible for you:

https://gist.github.com/c6fc/49d27fb60b8313029d756e497a6b7bfd https://gist.github.com/c6fc/dd95af62477d184a96863d496603e469

communix commented 1 year ago

@c6fc Thank you for your information. I found some issues on the current FW. One of the issue is that tcp server is not reset at soft reset. So we need to have hard reset to run a tcp server. I fix this issue and upload new code in the pico-w branch. please test with this FW and let me know your test result. https://github.com/kaluma-project/kaluma/tree/pico-w

c6fc commented 1 year ago

if I use the uf2 I built with node build --target=rp2 --board=pico-w on the current pico-w branch, I get the following error on upload.

Screenshot from 2023-01-18 09-19-55

If I switch back to the public release pico-w-1.1.0-beta.1 UF2, I don't get this error. Are there additional arguments required for the pico-w build to get the drivers passed into it?

communix commented 1 year ago

@c6fc It's strange. there's no changes related to the wifi driver. Could you please try it with .reset command before .load command?

And please use attached uf2 file which I used for this test.

kaluma-rp2-pico-w-1.1.0-beta.1_pico_w_test_0118.uf2.zip

etx commented 1 year ago

@communix I just gave this latest uf2 a try. net.createServer seems to work correctly once. I can do a res.write to send a string back to the client (netcat in this case). After that one connection I have to hard reset to make another connection. Unfortunately http.createServer is hanging when I call it.

For both I'm just using the example code from the docs.

Appreciate your work on this!!

emerson-a commented 1 year ago

I have the same issue.

Tried it both with the current FW and kaluma-rp2-pico-w-1.1.0-beta.1_pico_w_test_0118.uf2.zip Same result on both, only works once. Here's my code: https://gist.github.com/emerson-a/d48df41f8431ebcb3ed516f17485d7ef

I also appreciate your work on this!

communix commented 1 year ago

@etx @emerson-a Thank you for your feedback. let me check it.

communix commented 1 year ago

@emerson-a @etx Could you please try it with this binary? http.create server is working with this code. But I can't reproduce the hard reset issue, (After that one connection I have to hard reset to make another connection.) If you still have the same issue, please create new issue with the detailed scenario.

kaluma-rp2-pico-w-1.1.0-beta.1_pico_w_test_0212.uf2.zip

K4ST0R commented 1 year ago

I got the same issue than @emerson-a and @etx .

After one connection, I can't make another connection.

I try to debug it but I am really struggling. It seems to have a link with the code using the listen fd to manage the connection with the client.

Changing : https://github.com/kaluma-project/kaluma/blob/192154ee7f4dba8421b026c97448910c850bb438/src/modules/pico_cyw43/module_pico_cyw43.c#L680-L683 by

static err_t __tcp_server_accept_cb(void *arg, struct tcp_pcb *newpcb,
                                    err_t err) {
  if (err == ERR_OK)  {
 // test create fd
  uint8_t *oldFd = (uint8_t *)arg;
  int fdV = km_get_socket_fd();
  uint8_t *fd = &fdV;
  memcpy(&__socket_info.socket[*fd], &__socket_info.socket[*oldFd], sizeof(__socket_data_t));
  __socket_info.socket[*fd].fd = fdV;

(Sorry for the really bad code!)

I am able to connect again with another client but i can't connect two client in parallel.

emerson-a commented 1 year ago

@emerson-a @etx Could you please try it with this binary? http.create server is working with this code. But I can't reproduce the hard reset issue, (After that one connection I have to hard reset to make another connection.) If you still have the same issue, please create new issue with the detailed scenario.

kaluma-rp2-pico-w-1.1.0-beta.1_pico_w_test_0212.uf2.zip

I have tested this but the same issue occurs. I can only make one http connection.

Thanks again for your work on this!

communix commented 1 year ago

@emeson-a, @K4ST0R Thank you for your feedback. I think the remaining issue issue is two client support. I have created new issue about is (#557), So let's discuss this issue at #557. I'll close this issue. If anyone find new issue or the issue which is not fixed now, please create new issue. I'll take a look this issue.

etx commented 1 year ago

@communix Could you post the JS file you're flashing to test http.createServer? I'm still having a hard time getting it to work. Thank you!

communix commented 1 year ago

@etx I'm testing with the @emerson-a 's code. https://gist.github.com/emerson-a/d48df41f8431ebcb3ed516f17485d7ef