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
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ustd::Net Class Reference

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)
 

Detailed Description

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.)

Sample network connection

#define __ESP__ 1 // Platform defines required, see doc, mainpage.
#include "scheduler.h"
#include "net.h"
#include "ota.h" // optional for over-the-air software updates
#include "mqtt.h" // optional for connection to external MQTT server
ustd::Scheduler sched;
ustd::Net net(LED_BUILTIN);
ustd::Ota ota(); // optional
ustd::Mqtt mqtt();// optional
void appLoop();
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
net.begin(&sched); // connect to WLAN and sync NTP time,
// credentials read from LittleFS, (net.json)
ota.begin(&sched); // optional ota update
mqtt.begin(&sched); // optional connection to external MQTT server
int tID = sched.add(appLoop, "main"); // create task for your app code
}
void appLoop() {
// your code goes here.
}
// Never add code to this loop, use appLoop() instead.
void loop() {
sched.loop();
}
munet MQTT Gateway Class
Definition: mqtt.h:79
munet, the muwerk network class for WiFi and NTP
Definition: net.h:72
munet OTA Class
Definition: ota.h:57

Constructor & Destructor Documentation

◆ Net()

ustd::Net::Net ( uint8_t  signalLed = 0xff,
bool  signalLogic = false 
)
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 strength
  • net/connections: for changes in the number of connected clients when operating as access point
  • net/networks: for a list of WiFi networks nearby. The list can be requested by publishing net/networks/get
Parameters
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.

Member Function Documentation

◆ begin() [1/2]

void ustd::Net::begin ( Scheduler *  pScheduler,
Netmode  opmode = AP,
bool  restartOnMultipleFailures = true 
)
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.

Parameters
pSchedulerPointer 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.

◆ begin() [2/2]

void ustd::Net::begin ( Scheduler *  pScheduler,
String  SSID,
String  password = "",
String  hostname = "muwerk-${macls}",
Netmode  opmode = AP,
bool  restartOnMultipleFailures = true 
)
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.

Parameters
pSchedulerPointer to the muwerk scheduler.
SSIDThe 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 address
  • macls: last 4 digits of mac address
  • macfs: first 4 digits of mac address

The documentation for this class was generated from the following file: