mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
06dd60fba2
* Add wifi driver comboat for Elecrow W5 rp2040 and rp2350 devices Combo-AT driver uses AT command set to talk to onboard rtl8720d wifi device. The driver supports UDP/TCP/TLS clients in Wifi STA mode. Support for UDP/TCP servers is not supported, currently. https://aithinker-combo-guide.readthedocs.io/en/latest/docs/instruction/index.html https://aithinker-combo-guide.readthedocs.io/en/latest/docs/command-set/index.html https://aithinker-combo-guide.readthedocs.io/en/latest/docs/command-examples/index.html * Add wifi driver comboat for Elecrow W5 rp2040 and rp2350 devices Combo-AT driver uses AT command set to talk to onboard rtl8720d wifi device. The driver supports UDP/TCP/TLS clients in Wifi STA mode. Support for UDP/TCP servers is not supported, currently. https://aithinker-combo-guide.readthedocs.io/en/latest/docs/instruction/index.html https://aithinker-combo-guide.readthedocs.io/en/latest/docs/command-set/index.html https://aithinker-combo-guide.readthedocs.io/en/latest/docs/command-examples/index.html * switch to comboat_fw build tag for examples/net's that work with comboat driver
104 lines
1.9 KiB
Go
104 lines
1.9 KiB
Go
// This example opens a TCP connection and sends some data, for the purpose of
|
|
// testing speed and connectivity.
|
|
//
|
|
// You can open a server to accept connections from this program using:
|
|
//
|
|
// nc -lk 8080
|
|
|
|
//go:build ninafw || wioterminal || challenger_rp2040 || comboat_fw
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"log"
|
|
"machine"
|
|
"net"
|
|
"time"
|
|
|
|
"tinygo.org/x/drivers/netlink"
|
|
"tinygo.org/x/drivers/netlink/probe"
|
|
)
|
|
|
|
var (
|
|
ssid string
|
|
pass string
|
|
addr string = "10.0.0.100:8080"
|
|
)
|
|
|
|
var buf = &bytes.Buffer{}
|
|
|
|
func main() {
|
|
|
|
waitSerial()
|
|
|
|
link, _ := probe.Probe()
|
|
|
|
err := link.NetConnect(&netlink.ConnectParams{
|
|
Ssid: ssid,
|
|
Passphrase: pass,
|
|
})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
for {
|
|
sendBatch()
|
|
time.Sleep(500 * time.Millisecond)
|
|
}
|
|
}
|
|
|
|
func sendBatch() {
|
|
|
|
// make TCP connection
|
|
message("---------------\r\nDialing TCP connection")
|
|
conn, err := net.Dial("tcp", addr)
|
|
for ; err != nil; conn, err = net.Dial("tcp", addr) {
|
|
message(err.Error())
|
|
time.Sleep(5 * time.Second)
|
|
}
|
|
|
|
n := 0
|
|
w := 0
|
|
start := time.Now()
|
|
|
|
// send data
|
|
message("Sending data")
|
|
|
|
for i := 0; i < 1000; i++ {
|
|
buf.Reset()
|
|
fmt.Fprint(buf,
|
|
"\r---------------------------- i == ", i, " ----------------------------"+
|
|
"\r---------------------------- i == ", i, " ----------------------------")
|
|
if w, err = conn.Write(buf.Bytes()); err != nil {
|
|
println("error:", err.Error(), "\r")
|
|
break
|
|
}
|
|
n += w
|
|
}
|
|
|
|
buf.Reset()
|
|
ms := time.Now().Sub(start).Milliseconds()
|
|
fmt.Fprint(buf, "\nWrote ", n, " bytes in ", ms, " ms\r\n")
|
|
message(buf.String())
|
|
|
|
if _, err := conn.Write(buf.Bytes()); err != nil {
|
|
println("error:", err.Error(), "\r")
|
|
}
|
|
|
|
println("Disconnecting TCP...")
|
|
conn.Close()
|
|
}
|
|
|
|
func message(msg string) {
|
|
println(msg, "\r")
|
|
}
|
|
|
|
// Wait for user to open serial console
|
|
func waitSerial() {
|
|
for !machine.Serial.DTR() {
|
|
time.Sleep(100 * time.Millisecond)
|
|
}
|
|
}
|