Check if mesh peer exists or is self, show soft AP mac in status 5

Also added a few notes in the mesh md file
This commit is contained in:
Sara Damiano 2022-04-10 22:18:19 -04:00
parent df3fc96238
commit 92d264f4e0
3 changed files with 35 additions and 11 deletions

View File

@ -22,6 +22,10 @@ Add ``#define USE_TASMESH`` to your file ``user_config_override.h`` before compi
## Commands
**WARNING: The MAC address used for ESP-NOW is the *Soft AP MAC*, not the WiFi MAC.**
*NOTE: The colons in the mac addresses of the commands are optional.*
``MeshBroker`` - starts the broker on the ESP32, printing out the MAC and used WiFi-channel to the log. Must be called after WiFi is initialized!! Example 'Rule1 on system#boot do meshbroker endon'
``MeshChannel 1..13`` - changes the WiFi-channel (on the node) to n (1-13) according to the channel of the (ESP32-)broker.
@ -36,16 +40,24 @@ Add ``#define USE_TASMESH`` to your file ``user_config_override.h`` before compi
Rules examples:
- The broker must be started after wifi is up!!</br>``rule1 on system#boot do meshbroker endon``
- The node may be started as soon as possible. Once started wifi and webserver are disabled by design</br>``rule1 on system#init do meshnode 98:F4:AB:6D:2D:B5 endon``
- Add a known peer (another node in the mesh) after the node has initialized</br>``rule3 on mesh#node=1 do meshpeer 2cf4323cdb33 endon``
- The broker must be started after wifi is up!!
- To start as ESP32 as broker after wifi and mqtt connection, use</br>``rule1 on system#boot do meshbroker endon``
- The node may be started as soon as possible. Once started wifi and webserver are disabled by design.
- To start the node immediately use</br>``rule1 on system#init do meshnode FA:KE:AD:DR:ES:S1 endon``
- To use mesh in combination with deep sleep, you must set a rule to re-initialize the mesh on wake-up.
The mesh status and parameters are **NOT** (yet) saved to flash and the mesh is not restarted automatically.
- **WARNING**: In case of a system-wide power outage, nodes will be unable to reconnect until after the broker is ready!
If all devices power up at the same time, a broker starting after `system#boot` will likely not be ready until *after* a node attempting to join at `system#init`.
This will cause the node to fail to mesh and *no retrying is implemented at this time*.
To account for this, instead of (or in addition to) using a rule on the nodes, assign all nodes to a common group topic (`GroupTopic2 tasnodes`) and have the broker send a command on that topic after it is ready:</br>`rule2 on mesh#broker=1 do publish cmnd/tasnodes/meshnode FA:KE:AD:DR:ES:S1`
- Add a known peer (another node in the mesh) after the node has initialized</br>``rule3 on mesh#node=1 do meshpeer FA:KE:AD:DR:ES:S1 endon``
## Limitations
The following limitations apply:
- An ESP32 is only supported as a broker
- An ESP8266 is only supported as a node
- No command persistence is implemented so use rules to start a broker or a node
- No command persistence is implemented so use rules to start a broker or a node after start up or deep sleep
- Although node send queues are implemented there is no node receive queue so MQTT commands send to the node need to be as small as possible limited to a maximum of around 160 characters including the topic
- Although broker receive queues are implemented there is no broker send queue so MQTT commands send to the node need to be as small as possible limited to a maximum of around 160 characters including the topic
- As there is no direct connection from the node to the MQTT broker it will signal the node as LWT Offline

View File

@ -649,6 +649,9 @@ void CmndStatus(void)
(uint32_t)WiFi.localIP(), Settings->ipv4_address[1], Settings->ipv4_address[2],
Settings->ipv4_address[3], Settings->ipv4_address[4],
WiFi.macAddress().c_str());
#if defined USE_TASMESH
ResponseAppend_P(PSTR(",\"Soft AP Mac\":\"%s\""), WiFi.softAPmacAddress().c_str());
#endif // USE_TASMESH
#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET)
ResponseAppend_P(PSTR(",\"Ethernet\":{\"" D_CMND_HOSTNAME "\":\"%s\",\""
D_CMND_IPADDRESS "\":\"%_I\",\"" D_JSON_GATEWAY "\":\"%_I\",\"" D_JSON_SUBNETMASK "\":\"%_I\",\""

View File

@ -385,8 +385,9 @@ void MESHstartNode(int32_t _channel, uint8_t _role){ //we need a running broker
wifi_promiscuous_enable(0);
WiFi.disconnect();
MESHsetWifi(0);
if (esp_now_init() != 0) {
AddLog(LOG_LEVEL_INFO, PSTR("MSH: Node init failed"));
esp_err_t init_result = esp_now_init();
if (esp_err_t() != ESP_OK) {
AddLog(LOG_LEVEL_INFO, PSTR("MSH: Node init failed with error: %d"), init_result);
// try to re-launch wifi
MESH.role = ROLE_NONE;
MESHsetWifi(1);
@ -421,8 +422,9 @@ void MESHstartBroker(void) { // Must be called after WiFi is initialized!!
WiFi.softAPmacAddress(MESH.broker); //set MESH.broker to the needed MAC
uint32_t _channel = WiFi.channel();
if (esp_now_init() != 0) {
AddLog(LOG_LEVEL_INFO, PSTR("MSH: Broker init failed"));
esp_err_t init_result = esp_now_init();
if (esp_err_t() != ESP_OK) {
AddLog(LOG_LEVEL_INFO, PSTR("MSH: Broker init failed with error: %d"), init_result);
return;
}
@ -773,9 +775,16 @@ void CmndMeshPeer(void) {
char _peerMAC[18];
ToHex_P(_MAC, 6, _peerMAC, 18, ':');
AddLog(LOG_LEVEL_DEBUG,PSTR("MSH: MAC-string %s (%s)"), XdrvMailbox.data, _peerMAC);
MESHaddPeer(_MAC);
MESHcountPeers();
ResponseCmndChar(_peerMAC);
if (MESHcheckPeerList((const uint8_t *)_MAC) == false) {
MESHaddPeer(_MAC);
MESHcountPeers();
ResponseCmndChar(_peerMAC);
} else if (WiFi.macAddress() == String(_peerMAC) || WiFi.softAPmacAddress() == String(_peerMAC)){
// a device can be added as its own peer, but every send will result in a ESP_NOW_SEND_FAIL
AddLog(LOG_LEVEL_DEBUG,PSTR("MSH: device %s cannot be a peer of itself"), XdrvMailbox.data, _peerMAC);
} else {
AddLog(LOG_LEVEL_DEBUG,PSTR("MSH: %s is already on peer list, will not add"), XdrvMailbox.data, _peerMAC);
}
}
}