From af0db8a29f50cc49f8776f56c097fc5b873d27f1 Mon Sep 17 00:00:00 2001 From: Andre K Date: Mon, 14 Oct 2024 21:32:25 -0300 Subject: [PATCH 1/8] retain `fixed_position` during reset-nodedb (#5067) --- src/mesh/NodeDB.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 371cea413..558c5b825 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -556,7 +556,8 @@ void NodeDB::installDefaultChannels() void NodeDB::resetNodes() { - clearLocalPosition(); + if (!config.position.fixed_position) + clearLocalPosition(); numMeshNodes = 1; std::fill(devicestate.node_db_lite.begin() + 1, devicestate.node_db_lite.end(), meshtastic_NodeInfoLite()); devicestate.has_rx_text_message = false; @@ -1207,4 +1208,4 @@ void recordCriticalError(meshtastic_CriticalErrorCode code, uint32_t address, co LOG_ERROR("A critical failure occurred, portduino is exiting..."); exit(2); #endif -} \ No newline at end of file +} From 696bcc60af7e825ced41c642a76ea25a40dd3e46 Mon Sep 17 00:00:00 2001 From: Tavis Date: Tue, 15 Oct 2024 10:09:18 +0000 Subject: [PATCH 2/8] Ws85 updates : set want_ack, high_priority, add temperature. (#5052) * ws85 updates add temperature add wantack add high_priority set lull to 0 if never set. add the has_FIELD_NAME lines to ws85 * pbufs sync * high insteaed of max reliability * only set want_ack and high reliable if sensor_role set * protobufs --------- Co-authored-by: Tom Fifield --- protobufs | 2 +- src/modules/SerialModule.cpp | 43 ++++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/protobufs b/protobufs index e22381a3c..49ebc4783 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit e22381a3c6bbdd428f127ed8c0aa0a37789c3907 +Subproject commit 49ebc4783275f108a9f8723ca52a6edf0a954c55 diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index b1b02ac6a..dc9c8aa85 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -252,7 +252,12 @@ void SerialModule::sendTelemetry(meshtastic_Telemetry m) pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &meshtastic_Telemetry_msg, &m); p->to = NODENUM_BROADCAST; p->decoded.want_response = false; - p->priority = meshtastic_MeshPacket_Priority_RELIABLE; + if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR) { + p->want_ack = true; + p->priority = meshtastic_MeshPacket_Priority_HIGH; + } else { + p->priority = meshtastic_MeshPacket_Priority_RELIABLE; + } service->sendToMesh(p, RX_SRC_LOCAL, true); } @@ -424,8 +429,10 @@ void SerialModule::processWXSerial() static char windGust[5] = "xx.x"; // Assuming windGust is 4 characters long + null terminator static char batVoltage[5] = "0.0V"; static char capVoltage[5] = "0.0V"; + static char temperature[5] = "00.0"; static float batVoltageF = 0; static float capVoltageF = 0; + static float temperatureF = 0; bool gotwind = false; while (Serial2.available()) { @@ -499,6 +506,13 @@ void SerialModule::processWXSerial() strcpy(capVoltage, capVoltagePos + 17); // 18 for ws 80, 17 for ws85 capVoltageF = strtof(capVoltage, nullptr); } + // GXTS04Temp = 24.4 + } else if (strstr(line, "GXTS04Temp") != NULL) { // we have a temperature line + char *tempPos = strstr(line, "GXTS04Temp = "); + if (tempPos != NULL) { + strcpy(temperature, tempPos + 15); // 15 spaces for ws85 + temperatureF = strtof(temperature, nullptr); + } } // Update lineStart for the next line @@ -514,8 +528,8 @@ void SerialModule::processWXSerial() } if (gotwind) { - LOG_INFO("WS85 : %i %.1fg%.1f %.1fv %.1fv", atoi(windDir), strtof(windVel, nullptr), strtof(windGust, nullptr), - batVoltageF, capVoltageF); + LOG_INFO("WS85 : %i %.1fg%.1f %.1fv %.1fv %.1fC", atoi(windDir), strtof(windVel, nullptr), strtof(windGust, nullptr), + batVoltageF, capVoltageF, temperatureF); } if (gotwind && !Throttle::isWithinTimespanMs(lastAveraged, averageIntervalMillis)) { // calulate averages and send to the mesh @@ -535,17 +549,32 @@ void SerialModule::processWXSerial() // make a telemetry packet with the data meshtastic_Telemetry m = meshtastic_Telemetry_init_zero; m.which_variant = meshtastic_Telemetry_environment_metrics_tag; + m.variant.environment_metrics.wind_speed = velAvg; + m.variant.environment_metrics.has_wind_speed = true; + m.variant.environment_metrics.wind_direction = dirAvg; - m.variant.environment_metrics.wind_gust = gust; - m.variant.environment_metrics.wind_lull = lull; + m.variant.environment_metrics.has_wind_direction = true; + + m.variant.environment_metrics.temperature = temperatureF; + m.variant.environment_metrics.has_temperature = true; + m.variant.environment_metrics.voltage = capVoltageF > batVoltageF ? capVoltageF : batVoltageF; // send the larger of the two voltage values. + m.variant.environment_metrics.has_voltage = true; - LOG_INFO("WS85 Transmit speed=%fm/s, direction=%d , lull=%f, gust=%f, voltage=%f", + m.variant.environment_metrics.wind_gust = gust; + m.variant.environment_metrics.has_wind_gust = true; + + if (lull == -1) + lull = 0; + m.variant.environment_metrics.wind_lull = lull; + m.variant.environment_metrics.has_wind_lull = true; + + LOG_INFO("WS85 Transmit speed=%fm/s, direction=%d , lull=%f, gust=%f, voltage=%f temperature=%f", m.variant.environment_metrics.wind_speed, m.variant.environment_metrics.wind_direction, m.variant.environment_metrics.wind_lull, m.variant.environment_metrics.wind_gust, - m.variant.environment_metrics.voltage); + m.variant.environment_metrics.voltage, m.variant.environment_metrics.temperature); sendTelemetry(m); From 7fd1c334d3c1390ce8d7beff25cc81e0c0e0ec6e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 15 Oct 2024 09:15:15 -0500 Subject: [PATCH 3/8] [create-pull-request] automated change (#5074) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> --- protobufs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobufs b/protobufs index 49ebc4783..e22381a3c 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 49ebc4783275f108a9f8723ca52a6edf0a954c55 +Subproject commit e22381a3c6bbdd428f127ed8c0aa0a37789c3907 From 25b557cf46489dbe39c65b31d0e2ee09dc7eb451 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 15 Oct 2024 17:15:10 -0500 Subject: [PATCH 4/8] Fix incorrect va_start calls (#5076) --- src/RedirectablePrint.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index cdb191c1a..57f53019d 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -290,7 +290,7 @@ void RedirectablePrint::log(const char *logLevel, const char *format, ...) if (strcmp(logLevel, MESHTASTIC_LOG_LEVEL_TRACE) == 0) { if (settingsStrings[traceFilename] != "") { va_list arg; - va_start(arg, newFormat); + va_start(arg, format); try { traceFile << va_arg(arg, char *) << std::endl; } catch (const std::ios_base::failure &e) { @@ -326,7 +326,7 @@ void RedirectablePrint::log(const char *logLevel, const char *format, ...) #endif va_list arg; - va_start(arg, newFormat); + va_start(arg, format); log_to_serial(logLevel, newFormat, arg); log_to_syslog(logLevel, newFormat, arg); From ad214ea42a8c484f1ff90cd76dd58c89408e33fc Mon Sep 17 00:00:00 2001 From: Johnathon Mohr Date: Tue, 15 Oct 2024 17:08:49 -0700 Subject: [PATCH 5/8] Add MQTT exception for private IP address server (#5072) Determines if the given IP address is a private address, i.e. not routable on the public internet. These are the ranges: 127.0.0.1, 10.0.0.0-10.255.255.255, 172.16.0.0-172.31.255.255, 192.168.0.0-192.168.255.255. If so, allow MQTT publication the same as existing localhost support. --- src/mqtt/MQTT.cpp | 36 ++++++++++++++++++++++++++++++++++-- src/mqtt/MQTT.h | 4 ++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 80f6428ce..641583b62 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -35,6 +35,8 @@ Allocator &mqttPool = staticMqttPool; // FIXME - this size calculation is super sloppy, but it will go away once we dynamically alloc meshpackets static uint8_t bytes[meshtastic_MqttClientProxyMessage_size + 30]; // 12 for channel name and 16 for nodeid +static bool isMqttServerAddressPrivate = false; + void MQTT::mqttCallback(char *topic, byte *payload, unsigned int length) { mqtt->onReceive(topic, payload, length); @@ -238,6 +240,11 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE) moduleConfig.mqtt.map_report_settings.publish_interval_secs, default_map_publish_interval_secs); } + isMqttServerAddressPrivate = isPrivateIpAddress(moduleConfig.mqtt.address); + if (isMqttServerAddressPrivate) { + LOG_INFO("MQTT server is a private IP address."); + } + #if HAS_NETWORKING if (!moduleConfig.mqtt.proxy_to_client_enabled) pubSub.setCallback(mqttCallback); @@ -538,9 +545,8 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp_encrypted, const meshtastic_Me // mp_decoded will not be decoded when it's PKI encrypted and not directed to us if (mp_decoded.which_payload_variant == meshtastic_MeshPacket_decoded_tag) { - // check for the lowest bit of the data bitfield set false, and the use of one of the default keys. - if (!isFromUs(&mp_decoded) && strcmp(moduleConfig.mqtt.address, "127.0.0.1") != 0 && mp_decoded.decoded.has_bitfield && + if (!isFromUs(&mp_decoded) && !isMqttServerAddressPrivate && mp_decoded.decoded.has_bitfield && !(mp_decoded.decoded.bitfield & BITFIELD_OK_TO_MQTT_MASK) && (ch.settings.psk.size < 2 || (ch.settings.psk.size == 16 && memcmp(ch.settings.psk.bytes, defaultpsk, 16)) || (ch.settings.psk.size == 32 && memcmp(ch.settings.psk.bytes, eventpsk, 32)))) { @@ -696,4 +702,30 @@ bool MQTT::isValidJsonEnvelope(JSONObject &json) (json["from"]->AsNumber() == nodeDB->getNodeNum()) && // only accept message if the "from" is us (json.find("type") != json.end()) && json["type"]->IsString() && // should specify a type (json.find("payload") != json.end()); // should have a payload +} + +bool MQTT::isPrivateIpAddress(const char ip[]) +{ + // Check the easy ones first. + if (strcmp(ip, "127.0.0.1") == 0 || strncmp(ip, "10.", 3) == 0 || strncmp(ip, "192.168", 7) == 0) { + return true; + } + + // See if it's definitely not a 172 address. + if (strncmp(ip, "172", 3) != 0) { + return false; + } + + // We know it's a 172 address, now see if the second octet is 2 digits. + if (ip[6] != '.') { + return false; + } + + // Copy the second octet into a secondary buffer we can null-terminate and parse. + char octet2[3]; + strncpy(octet2, ip + 4, 2); + octet2[2] = 0; + + int octet2Num = atoi(octet2); + return octet2Num >= 16 && octet2Num <= 31; } \ No newline at end of file diff --git a/src/mqtt/MQTT.h b/src/mqtt/MQTT.h index 83adc8fd2..fbfb7856e 100644 --- a/src/mqtt/MQTT.h +++ b/src/mqtt/MQTT.h @@ -120,6 +120,10 @@ class MQTT : private concurrency::OSThread // returns true if this is a valid JSON envelope which we accept on downlink bool isValidJsonEnvelope(JSONObject &json); + /// Determines if the given IP address is a private address, i.e. not routable on the public internet. + /// These are the ranges: 127.0.0.1, 10.0.0.0-10.255.255.255, 172.16.0.0-172.31.255.255, 192.168.0.0-192.168.255.255. + bool isPrivateIpAddress(const char ip[]); + /// Return 0 if sleep is okay, veto sleep if we are connected to pubsub server // int preflightSleepCb(void *unused = NULL) { return pubSub.connected() ? 1 : 0; } }; From 3e5f129fceeb4cbc7d4154728b90b9e9e2416bff Mon Sep 17 00:00:00 2001 From: Johnathon Mohr Date: Wed, 16 Oct 2024 03:19:00 -0700 Subject: [PATCH 6/8] Ensure the MQTT address is an IPv4 before determining it's private (#5081) * Ensure the mqtt address is an IPv4 (or at least not a domain) before determining it's private. * check address length --- src/mqtt/MQTT.cpp | 24 +++++++++++++++++++----- src/mqtt/MQTT.h | 4 ++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 641583b62..45518153e 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -704,26 +704,40 @@ bool MQTT::isValidJsonEnvelope(JSONObject &json) (json.find("payload") != json.end()); // should have a payload } -bool MQTT::isPrivateIpAddress(const char ip[]) +bool MQTT::isPrivateIpAddress(const char address[]) { + // Min. length like 10.0.0.0, max like 192.168.255.255 + size_t length = strlen(address); + if (length < 8 || length > 15) { + return false; + } + + // Ensure the address contains only digits and dots. + // Even if it's not a valid IP address, we will know it's not a domain. + for (int i = 0; i < length; i++) { + if (!isdigit(address[i]) && address[i] != '.') { + return false; + } + } + // Check the easy ones first. - if (strcmp(ip, "127.0.0.1") == 0 || strncmp(ip, "10.", 3) == 0 || strncmp(ip, "192.168", 7) == 0) { + if (strcmp(address, "127.0.0.1") == 0 || strncmp(address, "10.", 3) == 0 || strncmp(address, "192.168", 7) == 0) { return true; } // See if it's definitely not a 172 address. - if (strncmp(ip, "172", 3) != 0) { + if (strncmp(address, "172", 3) != 0) { return false; } // We know it's a 172 address, now see if the second octet is 2 digits. - if (ip[6] != '.') { + if (address[6] != '.') { return false; } // Copy the second octet into a secondary buffer we can null-terminate and parse. char octet2[3]; - strncpy(octet2, ip + 4, 2); + strncpy(octet2, address + 4, 2); octet2[2] = 0; int octet2Num = atoi(octet2); diff --git a/src/mqtt/MQTT.h b/src/mqtt/MQTT.h index fbfb7856e..fcefb94a2 100644 --- a/src/mqtt/MQTT.h +++ b/src/mqtt/MQTT.h @@ -120,9 +120,9 @@ class MQTT : private concurrency::OSThread // returns true if this is a valid JSON envelope which we accept on downlink bool isValidJsonEnvelope(JSONObject &json); - /// Determines if the given IP address is a private address, i.e. not routable on the public internet. + /// Determines if the given address is a private IPv4 address, i.e. not routable on the public internet. /// These are the ranges: 127.0.0.1, 10.0.0.0-10.255.255.255, 172.16.0.0-172.31.255.255, 192.168.0.0-192.168.255.255. - bool isPrivateIpAddress(const char ip[]); + bool isPrivateIpAddress(const char address[]); /// Return 0 if sleep is okay, veto sleep if we are connected to pubsub server // int preflightSleepCb(void *unused = NULL) { return pubSub.connected() ? 1 : 0; } From 198b62f3fcc1c427c4b5ed1cc03168e89dbab56d Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 16 Oct 2024 07:34:24 -0500 Subject: [PATCH 7/8] I thought these were already board level extra --- variants/heltec_v2.1/platformio.ini | 1 + variants/heltec_v2/platformio.ini | 3 ++- variants/tlora_v2/platformio.ini | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/variants/heltec_v2.1/platformio.ini b/variants/heltec_v2.1/platformio.ini index 5aa04fc58..ea2281911 100644 --- a/variants/heltec_v2.1/platformio.ini +++ b/variants/heltec_v2.1/platformio.ini @@ -1,4 +1,5 @@ [env:heltec-v2_1] +board_level = extra ;build_type = debug ; to make it possible to step through our jtag debugger extends = esp32_base board = heltec_wifi_lora_32_V2 diff --git a/variants/heltec_v2/platformio.ini b/variants/heltec_v2/platformio.ini index cee1537d0..c81bca8ba 100644 --- a/variants/heltec_v2/platformio.ini +++ b/variants/heltec_v2/platformio.ini @@ -1,5 +1,6 @@ [env:heltec-v2_0] -;build_type = debug ; to make it possible to step through our jtag debugger +;build_type = debug ; to make it possible to step through our jtag debugger +board_level = extra extends = esp32_base board = heltec_wifi_lora_32_V2 build_flags = diff --git a/variants/tlora_v2/platformio.ini b/variants/tlora_v2/platformio.ini index 8710068af..8087a30e3 100644 --- a/variants/tlora_v2/platformio.ini +++ b/variants/tlora_v2/platformio.ini @@ -1,4 +1,5 @@ [env:tlora-v2] +board_level = extra extends = esp32_base board = ttgo-lora32-v1 build_flags = From f77c87dca8da0903f4f73d54c0f46ec9619b1e31 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 16 Oct 2024 09:18:44 -0500 Subject: [PATCH 8/8] Extra extra --- variants/tlora_v1/platformio.ini | 1 + variants/tlora_v1_3/platformio.ini | 1 + 2 files changed, 2 insertions(+) diff --git a/variants/tlora_v1/platformio.ini b/variants/tlora_v1/platformio.ini index c90daed90..65ec4bcdc 100644 --- a/variants/tlora_v1/platformio.ini +++ b/variants/tlora_v1/platformio.ini @@ -1,4 +1,5 @@ [env:tlora-v1] +board_level = extra extends = esp32_base board = ttgo-lora32-v1 build_flags = diff --git a/variants/tlora_v1_3/platformio.ini b/variants/tlora_v1_3/platformio.ini index 9d9f41a7c..99df28e56 100644 --- a/variants/tlora_v1_3/platformio.ini +++ b/variants/tlora_v1_3/platformio.ini @@ -1,4 +1,5 @@ [env:tlora_v1_3] +board_level = extra extends = esp32_base board = ttgo-lora32-v1 build_flags =