Documentation
¶
Index ¶
- Variables
- type Async
- type Conn
- type Device
- func (d *Device) Async() <-chan Async
- func (d *Device) Cmd(name string, args ...any) (resp *Response, err error)
- func (d *Device) CmdConn(name string, args ...any) (*Conn, error)
- func (d *Device) CmdInt(name string, args ...any) (int, error)
- func (d *Device) CmdStr(name string, args ...any) (string, error)
- func (d *Device) Init(reset bool) error
- func (d *Device) Lock()
- func (d *Device) Name() string
- func (d *Device) Server() <-chan *Conn
- func (d *Device) SetServer(en bool)
- func (d *Device) Unlock()
- func (d *Device) UnsafeCmd(name string, args ...any) (resp *Response, err error)
- func (d *Device) UnsafeWrite(p []byte) (int, error)
- func (d *Device) UnsafeWriteString(s string) (int, error)
- type Error
- type ErrorESP
- type Response
Constants ¶
This section is empty.
Variables ¶
var ( ErrTimeout = &timeoutError{} ErrParse = errors.New("parse") ErrArgType = errors.New("argument type") ErrUnkConn = errors.New("unknown connection") )
Errors that may be returned in the Error.Err field.
Functions ¶
This section is empty.
Types ¶
type Async ¶ added in v0.2.0
Async represents an asynchronous message from the ESP-AT device or asynchronous receive error. The messages are called Active Message Reports in ESP-AT documentation and provide information of state changes like WiFi connect, disconnect, etc.
type Conn ¶
Conn represents a TCP or UDP connection.
The ID field is the connection ID in multiple connection mode or -1 in single connection mode.
The Ch field is the channel that returns received data in active receive mode or informs about the availability of new data (returning nil) in passive receive mode.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device requires CIPDINFO=0.
func NewDevice ¶
NewDevice returns a driver for ESP-AT device available via r and w. It also starts required background goroutines. You must call Init method before use the returned device.
func (*Device) Async ¶
Async returns a channel that can be used to wait for asynchronous messages from ESP-AT device. The channel overflow is signaled by sending an empty message. In such case up two oldest messages are removed from the channel and the received message is placed right after the empty one.
func (*Device) Cmd ¶
Cmd executes an AT command. Name should be a command name without the AT prefix (e.g. "+GMR" instead of "AT+GMR"). Args may be of type string, int or nil. The first argument can be also of type []byte and in a such case it may be used as a receive buffer (for example the CIPRECVDATA command may read data into it but is also allowed to discard all or part of received data if the buffer was missing or too small). CmdStr, CmdInt, CmdConn can be used instead of Cmd if the response type is known in advance.
func (*Device) CmdConn ¶
CmdConn provides a convenient way to execute a command when a *Conn response is expected.
func (*Device) CmdInt ¶
CmdInt provides a convenient way to execute a command when an int response is expected.
func (*Device) CmdStr ¶
CmdStr provides a convenient way to execute a command when a string response is expected.
func (*Device) Init ¶
Init initailizes the device to the known state using the following commands:
ATE0 AT+SYSLOG=1
If reset is true (recomended) it resets the device and waits for the ready state (2 second max.) before executing the above commands.
func (*Device) Lock ¶
func (d *Device) Lock()
Lock locks the device. Device should be locked before use UnsafeCmd, Write, WriteString methods.
func (*Device) UnsafeWrite ¶
UnsafeWrite works like io.Writer Write method. Device must be locked and ready for at least len(p) bytes of data.
Directories
¶
Path | Synopsis |
---|---|
examples/client
Client is an example of TCP/UDP client.
|
Client is an example of TCP/UDP client. |
examples/simpleclient
Simpleclient is a simple TCP-only client.
|
Simpleclient is a simple TCP-only client. |
examples/simpleserver
Simpleserver is a simple TCP-only server.
|
Simpleserver is a simple TCP-only server. |
examples/client
Client is an example of TCP/UDP client.
|
Client is an example of TCP/UDP client. |
examples/simpleclient
Simpleclient is a simple TCP-only client.
|
Simpleclient is a simple TCP-only client. |
examples/simpleserver
Simpleserver is a simple TCP-only server.
|
Simpleserver is a simple TCP-only server. |
examples
|
|
ipclient
Ipclient a is an example TCP/UDP client written using raw espat package.
|
Ipclient a is an example TCP/UDP client written using raw espat package. |
ipserver
Ipserver a is an example TCP server written using raw espat package.
|
Ipserver a is an example TCP server written using raw espat package. |
wifisetup
Wifisetup configures the ESP-AT device in Wi-Fi station mode.
|
Wifisetup configures the ESP-AT device in Wi-Fi station mode. |