diff --git a/bin/device-update.sh b/bin/device-update.sh index ec0e839d7..98eff9d10 100755 --- a/bin/device-update.sh +++ b/bin/device-update.sh @@ -1,6 +1,6 @@ #!/bin/sh -PYTHON=${PYTHON:-python} +PYTHON=${PYTHON:-python3} # Usage info show_help() { diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index aa346aca4..8a2d8e9fc 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -23,6 +23,7 @@ #ifndef NO_ESP32 #include "mesh/http/WiFiAPClient.h" +#include "plugins/esp32/StoreForwardPlugin.h" #endif NodeDB nodeDB; diff --git a/src/mesh/http/ContentHandler.cpp b/src/mesh/http/ContentHandler.cpp index e46fdb1f7..3eefc11e2 100644 --- a/src/mesh/http/ContentHandler.cpp +++ b/src/mesh/http/ContentHandler.cpp @@ -77,7 +77,8 @@ void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer) ResourceNode *nodeAPIv1ToRadio = new ResourceNode("/api/v1/toradio", "PUT", &handleAPIv1ToRadio); ResourceNode *nodeAPIv1FromRadio = new ResourceNode("/api/v1/fromradio", "GET", &handleAPIv1FromRadio); - ResourceNode *nodeHotspot = new ResourceNode("/hotspot-detect.html", "GET", &handleHotspot); + ResourceNode *nodeHotspotApple = new ResourceNode("/hotspot-detect.html", "GET", &handleHotspot); + ResourceNode *nodeHotspotAndroid = new ResourceNode("/generate_204", "GET", &handleHotspot); ResourceNode *nodeFavicon = new ResourceNode("/favicon.ico", "GET", &handleFavicon); ResourceNode *nodeRoot = new ResourceNode("/", "GET", &handleRoot); ResourceNode *nodeStaticBrowse = new ResourceNode("/static", "GET", &handleStaticBrowse); @@ -96,7 +97,8 @@ void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer) secureServer->registerNode(nodeAPIv1ToRadioOptions); secureServer->registerNode(nodeAPIv1ToRadio); secureServer->registerNode(nodeAPIv1FromRadio); - secureServer->registerNode(nodeHotspot); + secureServer->registerNode(nodeHotspotApple); + secureServer->registerNode(nodeHotspotAndroid); secureServer->registerNode(nodeFavicon); secureServer->registerNode(nodeRoot); secureServer->registerNode(nodeStaticBrowse); @@ -117,7 +119,8 @@ void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer) insecureServer->registerNode(nodeAPIv1ToRadioOptions); insecureServer->registerNode(nodeAPIv1ToRadio); insecureServer->registerNode(nodeAPIv1FromRadio); - insecureServer->registerNode(nodeHotspot); + insecureServer->registerNode(nodeHotspotApple); + insecureServer->registerNode(nodeHotspotAndroid); insecureServer->registerNode(nodeFavicon); insecureServer->registerNode(nodeRoot); insecureServer->registerNode(nodeStaticBrowse); diff --git a/src/plugins/PluginDev.h b/src/plugins/PluginDev.h new file mode 100644 index 000000000..f0fccb8c5 --- /dev/null +++ b/src/plugins/PluginDev.h @@ -0,0 +1,10 @@ +#pragma once + +/* + * To developers: + * Use this to enable / disable features in your plugin that you don't want to risk checking into GitHub. + * + */ + +// Enable development more for StoreForwardPlugin +bool StoreForward_Dev = false; \ No newline at end of file diff --git a/src/plugins/esp32/RangeTestPlugin.cpp b/src/plugins/esp32/RangeTestPlugin.cpp index 35d39714e..b28bd8c9c 100644 --- a/src/plugins/esp32/RangeTestPlugin.cpp +++ b/src/plugins/esp32/RangeTestPlugin.cpp @@ -255,7 +255,9 @@ bool RangeTestPluginRadio::appendFile(const MeshPacket &mp) return 0; } - if (fileToWrite.println("time,from,sender name,sender lat,sender long,rx lat,rx long,rx snr,distance,payload")) { + // Print the CSV header + if (fileToWrite.println( + "time,from,sender name,sender lat,sender long,rx lat,rx long,rx snr,rx elevation,distance,payload")) { DEBUG_MSG("File was written\n"); } else { DEBUG_MSG("File write failed\n"); @@ -296,7 +298,9 @@ bool RangeTestPluginRadio::appendFile(const MeshPacket &mp) fileToAppend.printf("%f,", n->position.longitude_i * 1e-7); // Sender Long fileToAppend.printf("%f,", gpsStatus->getLatitude() * 1e-7); // RX Lat fileToAppend.printf("%f,", gpsStatus->getLongitude() * 1e-7); // RX Long - fileToAppend.printf("%f,", mp.rx_snr); // RX SNR + fileToAppend.printf("%d,", gpsStatus->getAltitude()); // RX Altitude + + fileToAppend.printf("%f,", mp.rx_snr); // RX SNR if (n->position.latitude_i && n->position.longitude_i && gpsStatus->getLatitude() && gpsStatus->getLongitude()) { float distance = latLongToMeter(n->position.latitude_i * 1e-7, n->position.longitude_i * 1e-7, diff --git a/src/plugins/esp32/StoreForwardPlugin.cpp b/src/plugins/esp32/StoreForwardPlugin.cpp index 8e0686825..6a90bf228 100644 --- a/src/plugins/esp32/StoreForwardPlugin.cpp +++ b/src/plugins/esp32/StoreForwardPlugin.cpp @@ -5,11 +5,13 @@ #include "Router.h" #include "configuration.h" #include "mesh-pb-constants.h" +#include "plugins/PluginDev.h" #include #include #define STOREFORWARD_MAX_PACKETS 0 -#define STOREFORWARD_SEND_HISTORY_SHORT 600 +#define STOREFORWARD_SEND_HISTORY_PERIOD 10 * 60 +#define STOREFORWARD_SEND_HISTORY_MAX 0 StoreForwardPlugin *storeForwardPlugin; @@ -22,9 +24,8 @@ int32_t StoreForwardPlugin::runOnce() if (radioConfig.preferences.is_router) { // Maybe some cleanup functions? - this->sawNodeReport(); this->historyReport(); - return (10 * 1000); + return (60 * 1000); } else { /* * If the plugin is turned on and is_router is not enabled, then we'll send a heartbeat every @@ -64,14 +65,12 @@ void StoreForwardPlugin::populatePSRAM() DEBUG_MSG(" Total PSRAM: %d\n", ESP.getPsramSize()); DEBUG_MSG(" Free PSRAM: %d\n", ESP.getFreePsram()); - // PacketHistoryStruct *packetHistory = (PacketHistoryStruct *)ps_calloc(STOREFORWARD_MAX_PACKETS, - // sizeof(PacketHistoryStruct)); - // Use a maximum of half the available PSRAM unless otherwise specified. uint32_t numberOfPackets = STOREFORWARD_MAX_PACKETS ? STOREFORWARD_MAX_PACKETS : ((ESP.getPsramSize() / 2) / sizeof(PacketHistoryStruct)); - this->packetHistory = (PacketHistoryStruct *)ps_calloc(numberOfPackets, sizeof(PacketHistoryStruct)); + // this->packetHistory = (PacketHistoryStruct *)ps_calloc(numberOfPackets, sizeof(PacketHistoryStruct)); + this->packetHistory = static_cast(ps_calloc(numberOfPackets, sizeof(PacketHistoryStruct))); DEBUG_MSG("After PSRAM initilization:\n"); DEBUG_MSG(" Total heap: %d\n", ESP.getHeapSize()); @@ -83,41 +82,17 @@ void StoreForwardPlugin::populatePSRAM() } // We saw a node. -uint32_t StoreForwardPlugin::sawNode(uint32_t node) +void StoreForwardPlugin::sawNode(uint32_t whoWeSaw, uint32_t sawSecAgo) { + if (radioConfig.preferences.is_router) { - /* - TODO: Move receivedRecord into the PSRAM - - TODO: Gracefully handle the case where we run out of records. - Maybe replace the oldest record that hasn't been seen in a while and assume they won't be back. - - TODO: Implment this as a std::map for quicker lookups (maybe it doesn't matter?). - */ - // DEBUG_MSG("%s (id=0x%08x Fr0x%02x To0x%02x, WantAck%d, HopLim%d", prefix, p->id, p->from & 0xff, p->to & 0xff, - // p->want_ack, p->hop_limit); - DEBUG_MSG("looking for node - from-0x%08x\n", node); - for (int i = 0; i < 50; i++) { - // DEBUG_MSG("Iterating through the seen nodes - %u %u %u\n", i, receivedRecord[i][0], receivedRecord[i][1]); - // First time seeing that node. - if (receivedRecord[i][0] == 0) { - // DEBUG_MSG("New node! Woohoo! Win!\n"); - receivedRecord[i][0] = node; - receivedRecord[i][1] = millis(); - - return receivedRecord[i][1]; - } - - // We've seen this node before. - if (receivedRecord[i][0] == node) { - // DEBUG_MSG("We've seen this node before\n"); - uint32_t lastSaw = receivedRecord[i][1]; - receivedRecord[i][1] = millis(); - return lastSaw; + // If node has been away for more than 10 minutes, send the node the last 10 minutes of + // messages + if (sawSecAgo > STOREFORWARD_SEND_HISTORY_PERIOD) { + // Node has been away for a while. + storeForwardPlugin->historySend(STOREFORWARD_SEND_HISTORY_PERIOD, whoWeSaw); } } - - return 0; } void StoreForwardPlugin::historyReport() @@ -132,8 +107,15 @@ void StoreForwardPlugin::historyReport() } DEBUG_MSG("StoreForwardPlugin::historyReport runtime - %u ms\n", millis() - startTimer); } + +/* + * + */ void StoreForwardPlugin::historySend(uint32_t msAgo, uint32_t to) { + // Send "Welcome back" + this->sendPayloadWelcome(to, false); + for (int i = 0; i < this->packetHistoryCurrent; i++) { if (this->packetHistory[i].time) { // DEBUG_MSG("... time-%u to-0x%08x\n", this->packetHistory[i].time, this->packetHistory[i].to & 0xffffffff); @@ -159,27 +141,6 @@ void StoreForwardPlugin::historyAdd(const MeshPacket *mp) this->packetHistoryCurrent++; } -// We saw a node. -void StoreForwardPlugin::sawNodeReport() -{ - - /* - TODO: Move receivedRecord into the PSRAM - - TODO: Gracefully handle the case where we run out of records. - Maybe replace the oldest record that hasn't been seen in a while and assume they won't be back. - - TODO: Implment this as a std::map for quicker lookups (maybe it doesn't matter?). - */ - - DEBUG_MSG("Iterating through the seen nodes in receivedRecord...\n"); - for (int i = 0; i < 50; i++) { - if (receivedRecord[i][1]) { - DEBUG_MSG("... record-%u from-0x%08x secAgo-%u\n", i, receivedRecord[i][0], (millis() - receivedRecord[i][1]) / 1000); - } - } -} - MeshPacket *StoreForwardPlugin::allocReply() { auto reply = allocDataPacket(); // Allocate a packet for sending @@ -194,8 +155,7 @@ void StoreForwardPlugin::sendPayload(NodeNum dest, bool wantReplies) p->decoded.want_response = wantReplies; p->want_ack = true; - /* - */ + static char heartbeatString[20]; snprintf(heartbeatString, sizeof(heartbeatString), "1"); @@ -205,60 +165,50 @@ void StoreForwardPlugin::sendPayload(NodeNum dest, bool wantReplies) service.sendToMesh(p); } +void StoreForwardPlugin::sendPayloadWelcome(NodeNum dest, bool wantReplies) +{ + DEBUG_MSG("*********************************\n"); + DEBUG_MSG("*********************************\n"); + DEBUG_MSG("*********************************\n"); + DEBUG_MSG("Sending S&F Welcome Message\n"); + DEBUG_MSG("*********************************\n"); + DEBUG_MSG("*********************************\n"); + DEBUG_MSG("*********************************\n"); + MeshPacket *p = allocReply(); + p->to = dest; + p->decoded.want_response = wantReplies; + + p->want_ack = true; + + p->decoded.portnum = PortNum_TEXT_MESSAGE_APP; + + static char heartbeatString[80]; + snprintf(heartbeatString, sizeof(heartbeatString), "Welcome back to the mesh. We have not seen you in x minutes!"); + + p->decoded.payload.size = strlen(heartbeatString); // You must specify how many bytes are in the reply + memcpy(p->decoded.payload.bytes, heartbeatString, p->decoded.payload.size); + + service.sendToMesh(p); +} + bool StoreForwardPlugin::handleReceived(const MeshPacket &mp) { #ifndef NO_ESP32 if (radioConfig.preferences.store_forward_plugin_enabled) { if (getFrom(&mp) != nodeDB.getNodeNum()) { - // DEBUG_MSG("Store & Forward Plugin -- Print Start ---------- ---------- ---------- ---------- ----------\n\n\n"); - // DEBUG_MSG("%s (id=0x%08x Fr0x%02x To0x%02x, WantAck%d, HopLim%d", prefix, p->id, p->from & 0xff, p->to & 0xff, - // p->want_ack, p->hop_limit); printPacket("----- PACKET FROM RADIO -----", &mp); - uint32_t sawTime = storeForwardPlugin->sawNode(getFrom(&mp) & 0xffffffff); - DEBUG_MSG("We last saw this node (%u), %u sec ago\n", mp.from & 0xffffffff, (millis() - sawTime) / 1000); + // uint32_t sawTime = storeForwardPlugin->sawNode(getFrom(&mp) & 0xffffffff); + // DEBUG_MSG("We last saw this node (%u), %u sec ago\n", mp.from & 0xffffffff, (millis() - sawTime) / 1000); DEBUG_MSG(" -------------- "); - if (mp.decoded.portnum == PortNum_UNKNOWN_APP) { - DEBUG_MSG("Packet came from - PortNum_UNKNOWN_APP\n"); - } else if (mp.decoded.portnum == PortNum_TEXT_MESSAGE_APP) { + if (mp.decoded.portnum == PortNum_TEXT_MESSAGE_APP) { DEBUG_MSG("Packet came from - PortNum_TEXT_MESSAGE_APP\n"); storeForwardPlugin->historyAdd(&mp); - } else if (mp.decoded.portnum == PortNum_REMOTE_HARDWARE_APP) { - DEBUG_MSG("Packet came from - PortNum_REMOTE_HARDWARE_APP\n"); - } else if (mp.decoded.portnum == PortNum_POSITION_APP) { - DEBUG_MSG("Packet came from - PortNum_POSITION_APP\n"); - } else if (mp.decoded.portnum == PortNum_NODEINFO_APP) { - DEBUG_MSG("Packet came from - PortNum_NODEINFO_APP\n"); - } else if (mp.decoded.portnum == PortNum_ROUTING_APP) { - DEBUG_MSG("Packet came from - PortNum_ROUTING_APP\n"); - } else if (mp.decoded.portnum == PortNum_ADMIN_APP) { - DEBUG_MSG("Packet came from - PortNum_ADMIN_APP\n"); - } else if (mp.decoded.portnum == PortNum_REPLY_APP) { - DEBUG_MSG("Packet came from - PortNum_REPLY_APP\n"); - } else if (mp.decoded.portnum == PortNum_IP_TUNNEL_APP) { - DEBUG_MSG("Packet came from - PortNum_IP_TUNNEL_APP\n"); - } else if (mp.decoded.portnum == PortNum_SERIAL_APP) { - DEBUG_MSG("Packet came from - PortNum_SERIAL_APP\n"); - } else if (mp.decoded.portnum == PortNum_STORE_FORWARD_APP) { - DEBUG_MSG("Packet came from - PortNum_STORE_FORWARD_APP\n"); - } else if (mp.decoded.portnum == PortNum_RANGE_TEST_APP) { - DEBUG_MSG("Packet came from - PortNum_RANGE_TEST_APP\n"); - } else if (mp.decoded.portnum == PortNum_PRIVATE_APP) { - DEBUG_MSG("Packet came from - PortNum_PRIVATE_APP\n"); - } else if (mp.decoded.portnum == PortNum_RANGE_TEST_APP) { - DEBUG_MSG("Packet came from - PortNum_RANGE_TEST_APP\n"); - } else if (mp.decoded.portnum == PortNum_ATAK_FORWARDER) { - DEBUG_MSG("Packet came from - PortNum_ATAK_FORWARDER\n"); } else { DEBUG_MSG("Packet came from an unknown port %u\n", mp.decoded.portnum); } - - if ((millis() - sawTime) > STOREFORWARD_SEND_HISTORY_SHORT) { - // Node has been away for a while. - storeForwardPlugin->historySend(sawTime, mp.from); - } } } else { @@ -276,14 +226,18 @@ StoreForwardPlugin::StoreForwardPlugin() #ifndef NO_ESP32 + isPromiscuous = true; // Brown chicken brown cow + /* Uncomment the preferences below if you want to use the plugin without having to configure it from the PythonAPI or WebUI. - - radioConfig.preferences.store_forward_plugin_enabled = 1; - radioConfig.preferences.is_router = 1; */ + if (StoreForward_Dev) { + radioConfig.preferences.store_forward_plugin_enabled = 1; + radioConfig.preferences.is_router = 1; + } + if (radioConfig.preferences.store_forward_plugin_enabled) { // Router diff --git a/src/plugins/esp32/StoreForwardPlugin.h b/src/plugins/esp32/StoreForwardPlugin.h index f8df48926..b444b6159 100644 --- a/src/plugins/esp32/StoreForwardPlugin.h +++ b/src/plugins/esp32/StoreForwardPlugin.h @@ -29,8 +29,7 @@ class StoreForwardPlugin : public SinglePortPlugin, private concurrency::OSThrea Update our local reference of when we last saw that node. @return 0 if we have never seen that node before otherwise return the last time we saw the node. */ - uint32_t sawNode(uint32_t); - void sawNodeReport(); + void sawNode(uint32_t whoWeSaw, uint32_t sawSecAgo); void historyAdd(const MeshPacket *mp); void historyReport(); void historySend(uint32_t msAgo, uint32_t to); @@ -40,6 +39,7 @@ class StoreForwardPlugin : public SinglePortPlugin, private concurrency::OSThrea * Send our payload into the mesh */ void sendPayload(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false); + void sendPayloadWelcome(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false); virtual MeshPacket *allocReply(); virtual bool wantPortnum(PortNum p) { return true; }; @@ -80,4 +80,3 @@ class StoreForwardPluginRadio : public SinglePortPlugin extern StoreForwardPluginRadio *storeForwardPluginRadio; */ -