munet Network Library for muwerk Scheduler
A muwerk network library supporting WiFi, NTP, OTA and MQTT for ESP8266 and ESP32 and serial links for all platforms
|
munet, the muwerk network class for WiFi and NTP More...
#include <net.h>
Public Member Functions | |
Net (uint8_t signalLed=0xff, bool signalLogic=false) | |
void | begin (Scheduler *pScheduler, Netmode opmode=AP, bool restartOnMultipleFailures=true) |
void | begin (Scheduler *pScheduler, String SSID, String password="", String hostname="muwerk-${macls}", Netmode opmode=AP, bool restartOnMultipleFailures=true) |
munet, the muwerk network class for WiFi and NTP
The library header-only and relies on the libraries ustd, muwerk, Arduino_JSON and PubSubClient.
Make sure to provide the required platform define before including ustd headers.
See README.md for a detailed description of all network configuration options.
Alternatively, operating mode and credentials can be given in source code during Net.begin(). (s.b.)
|
inline |
Instantiate a network object for WiFi and NTP connectivity.
The Net object publishes messages using muwerk's pub/sub intertask communication (which does not rely on MQTT servers), other muwerk tasks can subscribe to the following topics:
net/network
: for information about WiFi connection state changes. Status can be actively requested by publishing net/network/get
net/rssi
: for information about WiFi signal strengthnet/connections
: for changes in the number of connected clients when operating as access pointnet/networks
: for a list of WiFi networks nearby. The list can be requested by publishing net/networks/get
signalLed | (optional), Pin that will be set to LOW (led on) during network connection attempts. Once connected, led is switched off and can be used for other functions. Led on signals that the ESP is trying to connect to a network. |
signalLogic | (optional, default false ) If true the signal logic for the led is inverted. |
|
inline |
Starts the network based on the stored configuration.
This method starts the network using the information stored into the configuration file /net.json. Depending on how the network mode is configured, it may be idle (since disabled), running as an access point or as a station or both.
Other muwerk task can subscribe to topic 'net/network
' to receive information about network connection states.
pScheduler | Pointer to the muwerk scheduler. |
opmode | (optional, default AP) Default operation mode if none is configured |
restartOnMultipleFailures | (optional, default true ) Default restart on continued failure if none is configured. |
See README.md for a detailed description of all network configuration options.
|
inline |
Starts the network based on the supplied configuration.
This function starts the network using the supplied information and is intended for projects with hardcoded network configuration. This method allows only to configure the network running as an access point or as a station.
Other muwerk task can subscribe to topic 'net/network
' to receive information about network connection states.
pScheduler | Pointer to the muwerk scheduler. |
SSID | The SSID for the WiFi connection or access point. This can contin placeholder (see below). |
password | (optional, default unused) The password for the WiFi connection or access point |
hostname | (optional, default "muwerk-${macls}" ) The hostname of the system. This can contain placeholder (see below). |
opmode | (optional, default AP) The operating mode of the network. Can be AP or STATION |
restartOnMultipleFailures | (optional, default true ) restarts the device on continued failure. |
In STATION mode the network connects to an available WiFi network using the supplied credentials. After connecting, the system requests a network configuration via DHCP. After receiving the configuration, the IP address, netmask and gateway are set. If the DHCP server sends information about a valid NTP server, the time is synchronized using the information from that server.
Some of the configuration options support the use of placeholders in order to allow values that are specific to a certain device without the need to create separate configuration files. Placeholders are written in the form of ${PLACEHOLDER}
.
The following placeholders are currently available:
mac
: full mac addressmacls
: last 4 digits of mac addressmacfs
: first 4 digits of mac address