diff --git a/.github/workflows/package_amd64.yml b/.github/workflows/package_amd64.yml index ae7bf3242..0b5093f24 100644 --- a/.github/workflows/package_amd64.yml +++ b/.github/workflows/package_amd64.yml @@ -13,7 +13,7 @@ jobs: uses: ./.github/workflows/build_native.yml package-native: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: build-native steps: - name: Checkout code diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 5471332c5..bcbda53e2 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -13,7 +13,7 @@ jobs: uses: ./.github/workflows/build_raspbian.yml package-raspbian: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: build-raspbian steps: - name: Checkout code diff --git a/.github/workflows/package_raspbian_armv7l.yml b/.github/workflows/package_raspbian_armv7l.yml index 5b9c9aa71..1308fe925 100644 --- a/.github/workflows/package_raspbian_armv7l.yml +++ b/.github/workflows/package_raspbian_armv7l.yml @@ -13,7 +13,7 @@ jobs: uses: ./.github/workflows/build_raspbian_armv7l.yml package-raspbian_armv7l: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: build-raspbian_armv7l steps: - name: Checkout code diff --git a/.github/workflows/sec_sast_semgrep_pull.yml b/.github/workflows/sec_sast_semgrep_pull.yml index b6c288494..2575cbf01 100644 --- a/.github/workflows/sec_sast_semgrep_pull.yml +++ b/.github/workflows/sec_sast_semgrep_pull.yml @@ -4,7 +4,7 @@ on: pull_request jobs: semgrep-diff: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 container: image: returntocorp/semgrep diff --git a/boards/heltec_mesh_node_t114.json b/boards/heltec_mesh_node_t114.json index 5c97d8c75..2bd306eb9 100644 --- a/boards/heltec_mesh_node_t114.json +++ b/boards/heltec_mesh_node_t114.json @@ -5,7 +5,7 @@ }, "core": "nRF5", "cpu": "cortex-m4", - "extra_flags": "-DARDUINO_NRF52840_PCA10056 -DNRF52840_XXAA", + "extra_flags": "-DHELTEC_T114 -DNRF52840_XXAA", "f_cpu": "64000000L", "hwids": [ ["0x239A", "0x4405"], diff --git a/boards/me25ls01-4y10td.json b/boards/me25ls01-4y10td.json index 46c526a7c..9e1d63265 100644 --- a/boards/me25ls01-4y10td.json +++ b/boards/me25ls01-4y10td.json @@ -5,7 +5,7 @@ }, "core": "nRF5", "cpu": "cortex-m4", - "extra_flags": "-DARDUINO_WIO_WM1110 -DNRF52840_XXAA", + "extra_flags": "-DME25LS01_4Y10TD -DNRF52840_XXAA", "f_cpu": "64000000L", "hwids": [ ["0x239A", "0x8029"], diff --git a/boards/ms24sf1.json b/boards/ms24sf1.json index 4e28507da..8356e3012 100644 --- a/boards/ms24sf1.json +++ b/boards/ms24sf1.json @@ -5,7 +5,7 @@ }, "core": "nRF5", "cpu": "cortex-m4", - "extra_flags": "-DARDUINO_WIO_WM1110 -DNRF52840_XXAA", + "extra_flags": "-DMS24SF1 -DNRF52840_XXAA", "f_cpu": "64000000L", "hwids": [ ["0x239A", "0x8029"], diff --git a/boards/nordic_pca10059.json b/boards/nordic_pca10059.json index b99e3c763..6540817a2 100644 --- a/boards/nordic_pca10059.json +++ b/boards/nordic_pca10059.json @@ -5,7 +5,7 @@ }, "core": "nRF5", "cpu": "cortex-m4", - "extra_flags": "-DARDUINO_NRF52840_FEATHER -DNRF52840_XXAA", + "extra_flags": "-DNORDIC_PCA10059 -DNRF52840_XXAA", "f_cpu": "64000000L", "hwids": [ ["0x239A", "0x8029"], diff --git a/platformio.ini b/platformio.ini index 69d67a59c..4d7a683c7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -89,8 +89,7 @@ monitor_speed = 115200 monitor_filters = direct lib_deps = -; jgromes/RadioLib@~6.6.0 - https://github.com/jgromes/RadioLib.git#3115fc2d6700a9aee05888791ac930a910f2628f + jgromes/RadioLib@~7.0.0 https://github.com/meshtastic/esp8266-oled-ssd1306.git#e16cee124fe26490cb14880c679321ad8ac89c95 ; ESP8266_SSD1306 https://github.com/mathertel/OneButton@~2.6.1 ; OneButton library for non-blocking button debounce https://github.com/meshtastic/arduino-fsm.git#7db3702bf0cfe97b783d6c72595e3f38e0b19159 @@ -158,9 +157,9 @@ lib_deps = https://github.com/boschsensortec/Bosch-BSEC2-Library#v1.7.2502 boschsensortec/BME68x Sensor Library@^1.1.40407 https://github.com/KodinLanewave/INA3221@^1.0.0 - lewisxhe/SensorLib@^0.2.0 + lewisxhe/SensorLib@0.2.0 mprograms/QMC5883LCompass@^1.2.0 https://github.com/meshtastic/DFRobot_LarkWeatherStation#dee914270dc7cb3e43fbf034edd85a63a16a12ee - https://github.com/gjelsoe/STK8xxx-Accelerometer.git#v0.1.1 \ No newline at end of file + https://github.com/gjelsoe/STK8xxx-Accelerometer.git#v0.1.1 diff --git a/protobufs b/protobufs index 164e59873..5709c0a05 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 164e598734a813ae00a2a74266e9e06438f030ce +Subproject commit 5709c0a05eaefccbc9cb8ed3917adbf5fd134197 diff --git a/src/main.cpp b/src/main.cpp index a6e6ad631..e24ba68b3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -390,7 +390,7 @@ void setup() #endif #ifdef AQ_SET_PIN - // RAK-12039 set pin for Air quality sensor + // RAK-12039 set pin for Air quality sensor. Detectable on I2C after ~3 seconds, so we need to rescan later pinMode(AQ_SET_PIN, OUTPUT); digitalWrite(AQ_SET_PIN, HIGH); #endif @@ -1142,4 +1142,4 @@ void loop() } // if (didWake) LOG_DEBUG("wake!\n"); } -#endif +#endif \ No newline at end of file diff --git a/src/mesh/Default.h b/src/mesh/Default.h index bafa60898..5641b5d25 100644 --- a/src/mesh/Default.h +++ b/src/mesh/Default.h @@ -3,6 +3,8 @@ #include #define ONE_DAY 24 * 60 * 60 #define ONE_MINUTE_MS 60 * 1000 +#define THIRTY_SECONDS_MS 30 * 1000 +#define FIVE_SECONDS_MS 5 * 1000 #define default_gps_update_interval IF_ROUTER(ONE_DAY, 2 * 60) #define default_telemetry_broadcast_interval_secs IF_ROUTER(ONE_DAY / 2, 30 * 60) diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 742bdbf34..121687c49 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -25,6 +25,7 @@ #if !MESHTASTIC_EXCLUDE_MQTT #include "mqtt/MQTT.h" #endif +#include PhoneAPI::PhoneAPI() { @@ -541,14 +542,37 @@ bool PhoneAPI::available() return false; } +void PhoneAPI::sendNotification(meshtastic_LogRecord_Level level, uint32_t replyId, const char *message) +{ + meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed(); + cn->has_reply_id = true; + cn->reply_id = replyId; + cn->level = meshtastic_LogRecord_Level_WARNING; + cn->time = getValidTime(RTCQualityFromNet); + strncpy(cn->message, message, sizeof(cn->message)); + service->sendClientNotification(cn); + delete cn; +} + /** * Handle a packet that the phone wants us to send. It is our responsibility to free the packet to the pool */ bool PhoneAPI::handleToRadioPacket(meshtastic_MeshPacket &p) { printPacket("PACKET FROM PHONE", &p); + if (p.decoded.portnum == meshtastic_PortNum_TRACEROUTE_APP && lastPortNumToRadio[p.decoded.portnum] && + (millis() - lastPortNumToRadio[p.decoded.portnum]) < (THIRTY_SECONDS_MS)) { + LOG_WARN("Rate limiting portnum %d\n", p.decoded.portnum); + sendNotification(meshtastic_LogRecord_Level_WARNING, p.id, "TraceRoute can only be sent once every 30 seconds"); + return false; + } else if (p.decoded.portnum == meshtastic_PortNum_POSITION_APP && lastPortNumToRadio[p.decoded.portnum] && + (millis() - lastPortNumToRadio[p.decoded.portnum]) < (FIVE_SECONDS_MS)) { + LOG_WARN("Rate limiting portnum %d\n", p.decoded.portnum); + sendNotification(meshtastic_LogRecord_Level_WARNING, p.id, "Position can only be sent once every 5 seconds"); + return false; + } + lastPortNumToRadio[p.decoded.portnum] = millis(); service->handleToRadio(p); - return true; } diff --git a/src/mesh/PhoneAPI.h b/src/mesh/PhoneAPI.h index 5feb1c4bf..1e09b9535 100644 --- a/src/mesh/PhoneAPI.h +++ b/src/mesh/PhoneAPI.h @@ -2,8 +2,10 @@ #include "Observer.h" #include "mesh-pb-constants.h" +#include "meshtastic/portnums.pb.h" #include #include +#include #include // Make sure that we never let our packets grow too large for one BLE packet @@ -48,6 +50,9 @@ class PhoneAPI uint8_t config_state = 0; + // Hashmap of timestamps for last time we received a packet on the API per portnum + std::unordered_map lastPortNumToRadio; + /** * Each packet sent to the phone has an incrementing count */ @@ -99,6 +104,11 @@ class PhoneAPI */ virtual bool handleToRadio(const uint8_t *buf, size_t len); + /** + * Send a (client)notification to the phone + */ + virtual void sendNotification(meshtastic_LogRecord_Level level, uint32_t replyId, const char *message); + /** * Get the next packet we want to send to the phone * diff --git a/src/mesh/generated/meshtastic/clientonly.pb.h b/src/mesh/generated/meshtastic/clientonly.pb.h index dc323292a..5720c1c02 100644 --- a/src/mesh/generated/meshtastic/clientonly.pb.h +++ b/src/mesh/generated/meshtastic/clientonly.pb.h @@ -5,6 +5,7 @@ #define PB_MESHTASTIC_MESHTASTIC_CLIENTONLY_PB_H_INCLUDED #include #include "meshtastic/localonly.pb.h" +#include "meshtastic/mesh.pb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. @@ -28,6 +29,15 @@ typedef struct _meshtastic_DeviceProfile { /* The ModuleConfig of the node */ bool has_module_config; meshtastic_LocalModuleConfig module_config; + /* Fixed position data */ + bool has_fixed_position; + meshtastic_Position fixed_position; + /* Ringtone for ExternalNotification */ + bool has_ringtone; + char ringtone[231]; + /* Predefined messages for CannedMessage */ + bool has_canned_messages; + char canned_messages[201]; } meshtastic_DeviceProfile; @@ -36,8 +46,8 @@ extern "C" { #endif /* Initializer values for message structs */ -#define meshtastic_DeviceProfile_init_default {false, "", false, "", {{NULL}, NULL}, false, meshtastic_LocalConfig_init_default, false, meshtastic_LocalModuleConfig_init_default} -#define meshtastic_DeviceProfile_init_zero {false, "", false, "", {{NULL}, NULL}, false, meshtastic_LocalConfig_init_zero, false, meshtastic_LocalModuleConfig_init_zero} +#define meshtastic_DeviceProfile_init_default {false, "", false, "", {{NULL}, NULL}, false, meshtastic_LocalConfig_init_default, false, meshtastic_LocalModuleConfig_init_default, false, meshtastic_Position_init_default, false, "", false, ""} +#define meshtastic_DeviceProfile_init_zero {false, "", false, "", {{NULL}, NULL}, false, meshtastic_LocalConfig_init_zero, false, meshtastic_LocalModuleConfig_init_zero, false, meshtastic_Position_init_zero, false, "", false, ""} /* Field tags (for use in manual encoding/decoding) */ #define meshtastic_DeviceProfile_long_name_tag 1 @@ -45,6 +55,9 @@ extern "C" { #define meshtastic_DeviceProfile_channel_url_tag 3 #define meshtastic_DeviceProfile_config_tag 4 #define meshtastic_DeviceProfile_module_config_tag 5 +#define meshtastic_DeviceProfile_fixed_position_tag 6 +#define meshtastic_DeviceProfile_ringtone_tag 7 +#define meshtastic_DeviceProfile_canned_messages_tag 8 /* Struct field encoding specification for nanopb */ #define meshtastic_DeviceProfile_FIELDLIST(X, a) \ @@ -52,11 +65,15 @@ X(a, STATIC, OPTIONAL, STRING, long_name, 1) \ X(a, STATIC, OPTIONAL, STRING, short_name, 2) \ X(a, CALLBACK, OPTIONAL, STRING, channel_url, 3) \ X(a, STATIC, OPTIONAL, MESSAGE, config, 4) \ -X(a, STATIC, OPTIONAL, MESSAGE, module_config, 5) +X(a, STATIC, OPTIONAL, MESSAGE, module_config, 5) \ +X(a, STATIC, OPTIONAL, MESSAGE, fixed_position, 6) \ +X(a, STATIC, OPTIONAL, STRING, ringtone, 7) \ +X(a, STATIC, OPTIONAL, STRING, canned_messages, 8) #define meshtastic_DeviceProfile_CALLBACK pb_default_field_callback #define meshtastic_DeviceProfile_DEFAULT NULL #define meshtastic_DeviceProfile_config_MSGTYPE meshtastic_LocalConfig #define meshtastic_DeviceProfile_module_config_MSGTYPE meshtastic_LocalModuleConfig +#define meshtastic_DeviceProfile_fixed_position_MSGTYPE meshtastic_Position extern const pb_msgdesc_t meshtastic_DeviceProfile_msg; diff --git a/src/modules/Telemetry/AirQualityTelemetry.cpp b/src/modules/Telemetry/AirQualityTelemetry.cpp index d07296710..56d308cfa 100644 --- a/src/modules/Telemetry/AirQualityTelemetry.cpp +++ b/src/modules/Telemetry/AirQualityTelemetry.cpp @@ -10,11 +10,11 @@ #include "PowerFSM.h" #include "RTC.h" #include "Router.h" +#include "detect/ScanI2CTwoWire.h" #include "main.h" int32_t AirQualityTelemetryModule::runOnce() { - int32_t result = INT32_MAX; /* Uncomment the preferences below if you want to use the module without having to configure it from the PythonAPI or WebUI. @@ -29,21 +29,36 @@ int32_t AirQualityTelemetryModule::runOnce() if (firstTime) { // This is the first time the OSThread library has called this function, so do some setup - firstTime = 0; + firstTime = false; if (moduleConfig.telemetry.air_quality_enabled) { LOG_INFO("Air quality Telemetry: Initializing\n"); if (!aqi.begin_I2C()) { - LOG_WARN("Could not establish i2c connection to AQI sensor\n"); + LOG_WARN("Could not establish i2c connection to AQI sensor. Rescanning...\n"); + // rescan for late arriving sensors. AQI Module starts about 10 seconds into the boot so this is plenty. + uint8_t i2caddr_scan[] = {PMSA0031_ADDR}; + uint8_t i2caddr_asize = 1; + auto i2cScanner = std::unique_ptr(new ScanI2CTwoWire()); +#if defined(I2C_SDA1) + i2cScanner->scanPort(ScanI2C::I2CPort::WIRE1, i2caddr_scan, i2caddr_asize); +#endif + i2cScanner->scanPort(ScanI2C::I2CPort::WIRE, i2caddr_scan, i2caddr_asize); + auto found = i2cScanner->find(ScanI2C::DeviceType::PMSA0031); + if (found.type != ScanI2C::DeviceType::NONE) { + nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_PMSA003I].first = found.address.address; + nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_PMSA003I].second = + i2cScanner->fetchI2CBus(found.address); + return 1000; + } return disable(); } return 1000; } - return result; + return disable(); } else { // if we somehow got to a second run of this module with measurement disabled, then just wait forever if (!moduleConfig.telemetry.air_quality_enabled) - return result; + return disable(); uint32_t now = millis(); if (((lastSentToMesh == 0) || diff --git a/src/modules/Telemetry/AirQualityTelemetry.h b/src/modules/Telemetry/AirQualityTelemetry.h index 23df6ac58..fb8edd07e 100644 --- a/src/modules/Telemetry/AirQualityTelemetry.h +++ b/src/modules/Telemetry/AirQualityTelemetry.h @@ -44,7 +44,7 @@ class AirQualityTelemetryModule : private concurrency::OSThread, public Protobuf private: Adafruit_PM25AQI aqi; PM25_AQI_Data data = {0}; - bool firstTime = 1; + bool firstTime = true; meshtastic_MeshPacket *lastMeasurementPacket; uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute uint32_t lastSentToMesh = 0; diff --git a/variants/chatter2/variant.h b/variants/chatter2/variant.h index b7f946970..5c27e2fb5 100644 --- a/variants/chatter2/variant.h +++ b/variants/chatter2/variant.h @@ -66,6 +66,7 @@ #define SCREEN_ROTATE #define SCREEN_TRANSITION_FRAMERATE 5 // fps #define DISPLAY_FORCE_SMALL_FONTS +#define TFT_BACKLIGHT_ON LOW // Battery @@ -121,4 +122,4 @@ // cannot serve any extra function even if requested to LORA_DIO3 value is never used in src (as we are not using RF95), so no // need to define, and DIO3_AS_TCXO_AT_1V8 is set so it cannot serve any extra function even if requested to (from 13.3.2.1 // DioxMask in SX1262 datasheet: Note that if DIO2 or DIO3 are used to control the RF Switch or the TCXO, the IRQ will not be -// generated even if it is mapped to the pins.) \ No newline at end of file +// generated even if it is mapped to the pins.)