Documentation ¶
Overview ¶
Package wifinina implements TCP wireless communication over SPI with an attached separate ESP32 board using the Arduino WiFiNINA protocol.
In order to use this driver, the ESP32 must be flashed with specific firmware from Arduino. For more information: https://github.com/arduino/nina-fw
Index ¶
- Constants
- Variables
- func PrintBuffer(ninabuf *Buffer, w io.Writer) error
- type Buffer
- func (b *Buffer) AddByte(p byte)
- func (b *Buffer) AddData(p []byte)
- func (b *Buffer) AddString(s string)
- func (b *Buffer) AddUint16(p uint16)
- func (b *Buffer) AddUint32(p uint32)
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Command() byte
- func (b *Buffer) EndCmd()
- func (b *Buffer) GetBufferParam(n int, v []byte) (int, error)
- func (b *Buffer) GetByteParam(n int, v *byte) error
- func (b *Buffer) GetStringParam(n int, v *string) error
- func (b *Buffer) GetUint16Param(n int, v *uint16) error
- func (b *Buffer) GetUint32Param(n int, v *uint32) error
- func (b *Buffer) GetUint64Param(n int, v *uint64) error
- func (b *Buffer) IsDataCommand() bool
- func (b *Buffer) IsReply() bool
- func (b *Buffer) Len() int
- func (b *Buffer) NumParams() uint8
- func (b *Buffer) ParamLenSize() uint8
- func (b *Buffer) ReadReply(r ByteTransferer, checkCmd byte) (err error)
- func (b *Buffer) StartCmd(cmd uint8) *Buffer
- func (b *Buffer) WriteTo(w io.Writer) (int, error)
- type ByteTransferer
- type ConnectionStatus
- type Device
- func (d *Device) AnalogWrite(pin uint8, value uint8) error
- func (d *Device) AvailableData(sock uint8) (dataSize uint16, err error)
- func (d *Device) CheckDataSent(sock uint8) (bool, error)
- func (d *Device) Configure()
- func (d *Device) DigitalWrite(pin uint8, value uint8) error
- func (d *Device) Disconnect() error
- func (d *Device) GetClientState(sock uint8) (uint8, error)
- func (d *Device) GetConnectionStatus() (ConnectionStatus, error)
- func (d *Device) GetCurrentBSSID() (MACAddress, error)
- func (d *Device) GetCurrentEncryptionType() (EncryptionType, error)
- func (d *Device) GetCurrentRSSI() (int32, error)
- func (d *Device) GetCurrentSSID() (string, error)
- func (d *Device) GetDataBuf(sock uint8, buf []byte) (int, error)
- func (d *Device) GetFwVersion() (string, error)
- func (d *Device) GetHostByName(hostname string) (IPAddress, error)
- func (d *Device) GetIP() (ip, subnet, gateway IPAddress, err error)
- func (d *Device) GetMACAddress() (MACAddress, error)
- func (d *Device) GetNetworkBSSID(idx int) (MACAddress, error)
- func (d *Device) GetNetworkChannel(idx int) (uint8, error)
- func (d *Device) GetNetworkEncrType(idx int) (EncryptionType, error)
- func (d *Device) GetNetworkRSSI(idx int) (int32, error)
- func (d *Device) GetNetworkSSID(idx int) string
- func (d *Device) GetReasonCode() (uint8, error)
- func (d *Device) GetSocket() (uint8, error)
- func (d *Device) GetTemperature() (float32, error)
- func (d *Device) GetTime() (string, error)
- func (d *Device) InsertDataBuf(buf []byte, sock uint8) (bool, error)
- func (d *Device) NewDriver() net.DeviceDriver
- func (d *Device) PinMode(pin uint8, mode uint8) error
- func (d *Device) Ping(ip IPAddress, ttl uint8) int16
- func (d *Device) ScanNetworks() (int, error)
- func (d *Device) SendData(buf []byte, sock uint8) (uint16, error)
- func (d *Device) SendUDPData(sock uint8) (bool, error)
- func (d *Device) SetDNS(which uint8, dns1 uint32, dns2 uint32) error
- func (d *Device) SetDebug(on bool) error
- func (d *Device) SetHostname(hostname string) error
- func (d *Device) SetKey(ssid string, index uint8, key string) error
- func (d *Device) SetNetwork(ssid string) error
- func (d *Device) SetNetworkForAP(ssid string) error
- func (d *Device) SetPassphrase(ssid string, passphrase string) error
- func (d *Device) SetPassphraseForAP(ssid string, passphrase string) error
- func (d *Device) SetPowerMode(mode uint8) error
- func (d *Device) StartClient(addr uint32, port uint16, sock uint8, mode uint8) error
- func (d *Device) StartScanNetworks() (uint8, error)
- func (d *Device) StartServer(port uint16, sock uint8, mode uint8) error
- func (d *Device) StopClient(sock uint8) error
- type Driver
- func (drv *Driver) ConnectSSLSocket(addr, portStr string) error
- func (drv *Driver) ConnectTCPSocket(addr, portStr string) error
- func (drv *Driver) ConnectUDPSocket(addr, portStr, lportStr string) (err error)
- func (drv *Driver) DisconnectSocket() error
- func (drv *Driver) GetDNS(domain string) (string, error)
- func (drv *Driver) IsConnected() (bool, error)
- func (drv *Driver) IsSocketDataAvailable() bool
- func (drv *Driver) ReadSocket(b []byte) (n int, err error)
- func (drv *Driver) Response(timeout int) ([]byte, error)
- func (drv *Driver) StartSocketSend(size int) error
- func (drv *Driver) Write(b []byte) (n int, err error)
- type EncryptionType
- type Error
- type IPAddress
- type MACAddress
- type Transport
Constants ¶
const ( MaxSockets = 4 MaxNetworks = 10 MaxAttempts = 10 MaxLengthSSID = 32 MaxLengthWPAKey = 63 MaxLengthWEPKey = 13 WlFailure = -1 WlSuccess = 1 StatusNoShield ConnectionStatus = 255 StatusIdle ConnectionStatus = 0 StatusNoSSIDAvail ConnectionStatus = 1 StatusScanCompleted ConnectionStatus = 2 StatusConnected ConnectionStatus = 3 StatusConnectFailed ConnectionStatus = 4 StatusConnectionLost ConnectionStatus = 5 StatusDisconnected ConnectionStatus = 6 EncTypeTKIP EncryptionType = 2 EncTypeCCMP EncryptionType = 4 EncTypeWEP EncryptionType = 5 EncTypeNone EncryptionType = 7 EncTypeAuto EncryptionType = 8 TCPStateClosed = 0 TCPStateListen = 1 TCPStateSynSent = 2 TCPStateSynRcvd = 3 TCPStateEstablished = 4 TCPStateFinWait1 = 5 TCPStateFinWait2 = 6 TCPStateCloseWait = 7 TCPStateClosing = 8 TCPStateLastACK = 9 TCPStateTimeWait = 10 CmdStart = 0xE0 CmdEnd = 0xEE CmdErr = 0xEF CmdSetNet = 0x10 CmdSetPassphrase = 0x11 CmdSetKey = 0x12 CmdSetIPConfig = 0x14 CmdSetDNSConfig = 0x15 CmdSetHostname = 0x16 CmdSetPowerMode = 0x17 CmdSetAPNet = 0x18 CmdSetAPPassphrase = 0x19 CmdSetDebug = 0x1A CmdGetTemperature = 0x1B CmdGetReasonCode = 0x1F CmdGetConnStatus = 0x20 CmdGetIPAddr = 0x21 CmdGetMACAddr = 0x22 CmdGetCurrSSID = 0x23 CmdGetCurrBSSID = 0x24 CmdGetCurrRSSI = 0x25 CmdGetCurrEncrType = 0x26 CmdScanNetworks = 0x27 CmdStartServerTCP = 0x28 CmdGetStateTCP = 0x29 CmdDataSentTCP = 0x2A CmdAvailDataTCP = 0x2B CmdGetDataTCP = 0x2C CmdStartClientTCP = 0x2D CmdStopClientTCP = 0x2E CmdGetClientStateTCP = 0x2F CmdDisconnect = 0x30 CmdGetIdxRSSI = 0x32 CmdGetIdxEncrType = 0x33 CmdReqHostByName = 0x34 CmdGetHostByName = 0x35 CmdStartScanNetworks = 0x36 CmdGetFwVersion = 0x37 CmdSendDataUDP = 0x39 CmdGetRemoteData = 0x3A CmdGetTime = 0x3B CmdGetIdxBSSID = 0x3C CmdGetIdxChannel = 0x3D CmdPing = 0x3E CmdGetSocket = 0x3F // All command with DATA_FLAG 0x40 send a 16bit Len CmdSendDataTCP = 0x44 CmdGetDatabufTCP = 0x45 CmdInsertDataBuf = 0x46 // regular format commands CmdSetPinMode = 0x50 CmdSetDigitalWrite = 0x51 CmdSetAnalogWrite = 0x52 ErrTimeoutChipReady Error = 0x01 ErrTimeoutChipSelect Error = 0x02 ErrCheckStartCmd Error = 0x03 ErrWaitRsp Error = 0x04 ErrUnexpectedLength Error = 0xE0 ErrNoParamsReturned Error = 0xE1 ErrIncorrectSentinel Error = 0xE2 ErrIncorrectReply Error = 0xE3 ErrCmdErrorReceived Error = 0xEF ErrNotImplemented Error = 0xF0 ErrUnknownHost Error = 0xF1 ErrSocketAlreadySet Error = 0xF2 ErrConnectionTimeout Error = 0xF3 ErrNoData Error = 0xF4 ErrDataNotWritten Error = 0xF5 ErrCheckDataError Error = 0xF6 ErrBufferTooSmall Error = 0xF7 ErrNoSocketAvail Error = 0xFF NoSocketAvail uint8 = 0xFF )
const ( ProtoModeTCP = iota ProtoModeUDP ProtoModeTLS ProtoModeMul )
const (
ReadBufferSize = 128
)
Variables ¶
var ErrBufferFull = errors.New("buffer is full")
Functions ¶
Types ¶
type Buffer ¶ added in v0.15.3
type Buffer struct {
// contains filtered or unexported fields
}
Buffer wraps a byte slice that is allocated for creating and/or parsing wifinina command/reply messages (which have the same format as each other). It is NOT safe for concurrent use.
Cmd Struct Message ._______________________________________________________________________. | START CMD | C/R . CMD | N.PARAM | PARAM LEN | PARAM | .. | END CMD | |___________|_____________|_________|___________|________|____|_________| | 8 bit | 1bit . 7bit | 8bit | 8/16* bit | nbytes | .. | 8bit | |___________|_____________|_________|___________|________|____|_________| for most commands, the param len is 1 bytes; for data commands, it is 2
func NewBuffer ¶ added in v0.15.3
NewBuffer constructs a Buffer with the provided capacity. Enough memory to satisfy that capacity is allocated when the Buffer is constructed so that using the Buffer does not result in further allocation or garbage collection.
func (*Buffer) AddData ¶ added in v0.15.3
AddData appends a byte slice as a data parameter to the Buffer.
func (*Buffer) AddString ¶ added in v0.15.3
AddString appends a string parameter to the Buffer. The string should not be more than 256 bytes.
func (*Buffer) Command ¶ added in v0.15.3
Command returns the command byte that is set in the buffer
func (*Buffer) EndCmd ¶ added in v0.15.3
func (b *Buffer) EndCmd()
EndCmd denotes that the last param has been added to buffer; this will append the CmdEnd byte and adds necessary padding
func (*Buffer) GetBufferParam ¶ added in v0.15.3
func (*Buffer) GetStringParam ¶ added in v0.15.3
func (*Buffer) GetUint16Param ¶ added in v0.15.3
func (*Buffer) GetUint32Param ¶ added in v0.15.3
func (*Buffer) GetUint64Param ¶ added in v0.15.3
func (*Buffer) IsDataCommand ¶ added in v0.15.3
IsDataCommand checks if this is a data command that takes buffers as params
func (*Buffer) NumParams ¶ added in v0.15.3
NumParams returns the number of parameters that have been set on the command
func (*Buffer) ParamLenSize ¶ added in v0.15.3
ParamLenSize returns the number of bytes used in a wifinina message to send the length of a parameter. For most commands, 1; for data commands, can be 2
func (*Buffer) ReadReply ¶ added in v0.15.3
func (b *Buffer) ReadReply(r ByteTransferer, checkCmd byte) (err error)
ParseReply switches the buffer from being a request buffer to a reply buffer and attempts to parse the entire reply from the given byte source. If the checkCmd argument is a non-zero value, it will be compared to the command byte in the reply and if they do not match ErrIncorrectReply is returned.
type ByteTransferer ¶ added in v0.15.3
type ConnectionStatus ¶
type ConnectionStatus uint8
func (ConnectionStatus) String ¶
func (c ConnectionStatus) String() string
type Device ¶
type Device struct { Transport Transport // contains filtered or unexported fields }
func (*Device) AnalogWrite ¶ added in v0.15.3
AnalogWrite can be used to set the PWM of a GPIO pin on the device; please note that this command does not exist in the Arduino version of nina-fw, it is specific to the Adafruit fork used for their "Airlift" branded boards.
func (*Device) AvailableData ¶ added in v0.15.3
func (*Device) DigitalWrite ¶ added in v0.15.3
DigitalWrite can be used to set the state of a GPIO pin on the device; please note that this command does not exist in the Arduino version of nina-fw, it is specific to the Adafruit fork used for their "Airlift" branded boards.
func (*Device) Disconnect ¶
func (*Device) GetConnectionStatus ¶
func (d *Device) GetConnectionStatus() (ConnectionStatus, error)
func (*Device) GetCurrentBSSID ¶
func (d *Device) GetCurrentBSSID() (MACAddress, error)
func (*Device) GetCurrentEncryptionType ¶
func (d *Device) GetCurrentEncryptionType() (EncryptionType, error)
func (*Device) GetCurrentRSSI ¶
func (*Device) GetCurrentSSID ¶
func (*Device) GetFwVersion ¶
func (*Device) GetMACAddress ¶
func (d *Device) GetMACAddress() (MACAddress, error)
func (*Device) GetNetworkBSSID ¶
func (d *Device) GetNetworkBSSID(idx int) (MACAddress, error)
func (*Device) GetNetworkEncrType ¶
func (d *Device) GetNetworkEncrType(idx int) (EncryptionType, error)
func (*Device) GetNetworkSSID ¶
func (*Device) GetReasonCode ¶
func (*Device) GetTemperature ¶
func (*Device) InsertDataBuf ¶ added in v0.14.1
InsertDataBuf adds data to the buffer used for sending UDP data
func (*Device) NewDriver ¶
func (d *Device) NewDriver() net.DeviceDriver
func (*Device) PinMode ¶ added in v0.15.3
PinMode can be used to set the mode of a GPIO pin on the device; please note that this command does not exist in the Arduino version of nina-fw, it is specific to the Adafruit fork used for their "Airlift" branded boards.
func (*Device) ScanNetworks ¶
func (*Device) SendUDPData ¶ added in v0.14.1
SendUDPData sends the data previously added to the UDP buffer
func (*Device) SetHostname ¶
func (*Device) SetNetwork ¶
func (*Device) SetNetworkForAP ¶
func (*Device) SetPassphraseForAP ¶
func (*Device) SetPowerMode ¶
func (*Device) StartClient ¶
func (*Device) StartScanNetworks ¶
func (*Device) StartServer ¶ added in v0.14.1
func (*Device) StopClient ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
func (*Driver) ConnectSSLSocket ¶
func (*Driver) ConnectTCPSocket ¶
func (*Driver) ConnectUDPSocket ¶
func (*Driver) DisconnectSocket ¶
func (*Driver) IsConnected ¶
func (*Driver) IsSocketDataAvailable ¶
IsSocketDataAvailable returns of there is socket data available
func (*Driver) StartSocketSend ¶
type EncryptionType ¶
type EncryptionType uint8
func (EncryptionType) String ¶
func (e EncryptionType) String() string
type MACAddress ¶
type MACAddress uint64
func (MACAddress) String ¶
func (addr MACAddress) String() string