HTTP Requests
Closed this issue · 13 comments
SO happy that cyw43439 functionality has been added to tinygo - great work.
I've been looking through the examples and I'm not seeing any functionality for http requests. I see the http server, but the power of http requests is also very important.
Thanks!
power of http requests is also very important.
Agreed! Just out of curiosity, what will you be using this for?
I might try to add the functionality next week if I have the time
I'm building a small game console with a leaderboard functionality that needs the ability to upload high scores to an external server and load them from the server too. Currently, I'm deciding on whether to program it with KalumaJS, which uses embedded javascript and has pico w support, but obviously has huge performance downsides, or tinygo, which doesn't have the most rounded wifi support with the pico w. I'm def leaning towards tinygo due to performance.
Thanks! Functionality would be appreciated.
Hey @soypat ,
First of all, thank you so much for creating this driver for the Raspberry Pi Pico W! It's exciting to see support for WiFi on this platform.
I've successfully set up the driver and managed to connect to the network, which is fantastic. However, I've run into an issue when attempting to use the net/http package provided by TinyGo. Specifically, I encounter a nil pointer dereference error during execution.
Here are some details about my setup and the issue:
TinyGo Version: 0.31.1
Code Snippet:
dev := cyw43439.NewPicoWDevice()
cfg := cyw43439.DefaultWifiConfig()
err := dev.Init(cfg)
if err != nil {
panic(err)
}
err = dev.JoinWPA2(ssid, pass)
res, err := http.Get("http://example.com") // Line that is causing nil pointer dereference
I'm relatively new to TinyGo and not entirely sure if this is a compatibility issue between the driver and the net/http package or if I'm missing something in my setup. Any guidance or suggestions you could provide would be greatly appreciated!
We're still working on how to best integrate networking with MCUs into the Go standard library.
The way I'd suggest going about performing an HTTP request today would be with seqs/httpx
for now which is still in Work-In-Progress phase. I've created a PR with the functionality here: #42. You are free to try it though keep in mind I'm still bug-hunting.
I'll try it out, thank you!
Also, worth noting I've developed a way to debug seqs in a linux environment, which would make it easier to see what's going on through wireshark and other tools.
See this curl
command equivalent using seqs here:
https://github.com/soypat/netif/blob/main/cmd/gurl/gurl.go
To run you need to be sudo to give access to low level ethernet socket:
go build -o=gurl.bin ./cmd/gurl/ && sudo ./gurl.bin http://192.168.0.44:8080
Take not that if you wish to debug in vscode you'll need to run vscode as sudo. The instructions are in the README, but sum up a bit more than running:
sudo code --user-data-dir ~/.config/Code --no-sandbox .
Heya peeps! I've managed to get HTTP client working with a local connection. I've written some documentation present in the PR so that the purpose and scope of the example is clear to readers, will be reflected in #42. (See ./examples/http-client/README.md)
Please give it a try and let me know how it goes!
I'm not fluent in English, so I use a translator.
Can you also implement HTTPS requests?
@womeya Hey there! About TLS/HTTPS, I think @scottfeldman could give you a much better response than me. My understanding is Scott is working on TLS support on the Go upstream side of things. Ideally it should be as simple as wrapping the TCPConn instance with the following code from the crypto/tls
standard library package (more examples here and more docs here):
secureConn := tls.Client(tcpConn, &tls.Config{
Certificates: []tls.Certificate{cert},
})
err := secureConn.Handshake()
if err != nil {
panic("TLS handshake failed: " + err.Error())
}
Those interested in TLS connection please create a new issue requesting an example of its usage, otherwise I'll be closing this issue within a week or so- As for the PR I'll merge it one of these days.
@womeya Hey there! About TLS/HTTPS, I think @scottfeldman could give you a much better response than me. My understanding is Scott is working on TLS support on the Go upstream side of things.
Hi, yes, I'm working on/off on porting the full "net" package from Go to TinyGo, including crypto/tls. The current status I have them compiling cleanly using the drivers/examples/net examples. I had to stub out the netdev calls to the wifi driver (for now). Cool news is both "net" and "crypto/tls" are ported over unmodified. The bad news is all the pain moves to "syscall".
But that makes sense right? Because the network stack and drivers live in the OS kernel (pretending we have an OS), and the syscall interface is the porcelain interface between the kernel and apps. So seqs would implement the syscall interfaces for networking. (Discovering the syscalls necessary to support the drivers/examples/net examples was my next move, but I'm spotty on time).
I'm not sure how any of this helps the matter at hand of getting an HTTPS request dialed out.
The PR for TinyGo tracking the porting work is tinygo-org/tinygo#4187
(For some reason it was closed by me 3 days ago by mistake; I git flubbed something).
I just wanted to call the telegram bot api, but I don't think I can do it myself.
I decided to change the architecture and call the bot api from an external server and then call pico's api.
Thank you for kind response.