mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-09 01:13:40 +00:00
move netdev and netlink into their own packages and out of drivers
This moves the netdev/netlink namespace out of drivers and into their own packages. Also, defines netdev and netlink as L3/L4 and L2 OSI layers, respectively. Move some L3 functionality from netlink to netdev (GetIPAddr). For netlink, add ConnectParams for NetConnect to pass in L2 connection parameters (ssid, pass, auth_type, etc). Also adds connection mode (STA, AP, etc). For netlink, add SendEth and RecvEthFunc funcs to handle L2 send/recv of Ethernet pkts.
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
// examples/net/webclient (for HTTP)
|
||||
// examples/net/tlsclient (for HTTPS)
|
||||
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -20,6 +22,9 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -31,7 +36,13 @@ func main() {
|
||||
|
||||
waitSerial()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -9,6 +9,8 @@
|
||||
// examples/net/webclient (for HTTP)
|
||||
// examples/net/tlsclient (for HTTPS)
|
||||
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -18,6 +20,9 @@ import (
|
||||
"machine"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -30,7 +35,13 @@ func main() {
|
||||
|
||||
waitSerial()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -46,7 +57,7 @@ func main() {
|
||||
}
|
||||
fmt.Println(string(buf.Bytes()))
|
||||
|
||||
netdev.NetDisconnect()
|
||||
link.NetDisconnect()
|
||||
}
|
||||
|
||||
// Wait for user to open serial console
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -9,6 +9,8 @@
|
||||
// examples/net/webclient (for HTTP)
|
||||
// examples/net/tlsclient (for HTTPS)
|
||||
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -19,6 +21,9 @@ import (
|
||||
"machine"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -30,7 +35,13 @@ func main() {
|
||||
|
||||
waitSerial()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -50,7 +61,7 @@ func main() {
|
||||
|
||||
fmt.Println(string(body))
|
||||
|
||||
netdev.NetDisconnect()
|
||||
link.NetDisconnect()
|
||||
}
|
||||
|
||||
// Wait for user to open serial console
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -9,6 +9,8 @@
|
||||
// examples/net/webclient (for HTTP)
|
||||
// examples/net/tlsclient (for HTTPS)
|
||||
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -19,6 +21,9 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -30,7 +35,13 @@ func main() {
|
||||
|
||||
waitSerial()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -1,23 +0,0 @@
|
||||
//go:build challenger_rp2040
|
||||
|
||||
// +build: challenger_rp2040
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"tinygo.org/x/drivers/espat"
|
||||
)
|
||||
|
||||
var cfg = espat.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// UART
|
||||
Uart: machine.UART1,
|
||||
Tx: machine.UART1_TX_PIN,
|
||||
Rx: machine.UART1_RX_PIN,
|
||||
}
|
||||
|
||||
var netdev = espat.New(&cfg)
|
||||
@@ -4,6 +4,8 @@
|
||||
// Note: It may be necessary to increase the stack size when using
|
||||
// paho.mqtt.golang. Use the -stack-size=4KB command line option.
|
||||
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal || challenger_rp2040
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -18,6 +20,8 @@ import (
|
||||
"time"
|
||||
|
||||
mqtt "github.com/soypat/natiu-mqtt"
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -30,7 +34,13 @@ var (
|
||||
func main() {
|
||||
waitSerial()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -99,7 +109,7 @@ func main() {
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
conn.SetReadDeadline(time.Now().Add(10*time.Second))
|
||||
conn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||
err = client.HandleNext()
|
||||
if err != nil {
|
||||
log.Fatal("handle next: ", err)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -1,23 +0,0 @@
|
||||
//go:build challenger_rp2040
|
||||
|
||||
// +build: challenger_rp2040
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"tinygo.org/x/drivers/espat"
|
||||
)
|
||||
|
||||
var cfg = espat.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// UART
|
||||
Uart: machine.UART1,
|
||||
Tx: machine.UART1_TX_PIN,
|
||||
Rx: machine.UART1_RX_PIN,
|
||||
}
|
||||
|
||||
var netdev = espat.New(&cfg)
|
||||
@@ -4,6 +4,8 @@
|
||||
// Note: It may be necessary to increase the stack size when using
|
||||
// paho.mqtt.golang. Use the -stack-size=4KB command line option.
|
||||
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal || challenger_rp2040
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -14,6 +16,8 @@ import (
|
||||
"time"
|
||||
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -37,7 +41,13 @@ var connectionLostHandler mqtt.ConnectionLostHandler = func(client mqtt.Client,
|
||||
func main() {
|
||||
waitSerial()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -1,23 +0,0 @@
|
||||
//go:build challenger_rp2040
|
||||
|
||||
// +build: challenger_rp2040
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"tinygo.org/x/drivers/espat"
|
||||
)
|
||||
|
||||
var cfg = espat.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// UART
|
||||
Uart: machine.UART1,
|
||||
Tx: machine.UART1_TX_PIN,
|
||||
Rx: machine.UART1_RX_PIN,
|
||||
}
|
||||
|
||||
var netdev = espat.New(&cfg)
|
||||
@@ -3,6 +3,8 @@
|
||||
// It creates a UDP connection to request the current time and parse the
|
||||
// response from a NTP server. The system time is set to NTP time.
|
||||
|
||||
//go:build pyportal || arduino_nano33 || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal || challenger_rp2040
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -13,6 +15,9 @@ import (
|
||||
"net"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -30,7 +35,13 @@ func main() {
|
||||
|
||||
waitSerial()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -49,7 +60,7 @@ func main() {
|
||||
}
|
||||
|
||||
conn.Close()
|
||||
netdev.NetDisconnect()
|
||||
link.NetDisconnect()
|
||||
|
||||
runtime.AdjustTimeOffset(-1 * int64(time.Since(t)))
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || arduino_nano33 || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal arduino_nano33 nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -1,23 +0,0 @@
|
||||
//go:build challenger_rp2040
|
||||
|
||||
// +build: challenger_rp2040
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"tinygo.org/x/drivers/espat"
|
||||
)
|
||||
|
||||
var cfg = espat.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// UART
|
||||
Uart: machine.UART1,
|
||||
Tx: machine.UART1_TX_PIN,
|
||||
Rx: machine.UART1_RX_PIN,
|
||||
}
|
||||
|
||||
var netdev = espat.New(&cfg)
|
||||
@@ -4,6 +4,8 @@
|
||||
//
|
||||
// nc -lk 8080
|
||||
|
||||
//go:build pyportal || arduino_nano33 || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal || challenger_rp2040
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -15,7 +17,9 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/netdev"
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -25,12 +29,20 @@ var (
|
||||
)
|
||||
|
||||
var buf = &bytes.Buffer{}
|
||||
var link netlink.Netlinker
|
||||
var dev netdev.Netdever
|
||||
|
||||
func main() {
|
||||
|
||||
waitSerial()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, dev = probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -48,9 +60,9 @@ func sendBatch() {
|
||||
|
||||
// make TCP connection
|
||||
message("---------------\r\nDialing TCP connection")
|
||||
fd, _ := netdev.Socket(drivers.AF_INET, drivers.SOCK_STREAM, drivers.IPPROTO_TCP)
|
||||
err := netdev.Connect(fd, "", ip, port)
|
||||
for ; err != nil; err = netdev.Connect(fd, "", ip, port) {
|
||||
fd, _ := dev.Socket(netdev.AF_INET, netdev.SOCK_STREAM, netdev.IPPROTO_TCP)
|
||||
err := dev.Connect(fd, "", ip, port)
|
||||
for ; err != nil; err = dev.Connect(fd, "", ip, port) {
|
||||
message(err.Error())
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
@@ -67,7 +79,7 @@ func sendBatch() {
|
||||
fmt.Fprint(buf,
|
||||
"\r---------------------------- i == ", i, " ----------------------------"+
|
||||
"\r---------------------------- i == ", i, " ----------------------------")
|
||||
if w, err = netdev.Send(fd, buf.Bytes(), 0, time.Time{}); err != nil {
|
||||
if w, err = dev.Send(fd, buf.Bytes(), 0, time.Time{}); err != nil {
|
||||
println("error:", err.Error(), "\r")
|
||||
break
|
||||
}
|
||||
@@ -79,12 +91,12 @@ func sendBatch() {
|
||||
fmt.Fprint(buf, "\nWrote ", n, " bytes in ", ms, " ms\r\n")
|
||||
message(buf.String())
|
||||
|
||||
if _, err := netdev.Send(fd, buf.Bytes(), 0, time.Time{}); err != nil {
|
||||
if _, err := dev.Send(fd, buf.Bytes(), 0, time.Time{}); err != nil {
|
||||
println("error:", err.Error(), "\r")
|
||||
}
|
||||
|
||||
println("Disconnecting TCP...")
|
||||
netdev.Close(fd)
|
||||
dev.Close(fd)
|
||||
}
|
||||
|
||||
func message(msg string) {
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || arduino_nano33 || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal arduino_nano33 nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -1,23 +0,0 @@
|
||||
//go:build challenger_rp2040
|
||||
|
||||
// +build: challenger_rp2040
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"tinygo.org/x/drivers/espat"
|
||||
)
|
||||
|
||||
var cfg = espat.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// UART
|
||||
Uart: machine.UART1,
|
||||
Tx: machine.UART1_TX_PIN,
|
||||
Rx: machine.UART1_RX_PIN,
|
||||
}
|
||||
|
||||
var netdev = espat.New(&cfg)
|
||||
@@ -5,6 +5,8 @@
|
||||
//
|
||||
// nc -lk 8080
|
||||
|
||||
//go:build pyportal || arduino_nano33 || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal || challenger_rp2040 || pico
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -14,6 +16,9 @@ import (
|
||||
"machine"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -28,7 +33,13 @@ func main() {
|
||||
|
||||
waitSerial()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || arduino_nano33 || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal arduino_nano33 nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -7,6 +7,8 @@
|
||||
//
|
||||
// $ nc 10.0.0.2 8080 <file >copy ; cmp file copy
|
||||
|
||||
//go:build pyportal || arduino_nano33 || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -14,6 +16,9 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -36,7 +41,13 @@ func main() {
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || arduino_nano33 || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal arduino_nano33 nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -5,6 +5,8 @@
|
||||
//
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security
|
||||
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -17,6 +19,9 @@ import (
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -80,7 +85,13 @@ func makeRequest() {
|
||||
func main() {
|
||||
waitSerial()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || arduino_nano33 || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal arduino_nano33 nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -6,8 +6,6 @@
|
||||
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -21,9 +19,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/ili9341"
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
"tinygo.org/x/tinyfont/proggy"
|
||||
"tinygo.org/x/tinyterm"
|
||||
)
|
||||
@@ -34,18 +32,6 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
netcfg = rtl8720dn.Config{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
}
|
||||
|
||||
netdev = rtl8720dn.New(&netcfg)
|
||||
|
||||
display = ili9341.NewSPI(
|
||||
machine.SPI3,
|
||||
machine.LCD_DC,
|
||||
@@ -66,17 +52,6 @@ var (
|
||||
font = &proggy.TinySZ8pt7b
|
||||
)
|
||||
|
||||
func notify(e drivers.NetlinkEvent) {
|
||||
switch e {
|
||||
case drivers.NetlinkEventNetUp:
|
||||
fmt.Println("Wifi connection UP")
|
||||
fmt.Fprintf(terminal, "Wifi connection UP")
|
||||
case drivers.NetlinkEventNetDown:
|
||||
fmt.Println("Wifi connection DOWN")
|
||||
fmt.Fprintf(terminal, "Wifi connection DOWN")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
machine.SPI3.Configure(machine.SPIConfig{
|
||||
@@ -100,9 +75,13 @@ func main() {
|
||||
|
||||
fmt.Fprintf(terminal, "Connecting to %s...\r\n", ssid)
|
||||
|
||||
netdev.NetNotify(notify)
|
||||
link, _ := probe.Probe()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
// }
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
//go:build pyportal || arduino_nano33 || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -28,6 +30,9 @@ import (
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -91,7 +96,13 @@ func closeConnection() {
|
||||
func main() {
|
||||
waitSerial()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || arduino_nano33 || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal arduino_nano33 nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -6,6 +6,8 @@
|
||||
// Note: It may be necessary to increase the stack size when using "net/http".
|
||||
// Use the -stack-size=4KB command line option.
|
||||
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -15,6 +17,9 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -37,7 +42,13 @@ func main() {
|
||||
|
||||
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -48,7 +59,7 @@ func main() {
|
||||
http.HandleFunc("/off", LED_OFF)
|
||||
http.HandleFunc("/on", LED_ON)
|
||||
|
||||
err := http.ListenAndServe(port, nil)
|
||||
err = http.ListenAndServe(port, nil)
|
||||
for err != nil {
|
||||
fmt.Printf("error: %s\r\n", err.Error())
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -6,6 +6,8 @@
|
||||
// Note: It may be necessary to increase the stack size when using
|
||||
// "golang.org/x/net/websocket". Use the -stack-size=4KB command line option.
|
||||
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -15,6 +17,8 @@ import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/websocket"
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -33,7 +37,13 @@ func waitSerial() {
|
||||
func main() {
|
||||
waitSerial()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -6,6 +6,8 @@
|
||||
// Note: It may be necessary to increase the stack size when using
|
||||
// "golang.org/x/net/websocket". Use the -stack-size=4KB command line option.
|
||||
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -16,6 +18,8 @@ import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/websocket"
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -40,12 +44,18 @@ func waitSerial() {
|
||||
func main() {
|
||||
waitSerial()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
http.Handle("/echo", websocket.Handler(EchoServer))
|
||||
err := http.ListenAndServe(port, nil)
|
||||
err = http.ListenAndServe(port, nil)
|
||||
if err != nil {
|
||||
panic("ListenAndServe: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
@@ -3,6 +3,8 @@
|
||||
// Note: It may be necessary to increase the stack size when using "net/http".
|
||||
// Use the -stack-size=4KB command line option.
|
||||
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -10,6 +12,9 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -25,7 +30,13 @@ func main() {
|
||||
// wait a bit for console
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, _ := probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
Reference in New Issue
Block a user