NOTE: I have tested originally on a hidden network I am not sure if this is an issue and if so will there be additional flags to set?
NOTE: I have also tested on a regular network and the exact same result of response timeout error.
NOTE: I have tested with a proper password and an invalid password and the same result of response timeout error.
The issue is it immediately gives a timeout after connecting (or what I think is connecting.
---- Opened the serial port COM5 ----
Connecting to myssid
response timeout error:
response timeout error:
response timeout error:
response timeout error:
response timeout error:
...
code
// 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 -w 5 -lk 8080
package main
import (
"bytes"
"fmt"
"machine"
"time"
"tinygo.org/x/drivers/espat"
"tinygo.org/x/drivers/net"
)
var (
// access point info
ssid string = "myssid"
pass string = "mypass"
uart = machine.UART0
tx = machine.GP17
rx = machine.GP16
adaptor *espat.Device
)
// IP address of the server aka "hub". Replace with your own info.
const serverIP = ""
var buf = &bytes.Buffer{}
func main() {
initAdaptor()
connectToAP()
for {
sendBatch()
time.Sleep(500 * time.Millisecond)
}
}
func sendBatch() {
// make TCP connection
ip := net.ParseIP(serverIP)
raddr := &net.TCPAddr{IP: ip, Port: 8080}
laddr := &net.TCPAddr{Port: 8080}
message("---------------\r\nDialing TCP connection")
conn, err := net.DialTCP("tcp", laddr, raddr)
for ; err != nil; conn, err = net.DialTCP("tcp", laddr, raddr) {
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")
continue
}
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")
}
// Right now this code is never reached. Need a way to trigger it...
println("Disconnecting TCP...")
conn.Close()
}
// connect to access point
func connectToAP() {
time.Sleep(2 * time.Second)
println("Connecting to " + ssid)
err := adaptor.ConnectToAccessPoint(ssid, pass, 100*time.Second)
if err != nil { // error connecting to AP
for {
println(err)
time.Sleep(1 * time.Second)
}
}
println("Connected.")
time.Sleep(2 * time.Second)
ip, err := adaptor.GetClientIP()
for ; err != nil; ip, err = adaptor.GetClientIP() {
message(err.Error())
time.Sleep(1 * time.Second)
}
message(ip)
}
func message(msg string) {
println(msg, "\r")
}
func initAdaptor() *espat.Device {
uart.Configure(machine.UARTConfig{TX: tx, RX: rx})
adaptor = espat.New(uart)
adaptor.Configure()
return adaptor
}
Is there something broke in the driver or is there something I am missing? Thanks in advance!
I have set up the ESP8266 wifi on a pico on UART0 so on the wifi chip I have power and gnd and uart0tx to GP17 and rx to GP16. Code included below.
ESP82666 wifi unit: U0TXD esp8266 wifi -> GP17 pico UART0 TX U0RXD esp8266 wifi -> GP16 pico UART0 RX
3.3 -> 3.3 CH_EN -> 3.3 gnd -> gnd
no additional wires, am I missing connections?
NOTE: I have tested originally on a hidden network I am not sure if this is an issue and if so will there be additional flags to set? NOTE: I have also tested on a regular network and the exact same result of response timeout error. NOTE: I have tested with a proper password and an invalid password and the same result of response timeout error.
The issue is it immediately gives a timeout after connecting (or what I think is connecting.
code
Is there something broke in the driver or is there something I am missing? Thanks in advance!