|
SPSP
Simple publish-subscribe protocol. Connects low power IoT clients to MQTT.
|
ESP-NOW local layer. More...
#include <espnow.hpp>


Classes | |
| struct | BridgeConnInfoInternal |
| Internal bridge connection info. More... | |
Public Types | |
| using | LocalAddrT = SPSP::LocalLayers::ESPNOW::LocalAddrT |
| using | LocalMessageT = SPSP::LocalLayers::ESPNOW::LocalMessageT |
Public Types inherited from SPSP::ILocalLayer< LocalMessageT > | |
| using | LocalAddrT = typename LocalMessageT ::LocalAddrT |
| using | LocalMessageT = LocalMessageT |
Public Member Functions | |
| ESPNOW (IAdapter &adapter, WiFi::IESPNOW &wifi, const Config &conf) | |
| Constructs a new ESP-NOW layer object. More... | |
| ~ESPNOW () | |
| Destroys ESP-NOW layer object. More... | |
| bool | send (const LocalMessageT &msg) |
| Sends the message to given node. More... | |
| bool | connectToBridge (BridgeConnInfoRTC *rtndBr=nullptr, BridgeConnInfoRTC *connBr=nullptr) |
| Connects to the bridge. More... | |
Public Member Functions inherited from SPSP::ILocalLayer< LocalMessageT > | |
| void | setNode (void *n) |
| Sets pointer to the owner node. More... | |
| ILocalNode< ILocalLayer > * | getNode () const |
| Gets the node object. More... | |
| bool | nodeConnected () const |
| Checks whether the owner node is connected. More... | |
| virtual bool | send (const LocalMessageT &msg)=0 |
| Sends the message to given node. More... | |
Protected Member Functions | |
| void | receive (const LocalMessageT &msg, int rssi) |
| Receive message handler. More... | |
| void | sendRaw (const LocalAddrT &dst, const std::string &data) |
| Sends raw packet to the underlaying library. More... | |
| void | recvCb (const LocalAddrT src, std::string data, int rssi) |
| Receive callback for underlaying ESP-NOW adapter. More... | |
| void | sendCb (const LocalAddrT dst, bool delivered) |
| Send callback for underlaying ESP-NOW adapter. More... | |
| uint8_t | getBucketIdFromLocalAddr (const LocalAddrT &addr) const |
Calculates bucket id from LocalAddrT object. More... | |
Protected Attributes | |
| std::mutex | m_mutex |
| Mutex to prevent race conditions. | |
| const Config | m_conf |
| Configuration. | |
| WiFi::IESPNOW & | m_wifi |
| WiFi instance. | |
| IAdapter & | m_adapter |
| Low level ESP-NOW adapter. | |
| SerDes | m_serdes |
| Packet serializer/deserializer. | |
| BridgeConnInfoInternal | m_bestBridge = {} |
| Bridge with best signal. | |
| std::mutex | m_bestBridgeMutex |
| Mutex for modifying m_bestBridge* attributes. | |
| std::array< std::promise< bool >, MAX_PEER_NUM > | m_sendingPromises |
| Container for promises of being-sent messages. More... | |
| std::array< std::mutex, MAX_PEER_NUM > | m_sendingMutexes |
| Container for mutex of being-sent messages. More... | |
ESP-NOW local layer.
Definition at line 54 of file espnow.hpp.
| SPSP::LocalLayers::ESPNOW::ESPNOW::ESPNOW | ( | IAdapter & | adapter, |
| WiFi::IESPNOW & | wifi, | ||
| const Config & | conf | ||
| ) |
Constructs a new ESP-NOW layer object.
Requires already initialized WiFi.
| adapter | ESP-NOW low-level adapter |
| wifi | WiFi instance |
| conf | Configuration |
| SPSP::LocalLayers::ESPNOW::ESPNOW::~ESPNOW | ( | ) |
Destroys ESP-NOW layer object.
| bool SPSP::LocalLayers::ESPNOW::ESPNOW::connectToBridge | ( | BridgeConnInfoRTC * | rtndBr = nullptr, |
| BridgeConnInfoRTC * | connBr = nullptr |
||
| ) |
Connects to the bridge.
If rtndBr is not nullptr, uses it's address, returns true immediately, does no scan whatsoever and connBr = rtndBr. Otherwise probes all wireless channels (available in the currently configured country) and selects bridge with the best signal.
You can use retainedBridge and connectedBridge parameters to implement custom logic around deep-sleep reconnection without scans.
rtndBr and connBr may be the same pointers.
Automatically resubscribes to all topics.
| rtndBr | Retained bridge peer info (for reconnection) |
| connBr | Connected bridge peer info storage (if connection successful and connBr != nullptr) |
|
protected |
Calculates bucket id from LocalAddrT object.
Used for m_sendingPromises and m_sendingMutexes arrays.
| addr | Address of the peer |
|
protected |
Receive message handler.
Separate from recvCb to allow simpler testing.
| msg | Message |
| rssi | Received signal strength indicator (in dBm) |
|
protected |
Receive callback for underlaying ESP-NOW adapter.
| src | Source address |
| data | Raw data |
| rssi | Received signal strength indicator (in dBm) |
| bool SPSP::LocalLayers::ESPNOW::ESPNOW::send | ( | const LocalMessageT & | msg | ) |
Sends the message to given node.
In the message, empty address means send to the bridge peer.
Note: this will block until delivery status is confirmed!
| msg | Message |
|
protected |
Send callback for underlaying ESP-NOW adapter.
| dst | Destination address |
| delivered | Whether packet has been delivered successfully |
|
protected |
Sends raw packet to the underlaying library.
Also registers and unregisters the peer temporarily.
This is not multi-thread safe.
| dst | Destination address |
| data | Raw data |
|
protected |
Container for mutex of being-sent messages.
We need only one thread waiting for message status per bucket in m_sendingPromises. Efectively allows maximum of MAX_PEER_NUM messages being sent at the same time.
Definition at line 128 of file espnow.hpp.
|
protected |
Container for promises of being-sent messages.
send() blocks until status of delivery is available (and no other message is being sent to the same node). Assign each peer a "bucket". When sending a message to other peer from the same bucket, wait for it to finish. Additional support for this mechanism is provided by m_sendingMutexes.
Definition at line 118 of file espnow.hpp.
1.8.17