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 | Public Attributes | List of all members
ustd::MuSerial Class Reference

munet MuSerial Class More...

#include <muserial.h>

Public Member Functions

 MuSerial (String name, HardwareSerial *pSerial, unsigned long baudRate=115200, uint8_t connectionLed=-1)
 
void begin (Scheduler *_pSched)
 
bool outgoingBlockSet (String topic)
 
bool outgoingBlockRemove (String topic)
 
bool incomingBlockSet (String topic)
 
bool incomingBlockRemove (String topic)
 

Public Attributes

bool activeLogic = false
 
unsigned long connectionLedBlinkDurationMs
 milli-secs the connectionLed is flashed on receiving a ping.
 

Detailed Description

munet MuSerial Class

The MuSerial class connects two muwerk MCUs via a serial connection. The serial connection automatically fowards all pub/sub messages (that are not blocked by exception lists) between the two nodes.

A main application could be to connect a non-networked MCU to a networked MCU to allow forwarding and receiving MQTT messages on MCUs without network connection via a serial link.

A system of two muwerk MCUs connected via MuSerial act to the outside world as if they were one system. Hardware (mupplets) can be addressed the same way, regardless if they are on node1 or node2.

Sample MuSerial node (without network acces)

#define __ESP__ 1 // Platform defines required, see doc, mainpage.
#include "scheduler.h"
#include "muserial.h"
ustd::Scheduler sched;
ustd::MuSerial serlink("serlink", &Serial2, 115200, LED_BUILTIN);
void setup() {
muserial.begin(&sched);
}
munet MuSerial Class
Definition: muserial.h:76

Sample MuSerial node (with network access)

#include "scheduler.h"
#include "muserial.h"
#include "net.h"
#include "mqtt.h"
#include "ota.h"
ustd::Scheduler sched(10, 16, 32);
ustd::MuSerial muser("esp32", &Serial1, 115200, LED_BUILTIN);
ustd::Net net(LED_BUILTIN);
void setup() {
muser.begin(&sched);
net.begin(&sched);
mqtt.begin(&sched);
ota.begin(&sched);
}
munet MQTT Gateway Class
Definition: mqtt.h:79
void begin(Scheduler *_pSched, String _mqttServer="", uint16_t _mqttServerPort=1883, bool _mqttRetained=false, String _clientName="${hostname}", String _domainToken="mu", String _outDomainToken="omu", String _mqttUsername="", String _mqttPassword="", String _willTopic="", String _willMessage="")
Definition: mqtt.h:134
munet, the muwerk network class for WiFi and NTP
Definition: net.h:72
munet OTA Class
Definition: ota.h:57
void begin(Scheduler *_pSched)
Definition: ota.h:76

For a complete example, see: muwerk SerialBridge example

Constructor & Destructor Documentation

◆ MuSerial()

ustd::MuSerial::MuSerial ( String  name,
HardwareSerial *  pSerial,
unsigned long  baudRate = 115200,
uint8_t  connectionLed = -1 
)
inline

Instantiate a serial link between two muwerk instances.

Parameters
nameName of this node (used in pub/sub protocol, received as 'remoteName' by other system)
pSerialpointer to Serial object
baudRatebaud rate for communication. Must be same as used by other node.
connectionLedoptional gpio pin number of a led (e.g. LED_BUILTIN) that is flashed on receiving a PING from other system.

Member Function Documentation

◆ begin()

void ustd::MuSerial::begin ( Scheduler *  _pSched)
inline

Setup serial link.

Parameters
_pSchedPointer to the muwerk scheduler.

◆ incomingBlockRemove()

bool ustd::MuSerial::incomingBlockRemove ( String  topic)
inline

Unblock a topic-wildcard from being received from external mqtt server

Parameters
topicAn mqtt topic wildcard for topics that should again be forwarded internally to muwerk. Unblock only removes a a block identical to the given topic. So topic must be identical to a topic (wildcard) that has been used with 'incomingBlockSet()'.
Returns
true on success, false if no corresponding block could be found.

◆ incomingBlockSet()

bool ustd::MuSerial::incomingBlockSet ( String  topic)
inline

Block a topic-wildcard from being published to the internal scheduler

Parameters
topicAn mqtt topic wildcard for topics that should not be forwarded from external mqtt server to the muwerk scheduler. This can be used to block any incoming messages according to their topic.
Returns
true on success, false if entry already exists, or couldn't be added.

◆ outgoingBlockRemove()

bool ustd::MuSerial::outgoingBlockRemove ( String  topic)
inline

Unblock a topic-wildcard from being published to external mqtt server

Parameters
topicAn mqtt topic wildcard for topics that should again be forwarded to external mqtt. Unblock only removes a a block identical to the given topic. So topic must be identical to a topic (wildcard) that has been used with 'outgoingBlockSet()'.
Returns
true on success, false if no corresponding block could be found.

◆ outgoingBlockSet()

bool ustd::MuSerial::outgoingBlockSet ( String  topic)
inline

Block a topic-wildcard from being published to external mqtt server

Parameters
topicAn mqtt topic wildcard for topics that should not be forwarded to external mqtt. E.g. 'mymupplet/#' Would block all messages a mupplet with name 'mymupplet' publishes from being forwarded to the extern mqtt server
Returns
true on success, false if entry already exists, or couldn't be added.

Member Data Documentation

◆ activeLogic

bool ustd::MuSerial::activeLogic = false

If a connectionLed is used, this defines if active-high (true) or active-low (false) logic is used.


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