Network Component
Installation
The component requires ESP-IDF 5.3 and higher and is installed using IDF Component Manager.
Add this to the idf_component.yml
in the project main
directory or in the component directory:
dependencies:
plasmapper/pl_network: "^1.1.2"
Add this to the source code:
#include "pl_network.h"
Add extern "C"
to the app_main
function:
extern "C" void app_main(void) {...}
Add this to the sdkconfig.defaults
in the project directory or configure the values using Project Configuration:
CONFIG_COMPILER_CXX_RTTI=y
CONFIG_LWIP_SO_RCVBUF=y
Features
PL::IpV4Address
andPL::IpV6Address
- data types for IPv4 and IPv6 addresses with number and string initialization and ToString methods.PL::NetworkEndpoint
- a data type for an IP address (v4 or v6) and a port.PL::NetworkInterface
- a base class for any network interface.PL::Ethernet
- a base class for any ethernet interface.PL::WiFiStation
- a base class for any Wi-Fi station.PL::EspNetworkInterface
- is a base class for the internal ESP Ethernet and WiFi station. It implements severalPL::NetworkInterface
methods using ESP C api for the IP and DHCP configuration.PL::EspEthernet
- is aPL::Ethernet
implementation for the internal ESP Ethernet. It is initialized with the specificesp_eth_phy_new_xxx
function for the PHY chip that is used.PL::EspEthernet::Initialize()
installs the Ethernet driver.PL::EspEthernet::Enable()
andPL::EspEthernet::Disable()
enable and disable the interface.PL::EspEthernet::IsConnected()
checks the connection status.PL::EspWiFiStation
- is aPL::WiFiStation
implementation for the internal ESP Wi-Fi station.PL::EspWiFiStation::Initialize()
installs the Wi-Fi driver.PL::EspWiFiStation::Enable()
andPL::EspWiFiStation::Disable()
enable and disable the interface.PL::EspWiFiStation::IsConnected()
check the connection status.PL::EspWiFiStation::GetSsid()
,PL::EspWiFiStation::SetSsid()
,PL::EspWiFiStation::GetPassword()
andPL::EspWiFiStation::SetPassword()
get and set Wi-Fi station SSID and password.PL::NetworkStream
- a base class for any network stream. In addition toPL::Stream
methods it provides Nagle algorithm enabling/disabling, keep-alive packet configuration and getting local/remote endpoint information.PL::NetworkServer
- a base class for any network server. In addition toPL::Server
methods it provides port and maximum number of clients configuration.PL::TcpClient
- a TCP client class. It is initialized with an IP address and a port, that can be changed later.PL::TcpClient::Connect()
andPL::TcpClient::Disonnect()
connect/disconenct the client from the server.PL::TcpClient::GetStream()
returns a lockablePL::NetworkStream
for reading and writing.PL::TcpServer
- aPL::NetworkServer
implementation for TCP connections. The descendant class should overridePL::TcpServer::HandleRequest()
to handle the client request.PL::TcpServer::HandleRequest()
is only called for clients with the incoming data in the internal buffer.
Thread safety
Class method thread safety is implemented by having the PL::Lockable
as a base class and creating the class object lock guard at the beginning of the methods.
PL::TcpServer
task method locks both the PL::TcpServer
and the client PL::NetworkStream
objects for the duration of the transaction.
Examples
API reference
- Types
- PL::NetworkInterface class
PL::NetworkInterface
NetworkInterface()
EnableIpV4DhcpClient()
DisableIpV4DhcpClient()
EnableIpV6DhcpClient()
DisableIpV6DhcpClient()
IsConnected()
IsIpV4DhcpClientEnabled()
IsIpV6DhcpClientEnabled()
GetIpV4Address()
SetIpV4Address()
GetIpV4Netmask()
SetIpV4Netmask()
GetIpV4Gateway()
SetIpV4Gateway()
GetIpV6LinkLocalAddress()
GetIpV6GlobalAddress()
SetIpV6GlobalAddress()
Initialize()
Enable()
Disable()
IsEnabled()
GetName()
SetName()
Lock()
Unlock()
connectedEvent
disconnectedEvent
gotIpV4AddressEvent
lostIpV4AddressEvent
gotIpV6AddressEvent
lostIpV6AddressEvent
enabledEvent
disabledEvent
- PL::Ethernet class
PL::Ethernet
Ethernet()
EnableIpV4DhcpClient()
DisableIpV4DhcpClient()
EnableIpV6DhcpClient()
DisableIpV6DhcpClient()
IsConnected()
IsIpV4DhcpClientEnabled()
IsIpV6DhcpClientEnabled()
GetIpV4Address()
SetIpV4Address()
GetIpV4Netmask()
SetIpV4Netmask()
GetIpV4Gateway()
SetIpV4Gateway()
GetIpV6LinkLocalAddress()
GetIpV6GlobalAddress()
SetIpV6GlobalAddress()
Initialize()
Enable()
Disable()
IsEnabled()
GetName()
SetName()
Lock()
Unlock()
connectedEvent
disconnectedEvent
gotIpV4AddressEvent
lostIpV4AddressEvent
gotIpV6AddressEvent
lostIpV6AddressEvent
enabledEvent
disabledEvent
- PL::WiFiStation class
PL::WiFiStation
WiFiStation()
GetSsid()
SetSsid()
GetPassword()
SetPassword()
EnableIpV4DhcpClient()
DisableIpV4DhcpClient()
EnableIpV6DhcpClient()
DisableIpV6DhcpClient()
IsConnected()
IsIpV4DhcpClientEnabled()
IsIpV6DhcpClientEnabled()
GetIpV4Address()
SetIpV4Address()
GetIpV4Netmask()
SetIpV4Netmask()
GetIpV4Gateway()
SetIpV4Gateway()
GetIpV6LinkLocalAddress()
GetIpV6GlobalAddress()
SetIpV6GlobalAddress()
Initialize()
Enable()
Disable()
IsEnabled()
GetName()
SetName()
Lock()
Unlock()
connectedEvent
disconnectedEvent
gotIpV4AddressEvent
lostIpV4AddressEvent
gotIpV6AddressEvent
lostIpV6AddressEvent
enabledEvent
disabledEvent
- PL::EspNetworkInterface class
PL::EspNetworkInterface
EnableIpV4DhcpClient()
DisableIpV4DhcpClient()
EnableIpV6DhcpClient()
DisableIpV6DhcpClient()
IsIpV4DhcpClientEnabled()
IsIpV6DhcpClientEnabled()
GetIpV4Address()
SetIpV4Address()
GetIpV4Netmask()
SetIpV4Netmask()
GetIpV4Gateway()
SetIpV4Gateway()
GetIpV6LinkLocalAddress()
GetIpV6GlobalAddress()
SetIpV6GlobalAddress()
IsConnected()
Initialize()
Enable()
Disable()
IsEnabled()
GetName()
SetName()
Lock()
Unlock()
connectedEvent
disconnectedEvent
gotIpV4AddressEvent
lostIpV4AddressEvent
gotIpV6AddressEvent
lostIpV6AddressEvent
enabledEvent
disabledEvent
EspNetworkInterface()
InitializeNetif()
- PL::EspEthernet class
- PL::EspWiFiStation class
PL::EspWiFiStation
EspWiFiStation()
Lock()
Unlock()
Initialize()
Enable()
Disable()
IsEnabled()
IsConnected()
GetSsid()
SetSsid()
GetPassword()
SetPassword()
EnableIpV4DhcpClient()
DisableIpV4DhcpClient()
EnableIpV6DhcpClient()
DisableIpV6DhcpClient()
IsIpV4DhcpClientEnabled()
IsIpV6DhcpClientEnabled()
GetIpV4Address()
SetIpV4Address()
GetIpV4Netmask()
SetIpV4Netmask()
GetIpV4Gateway()
SetIpV4Gateway()
GetIpV6LinkLocalAddress()
GetIpV6GlobalAddress()
SetIpV6GlobalAddress()
GetName()
SetName()
connectedEvent
disconnectedEvent
gotIpV4AddressEvent
lostIpV4AddressEvent
gotIpV6AddressEvent
lostIpV6AddressEvent
enabledEvent
disabledEvent
defaultName
InitializeNetif()
- PL::NetworkStream class
PL::NetworkStream
NetworkStream()
NetworkStream()
Lock()
Unlock()
Read()
Write()
Close()
EnableNagleAlgorithm()
DisableNagleAlgorithm()
EnableKeepAlive()
DisableKeepAlive()
IsOpen()
GetReadableSize()
GetReadTimeout()
SetReadTimeout()
GetLocalEndpoint()
GetRemoteEndpoint()
SetKeepAliveIdleTime()
SetKeepAliveInterval()
SetKeepAliveCount()
Read()
Write()
Write()
ReadUntil()
ReadUntil()
ReadUntil()
FlushReadBuffer()
defaultReadTimeout
- PL::NetworkServer class
- PL::TcpClient class
- PL::TcpServer class
PL::TcpServer
TcpServer()
Lock()
Unlock()
Enable()
Disable()
EnableNagleAlgorithm()
DisableNagleAlgorithm()
EnableKeepAlive()
DisableKeepAlive()
IsEnabled()
GetPort()
SetPort()
GetMaxNumberOfClients()
SetMaxNumberOfClients()
GetClientStreams()
SetTaskParameters()
SetKeepAliveIdleTime()
SetKeepAliveInterval()
SetKeepAliveCount()
GetName()
SetName()
clientConnectedEvent
clientDisconnectedEvent
enabledEvent
disabledEvent
defaultTaskParameters
defaultMaxNumberOfClients
defaultKeepAliveIdleTime
defaultKeepAliveInterval
defaultKeepAliveCount
HandleRequest()