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.1"

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

  1. PL::IpV4Address and PL::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.

  2. PL::NetworkInterface - a base class for any network interface.

  3. PL::Ethernet - a base class for any ethernet interface.

  4. PL::WiFiStation - a base class for any Wi-Fi station.

  5. PL::EspNetworkInterface - is a base class for the internal ESP Ethernet and WiFi station. It implements several PL::NetworkInterface methods using ESP C api for the IP and DHCP configuration.

  6. PL::EspEthernet - is a PL::Ethernet implementation for the internal ESP Ethernet. It is initialized with the specific esp_eth_phy_new_xxx function for the PHY chip that is used. PL::EspEthernet::Initialize() installs the Ethernet driver. PL::EspEthernet::Enable() and PL::EspEthernet::Disable() enable and disable the interface. PL::EspEthernet::IsConnected() checks the connection status.

  7. PL::EspWiFiStation - is a PL::WiFiStation implementation for the internal ESP Wi-Fi station. PL::EspWiFiStation::Initialize() installs the Wi-Fi driver. PL::EspWiFiStation::Enable() and PL::EspWiFiStation::Disable() enable and disable the interface. PL::EspWiFiStation::IsConnected() check the connection status. PL::EspWiFiStation::GetSsid(), PL::EspWiFiStation::SetSsid(), PL::EspWiFiStation::GetPassword() and PL::EspWiFiStation::SetPassword() get and set Wi-Fi station SSID and password.

  8. PL::NetworkStream - a base class for any network stream. In addition to PL::Stream methods it provides Nagle algorithm enabling/disabling, keep-alive packet configuration and getting local/remote endpoint information.

  9. PL::NetworkServer - a base class for any network server. In addition to PL::Server methods it provides port and maximum number of clients configuration.

  10. PL::TcpClient - a TCP client class. It is initialized with an IP address and a port, that can be changed later. PL::TcpClient::Connect() and PL::TcpClient::Disonnect() connect/disconenct the client from the server. PL::TcpClient::GetStream() returns a lockable PL::NetworkStream for reading and writing.

  11. PL::TcpServer - a PL::NetworkServer implementation for TCP connections. The descendant class should override PL::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