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
NetworkInterface
NetworkInterface::NetworkInterface()
NetworkInterface::EnableIpV4DhcpClient()
NetworkInterface::DisableIpV4DhcpClient()
NetworkInterface::EnableIpV6DhcpClient()
NetworkInterface::DisableIpV6DhcpClient()
NetworkInterface::IsConnected()
NetworkInterface::IsIpV4DhcpClientEnabled()
NetworkInterface::IsIpV6DhcpClientEnabled()
NetworkInterface::GetIpV4Address()
NetworkInterface::SetIpV4Address()
NetworkInterface::GetIpV4Netmask()
NetworkInterface::SetIpV4Netmask()
NetworkInterface::GetIpV4Gateway()
NetworkInterface::SetIpV4Gateway()
NetworkInterface::GetIpV6LinkLocalAddress()
NetworkInterface::GetIpV6GlobalAddress()
NetworkInterface::SetIpV6GlobalAddress()
NetworkInterface::Initialize()
NetworkInterface::Enable()
NetworkInterface::Disable()
NetworkInterface::IsEnabled()
NetworkInterface::GetName()
NetworkInterface::SetName()
NetworkInterface::Lock()
NetworkInterface::Unlock()
NetworkInterface::connectedEvent
NetworkInterface::disconnectedEvent
NetworkInterface::gotIpV4AddressEvent
NetworkInterface::lostIpV4AddressEvent
NetworkInterface::gotIpV6AddressEvent
NetworkInterface::lostIpV6AddressEvent
NetworkInterface::enabledEvent
NetworkInterface::disabledEvent
- PL::Ethernet class
Ethernet
Ethernet::Ethernet()
Ethernet::EnableIpV4DhcpClient()
Ethernet::DisableIpV4DhcpClient()
Ethernet::EnableIpV6DhcpClient()
Ethernet::DisableIpV6DhcpClient()
Ethernet::IsConnected()
Ethernet::IsIpV4DhcpClientEnabled()
Ethernet::IsIpV6DhcpClientEnabled()
Ethernet::GetIpV4Address()
Ethernet::SetIpV4Address()
Ethernet::GetIpV4Netmask()
Ethernet::SetIpV4Netmask()
Ethernet::GetIpV4Gateway()
Ethernet::SetIpV4Gateway()
Ethernet::GetIpV6LinkLocalAddress()
Ethernet::GetIpV6GlobalAddress()
Ethernet::SetIpV6GlobalAddress()
Ethernet::Initialize()
Ethernet::Enable()
Ethernet::Disable()
Ethernet::IsEnabled()
Ethernet::GetName()
Ethernet::SetName()
Ethernet::Lock()
Ethernet::Unlock()
Ethernet::connectedEvent
Ethernet::disconnectedEvent
Ethernet::gotIpV4AddressEvent
Ethernet::lostIpV4AddressEvent
Ethernet::gotIpV6AddressEvent
Ethernet::lostIpV6AddressEvent
Ethernet::enabledEvent
Ethernet::disabledEvent
- PL::WiFiStation class
WiFiStation
WiFiStation::WiFiStation()
WiFiStation::GetSsid()
WiFiStation::SetSsid()
WiFiStation::GetPassword()
WiFiStation::SetPassword()
WiFiStation::EnableIpV4DhcpClient()
WiFiStation::DisableIpV4DhcpClient()
WiFiStation::EnableIpV6DhcpClient()
WiFiStation::DisableIpV6DhcpClient()
WiFiStation::IsConnected()
WiFiStation::IsIpV4DhcpClientEnabled()
WiFiStation::IsIpV6DhcpClientEnabled()
WiFiStation::GetIpV4Address()
WiFiStation::SetIpV4Address()
WiFiStation::GetIpV4Netmask()
WiFiStation::SetIpV4Netmask()
WiFiStation::GetIpV4Gateway()
WiFiStation::SetIpV4Gateway()
WiFiStation::GetIpV6LinkLocalAddress()
WiFiStation::GetIpV6GlobalAddress()
WiFiStation::SetIpV6GlobalAddress()
WiFiStation::Initialize()
WiFiStation::Enable()
WiFiStation::Disable()
WiFiStation::IsEnabled()
WiFiStation::GetName()
WiFiStation::SetName()
WiFiStation::Lock()
WiFiStation::Unlock()
WiFiStation::connectedEvent
WiFiStation::disconnectedEvent
WiFiStation::gotIpV4AddressEvent
WiFiStation::lostIpV4AddressEvent
WiFiStation::gotIpV6AddressEvent
WiFiStation::lostIpV6AddressEvent
WiFiStation::enabledEvent
WiFiStation::disabledEvent
- PL::EspNetworkInterface class
EspNetworkInterface
EspNetworkInterface::EnableIpV4DhcpClient()
EspNetworkInterface::DisableIpV4DhcpClient()
EspNetworkInterface::EnableIpV6DhcpClient()
EspNetworkInterface::DisableIpV6DhcpClient()
EspNetworkInterface::IsIpV4DhcpClientEnabled()
EspNetworkInterface::IsIpV6DhcpClientEnabled()
EspNetworkInterface::GetIpV4Address()
EspNetworkInterface::SetIpV4Address()
EspNetworkInterface::GetIpV4Netmask()
EspNetworkInterface::SetIpV4Netmask()
EspNetworkInterface::GetIpV4Gateway()
EspNetworkInterface::SetIpV4Gateway()
EspNetworkInterface::GetIpV6LinkLocalAddress()
EspNetworkInterface::GetIpV6GlobalAddress()
EspNetworkInterface::SetIpV6GlobalAddress()
EspNetworkInterface::IsConnected()
EspNetworkInterface::Initialize()
EspNetworkInterface::Enable()
EspNetworkInterface::Disable()
EspNetworkInterface::IsEnabled()
EspNetworkInterface::GetName()
EspNetworkInterface::SetName()
EspNetworkInterface::Lock()
EspNetworkInterface::Unlock()
EspNetworkInterface::connectedEvent
EspNetworkInterface::disconnectedEvent
EspNetworkInterface::gotIpV4AddressEvent
EspNetworkInterface::lostIpV4AddressEvent
EspNetworkInterface::gotIpV6AddressEvent
EspNetworkInterface::lostIpV6AddressEvent
EspNetworkInterface::enabledEvent
EspNetworkInterface::disabledEvent
EspNetworkInterface::EspNetworkInterface()
EspNetworkInterface::InitializeNetif()
- PL::EspEthernet class
- PL::EspWiFiStation class
EspWiFiStation
EspWiFiStation::EspWiFiStation()
EspWiFiStation::Lock()
EspWiFiStation::Unlock()
EspWiFiStation::Initialize()
EspWiFiStation::Enable()
EspWiFiStation::Disable()
EspWiFiStation::IsEnabled()
EspWiFiStation::IsConnected()
EspWiFiStation::GetSsid()
EspWiFiStation::SetSsid()
EspWiFiStation::GetPassword()
EspWiFiStation::SetPassword()
EspWiFiStation::EnableIpV4DhcpClient()
EspWiFiStation::DisableIpV4DhcpClient()
EspWiFiStation::EnableIpV6DhcpClient()
EspWiFiStation::DisableIpV6DhcpClient()
EspWiFiStation::IsIpV4DhcpClientEnabled()
EspWiFiStation::IsIpV6DhcpClientEnabled()
EspWiFiStation::GetIpV4Address()
EspWiFiStation::SetIpV4Address()
EspWiFiStation::GetIpV4Netmask()
EspWiFiStation::SetIpV4Netmask()
EspWiFiStation::GetIpV4Gateway()
EspWiFiStation::SetIpV4Gateway()
EspWiFiStation::GetIpV6LinkLocalAddress()
EspWiFiStation::GetIpV6GlobalAddress()
EspWiFiStation::SetIpV6GlobalAddress()
EspWiFiStation::GetName()
EspWiFiStation::SetName()
EspWiFiStation::connectedEvent
EspWiFiStation::disconnectedEvent
EspWiFiStation::gotIpV4AddressEvent
EspWiFiStation::lostIpV4AddressEvent
EspWiFiStation::gotIpV6AddressEvent
EspWiFiStation::lostIpV6AddressEvent
EspWiFiStation::enabledEvent
EspWiFiStation::disabledEvent
EspWiFiStation::defaultName
EspWiFiStation::InitializeNetif()
- PL::NetworkStream class
NetworkStream
NetworkStream::NetworkStream()
NetworkStream::NetworkStream()
NetworkStream::Lock()
NetworkStream::Unlock()
NetworkStream::Read()
NetworkStream::Write()
NetworkStream::Close()
NetworkStream::EnableNagleAlgorithm()
NetworkStream::DisableNagleAlgorithm()
NetworkStream::EnableKeepAlive()
NetworkStream::DisableKeepAlive()
NetworkStream::IsOpen()
NetworkStream::GetReadableSize()
NetworkStream::GetReadTimeout()
NetworkStream::SetReadTimeout()
NetworkStream::GetLocalEndpoint()
NetworkStream::GetRemoteEndpoint()
NetworkStream::SetKeepAliveIdleTime()
NetworkStream::SetKeepAliveInterval()
NetworkStream::SetKeepAliveCount()
NetworkStream::Read()
NetworkStream::Write()
NetworkStream::Write()
NetworkStream::ReadUntil()
NetworkStream::ReadUntil()
NetworkStream::ReadUntil()
NetworkStream::FlushReadBuffer()
NetworkStream::defaultReadTimeout
- PL::NetworkServer class
NetworkServer
NetworkServer::NetworkServer()
NetworkServer::GetPort()
NetworkServer::SetPort()
NetworkServer::GetMaxNumberOfClients()
NetworkServer::SetMaxNumberOfClients()
NetworkServer::Enable()
NetworkServer::Disable()
NetworkServer::IsEnabled()
NetworkServer::GetName()
NetworkServer::SetName()
NetworkServer::Lock()
NetworkServer::Unlock()
NetworkServer::enabledEvent
NetworkServer::disabledEvent
- PL::TcpClient class
TcpClient
TcpClient::TcpClient()
TcpClient::TcpClient()
TcpClient::Lock()
TcpClient::Unlock()
TcpClient::Connect()
TcpClient::Disconnect()
TcpClient::EnableNagleAlgorithm()
TcpClient::DisableNagleAlgorithm()
TcpClient::IsConnected()
TcpClient::GetReadTimeout()
TcpClient::SetReadTimeout()
TcpClient::GetLocalEndpoint()
TcpClient::GetRemoteEndpoint()
TcpClient::SetRemoteEndpoint()
TcpClient::SetRemoteEndpoint()
TcpClient::GetStream()
- PL::TcpServer class
TcpServer
TcpServer::TcpServer()
TcpServer::Lock()
TcpServer::Unlock()
TcpServer::Enable()
TcpServer::Disable()
TcpServer::EnableNagleAlgorithm()
TcpServer::DisableNagleAlgorithm()
TcpServer::EnableKeepAlive()
TcpServer::DisableKeepAlive()
TcpServer::IsEnabled()
TcpServer::GetPort()
TcpServer::SetPort()
TcpServer::GetMaxNumberOfClients()
TcpServer::SetMaxNumberOfClients()
TcpServer::GetClientStreams()
TcpServer::SetTaskParameters()
TcpServer::SetKeepAliveIdleTime()
TcpServer::SetKeepAliveInterval()
TcpServer::SetKeepAliveCount()
TcpServer::GetName()
TcpServer::SetName()
TcpServer::clientConnectedEvent
TcpServer::clientDisconnectedEvent
TcpServer::enabledEvent
TcpServer::disabledEvent
TcpServer::defaultTaskParameters
TcpServer::defaultMaxNumberOfClients
TcpServer::defaultKeepAliveIdleTime
TcpServer::defaultKeepAliveInterval
TcpServer::defaultKeepAliveCount
TcpServer::HandleRequest()