2021-01-28 20:03:11 +00:00
|
|
|
bool initCommunication() {
|
|
|
|
WiFi.persistent(false);
|
|
|
|
bool ok = WifiEspNowBroadcast.begin("CO-WARN", 3);
|
|
|
|
if (!ok) {
|
|
|
|
LOG("WifiEspNowBroadcast.begin() failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
WifiEspNowBroadcast.onReceive(processRx, nullptr);
|
|
|
|
LOG("MAC address of this node is %s", WiFi.softAPmacAddress().c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-17 13:15:37 +00:00
|
|
|
/*
|
|
|
|
process wifi stack Rx interrupt
|
|
|
|
*/
|
2021-01-28 20:03:11 +00:00
|
|
|
ICACHE_RAM_ATTR void processRx(const uint8_t mac[6], const uint8_t* buf, size_t count, void* cbarg) {
|
2021-06-17 13:15:37 +00:00
|
|
|
//simple frame size check
|
|
|
|
if (count != sizeof(receiveBuffer[rxCounter])) {
|
2021-01-28 20:03:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-17 13:15:37 +00:00
|
|
|
receiveBuffer[rxCounter] = *(rm370*)buf;
|
|
|
|
//memcpy(&receiveBuffer[rxCounter].originMAC[0], &mac, sizeof(receiveBuffer[rxCounter].originMAC)); //dont overwrite original package
|
2021-01-28 20:03:11 +00:00
|
|
|
//shift ring buffer input pointer
|
2021-06-17 13:15:37 +00:00
|
|
|
if (rxCounter + 1 < MAX_PEERS) {
|
2021-01-28 20:03:11 +00:00
|
|
|
rxCounter++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rxCounter = 0;
|
|
|
|
}
|
|
|
|
}
|
2021-06-22 19:41:10 +00:00
|
|
|
LOG("[%02d] Message from %02X:%02X:%02X:%02X:%02X:%02X", rxCounter, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
2021-01-28 20:03:11 +00:00
|
|
|
}
|
|
|
|
|
2021-06-17 13:15:37 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
*/
|
2021-01-28 20:03:11 +00:00
|
|
|
void checkMessage() {
|
2021-06-17 13:15:37 +00:00
|
|
|
if (receiveBuffer[rxHandlePointer].PREAMBLE1 == 'R' && receiveBuffer[rxHandlePointer].PREAMBLE2 == 'M') {
|
|
|
|
LOG("Origin MAC %02X:%02X:%02X:%02X:%02X:%02X || \tStatus: %c | BatWarn: %c",
|
|
|
|
receiveBuffer[rxHandlePointer].originMAC[0],
|
|
|
|
receiveBuffer[rxHandlePointer].originMAC[1],
|
|
|
|
receiveBuffer[rxHandlePointer].originMAC[2],
|
|
|
|
receiveBuffer[rxHandlePointer].originMAC[3],
|
|
|
|
receiveBuffer[rxHandlePointer].originMAC[4],
|
|
|
|
receiveBuffer[rxHandlePointer].originMAC[5],
|
|
|
|
receiveBuffer[rxHandlePointer].code,
|
|
|
|
(receiveBuffer[rxHandlePointer].batteryWarning) ? '!' : '.');
|
|
|
|
switch (receiveBuffer[rxHandlePointer].code) {
|
2021-01-28 20:03:11 +00:00
|
|
|
case 'r':
|
2021-06-17 13:15:37 +00:00
|
|
|
//LOG("\tALARM received");
|
2021-01-28 20:03:11 +00:00
|
|
|
break;
|
|
|
|
case 'y':
|
2021-06-17 13:15:37 +00:00
|
|
|
//LOG("\tWARNING received");
|
2021-01-28 20:03:11 +00:00
|
|
|
break;
|
|
|
|
case 'g':
|
2021-06-17 13:15:37 +00:00
|
|
|
//LOG("\tGREEN received");
|
2021-01-28 20:03:11 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-06-17 13:15:37 +00:00
|
|
|
if (receiveBuffer[rxHandlePointer].batteryWarning == true) {
|
|
|
|
//LOG("\tBAT Warning received");
|
2021-01-28 20:03:11 +00:00
|
|
|
}
|
2021-06-17 13:15:37 +00:00
|
|
|
refreshGlobalStatus = true;
|
2021-01-28 20:03:11 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
DEBUGLOG("Payload does not contain known preamble.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-17 13:15:37 +00:00
|
|
|
|
2021-01-28 20:03:11 +00:00
|
|
|
void sendMessage() {
|
|
|
|
}
|