espat

package module
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2023 License: BSD-3-Clause Imports: 8 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

type Async struct {
	Str string
	Err error
}

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

type Conn struct {
	Dev *Device
	ID  int           // connection ID or -1
	Ch  <-chan []byte // receive channel
}

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

func NewDevice(name string, r io.Reader, w io.Writer) *Device

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

func (d *Device) Async() <-chan 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

func (d *Device) Cmd(name string, args ...any) (resp *Response, err error)

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

func (d *Device) CmdConn(name string, args ...any) (*Conn, error)

CmdConn provides a convenient way to execute a command when a *Conn response is expected.

func (*Device) CmdInt

func (d *Device) CmdInt(name string, args ...any) (int, error)

CmdInt provides a convenient way to execute a command when an int response is expected.

func (*Device) CmdStr

func (d *Device) CmdStr(name string, args ...any) (string, error)

CmdStr provides a convenient way to execute a command when a string response is expected.

func (*Device) Init

func (d *Device) Init(reset bool) error

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) Name

func (d *Device) Name() string

Name returns the device name set by NewDevice.

func (*Device) Server

func (d *Device) Server() <-chan *Conn

Server returns the server channel. See also SetServer.

func (*Device) SetServer

func (d *Device) SetServer(en bool)

SetServer enables the server channel. See also Server.

func (*Device) Unlock

func (d *Device) Unlock()

Unlock unlocks the device.

func (*Device) UnsafeCmd

func (d *Device) UnsafeCmd(name string, args ...any) (resp *Response, err error)

UnsafeCmd is like Cmd but intended to be used with a locked device.

func (*Device) UnsafeWrite

func (d *Device) UnsafeWrite(p []byte) (int, error)

UnsafeWrite works like io.Writer Write method. Device must be locked and ready for at least len(p) bytes of data.

func (*Device) UnsafeWriteString

func (d *Device) UnsafeWriteString(s string) (int, error)

UnsafeWriteString works like io.StringWriter WriteString method. Device must be locked and ready for at least len(s) bytes of data.

type Error

type Error struct {
	Dev string
	Cmd string
	Err error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Timeout

func (e *Error) Timeout() bool

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorESP

type ErrorESP struct {
	Code string
}

ErrorESP represents an error code returned by ESP-AT. It is returned in the Error.Err field.

func (*ErrorESP) Error

func (e *ErrorESP) Error() string

type Response added in v0.2.0

type Response struct {
	Str  string
	Int  int
	Conn *Conn
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL