How to use with soypat/cyw43439
Hello there! Thanks for creating all these libraries for the pico-w. I'm very new to tinygo so feel free to point me somewhere else if I'm just overlooking something.
I'm trying to use soypat/cyw43439 to connect to a wifi network which works great! But I'm not sure how to initialize a websocket client using that wifi network.
It really boils down to first setting up the wifi connection and next trying to create a websocket connection.
When I run this code on the pico-w I get
time=1970-01-01T00:00:15.242Z level=INFO msg="DHCP complete" cidrbits=16 ourIP=192.168.0.151 dns=192.168.0.115 broadcast=192.168.255.255 gateway="invalid IP" router=192.168.0.1 dhcp=192.168.0.1 hostname=TCP-pico lease=2h0m0s renewal=1h0m0s rebinding=1h45m0s
...
time=1970-01-01T00:00:15.249Z level=ERROR msg="while dialing:" !BADKEY="Lookup of host name '192.168.0.180' failed: Netdev not set"
My assumption here is that netdev isn't being set to the device that is created by connecting to the wifi network but that is really just an assumption coming from the error message and that the error message comes from a nopNetdev.
Anyway any advice would be awesome! Thank you!
If you are to use the net API you need to set the Netdever by calling UseNetdev:
https://github.com/tinygo-org/drivers/blob/019bbbe5fb66ff6ecd50949520253a50ecc72733/netdev/netdev.go#L56
That said, that is much easier said than done without a NetDever. I strongly suggest you use a seqs.TCPConn as the transport for peasocket. You can find examples on how to instantiate a Server TCPConn in cyw43439:
- https://github.com/soypat/cyw43439/tree/main/examples/tcpserver see
socketvariable. - https://github.com/soypat/cyw43439/tree/main/examples/tcpclient also see socket variable
Awesome! I’ll see if I can figure it out from here and report back. Thank you!
Looking at the code a bit more and it seems that net is baked into the Client, or at least for dialing. So it seems like you are suggesting passing a seqs.TCPConn to the tx and rx of the peasocket.Client in order to skip calling dial on the client but it seems like those can only be set by calling Dial. Maybe you are suggesting skipping the Client entirely and writing the glue code for interfacing seqs.TCPConn and peasocket.
If I do get this working I’d be more than happy to contribute back some documentation on this if you are interested. Maybe someone else can benefit from this discussion!
Ah yes, I recall now- the net is baked in because of http request that is needed to start the websocket connection :(
There is a lightweight http library written for working with seqs though- I don't have the time to rewrite the logic at this time
Well I appreciate the response! I might switch gears to MQTT since that is already part of the cyw43439 library.