diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b01111fd..6e6f8e66 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,6 +36,7 @@ jobs: - name: Integration test run: | .pio/build/native/program & - sleep 1 + sleep 5 + echo "Simulator started, launching python test..." python3 -c 'from meshtastic.test import testSimulator; testSimulator()' diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1381bb27..c4ee9541 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -14,17 +14,14 @@ - - - + - @@ -49,7 +46,7 @@ - + @@ -63,9 +60,9 @@ - + - @@ -96,6 +93,10 @@ + + + + @@ -117,18 +118,23 @@ - - file://$PROJECT_DIR$/src/mesh/StreamAPI.cpp - 20 - file://$PROJECT_DIR$/src/mesh/wifi/WiFiServerAPI.cpp 53 + + file://$PROJECT_DIR$/src/mesh/wifi/WiFiServerAPI.cpp + 37 + + + + + + diff --git a/docs/software/TODO.md b/docs/software/TODO.md index 828f4f93..435e1049 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -4,9 +4,20 @@ You probably don't care about this section - skip to the next one. ## before next release +* test github actions locally on linux +* fix github actions per sasha tip +* @havealoha comments about odd sleep behavior +* fix heltec battery scaling +* DONE sendtext busted in portduino, due to bytetime calculations +* remove linux dependency in native build +* DONE tcp stream problem in python+pordtuino, server thinks client dropped when client DID NOT DROP +* DONE TCP mode for android, localhost is at 10.0.2.2 +* make sure USB still works in android +* add portduino builds to zip +* add license to portduino and make announcement * DONE naks are being dropped (though enqueuedLocal) sometimes before phone/PC gets them * DONE have android fill in if local GPS has poor signal -* fix heltec battery scaling +* release to beta and amazon * add reference counting to mesh packets * allow multiple simultanteous phoneapi connections * DONE split position.time and last_heard @@ -38,6 +49,10 @@ You probably don't care about this section - skip to the next one. ## MQTT +* do initial development inside of portduino +* do as much possible on the device side (so we can eventually just have ESP32 talk directly to server) +* eventually add a MQTTPacket on the ToRadio & FromRadio links + ## Multichannel support * DONE cleanup the external notification and serial plugins @@ -138,6 +153,7 @@ You probably don't care about this section - skip to the next one. For app cleanup: +* don't store redundant User admin or position broadcasts in the ToPhone queue (only keep one per sending node per proto type, and only most recent) * use structured logging to kep logs in ram. Also send logs as packets to api clients * DONE writeup nice python options docs (common cases, link to protobuf docs) * have android app link to user manual diff --git a/platformio.ini b/platformio.ini index 519da9c3..92f0f69a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -110,7 +110,7 @@ lib_deps = # board_build.ldscript = linker/esp32.extram.bss.ld lib_ignore = segger_rtt platform_packages = - framework-arduinoespressif32@https://github.com/meshtastic/arduino-esp32.git#352c8ea7cb73f10433ed139f34251979c470ad56 + framework-arduinoespressif32@https://github.com/meshtastic/arduino-esp32.git#4cde0f5d412d2695184f32e8a47e9bea57b45276 ; leave this commented out to avoid breaking Windows upload_port = /dev/ttyUSB0 diff --git a/proto b/proto index 0ea23280..5cb09ec9 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 0ea232802651fd6aaa53c93c09f4c2eb36470dd0 +Subproject commit 5cb09ec96321ce0cfae18141e5da3b75e001c9fe diff --git a/src/OSTimer.cpp b/src/OSTimer.cpp index 0978163c..9be4bd3d 100644 --- a/src/OSTimer.cpp +++ b/src/OSTimer.cpp @@ -40,7 +40,7 @@ bool scheduleHWCallback(PendableFunction callback, void *param1, uint32_t param2 tParam1 = param1; tParam2 = param2; - timerAlarmWrite(timer, delayMsec * 1000L, false); // Do not reload, we want it to be a single shot timer + timerAlarmWrite(timer, delayMsec * 1000UL, false); // Do not reload, we want it to be a single shot timer timerRestart(timer); timerAlarmEnable(timer); return true; diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 338412c3..e101c494 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -303,7 +303,9 @@ void PowerFSM_setup() #ifndef NRF52_SERIES // We never enter light-sleep or NB states on NRF52 (because the CPU uses so little power normally) - powerFSM.add_timed_transition(&stateDARK, &stateNB, getPref_phone_timeout_secs() * 1000, NULL, "Phone timeout"); + // I don't think this transition is correct, turning off for now - @geeksville + // powerFSM.add_timed_transition(&stateDARK, &stateNB, getPref_phone_timeout_secs() * 1000, NULL, "Phone timeout"); + powerFSM.add_timed_transition(&stateNB, &stateLS, getPref_min_wake_secs() * 1000, NULL, "Min wake timeout"); powerFSM.add_timed_transition(&stateDARK, &stateLS, getPref_wait_bluetooth_secs() * 1000, NULL, "Bluetooth timeout"); #else diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index 73600b32..d88fbe4b 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -40,7 +40,7 @@ size_t RedirectablePrint::vprintf(const char *format, va_list arg) va_end(arg); return 0; }; - if (len >= printBufLen) { + if (len >= (int)printBufLen) { delete[] printBuf; printBufLen *= 2; printBuf = new char[printBufLen]; diff --git a/src/concurrency/BinarySemaphorePosix.h b/src/concurrency/BinarySemaphorePosix.h index 8a636867..475b2987 100644 --- a/src/concurrency/BinarySemaphorePosix.h +++ b/src/concurrency/BinarySemaphorePosix.h @@ -1,6 +1,5 @@ #pragma once -#include "configuration.h" #include "../freertosinc.h" namespace concurrency @@ -28,4 +27,4 @@ class BinarySemaphorePosix #endif -} \ No newline at end of file +} // namespace concurrency \ No newline at end of file diff --git a/src/gps/RTC.cpp b/src/gps/RTC.cpp index 87b73ce8..5f6a54c5 100644 --- a/src/gps/RTC.cpp +++ b/src/gps/RTC.cpp @@ -39,7 +39,7 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv) currentQuality = q; shouldSet = true; DEBUG_MSG("Upgrading time to RTC %ld secs (quality %d)\n", tv->tv_sec, q); - } else if(q == RTCQualityGPS && (now - lastSetMsec) > (12 * 60 * 60 * 1000L)) { + } else if(q == RTCQualityGPS && (now - lastSetMsec) > (12 * 60 * 60 * 1000UL)) { // Every 12 hrs we will slam in a new GPS time, to correct for local RTC clock drift shouldSet = true; DEBUG_MSG("Reapplying external time to correct clock drift %ld secs\n", tv->tv_sec); diff --git a/src/main.cpp b/src/main.cpp index 1bd94221..25e5e15c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -317,7 +317,7 @@ void setup() #endif #ifdef DEBUG_PORT - if (radioConfig.preferences.serial_disabled) { + if (!radioConfig.preferences.serial_disabled) { consoleInit(); // Set serial baud rate and init our mesh console } #endif diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index db039afb..018ab6d3 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -15,7 +15,10 @@ #error ToRadio is too big #endif -PhoneAPI::PhoneAPI() {} +PhoneAPI::PhoneAPI() +{ + lastContactMsec = millis(); +} PhoneAPI::~PhoneAPI() { @@ -53,9 +56,12 @@ void PhoneAPI::close() void PhoneAPI::checkConnectionTimeout() { if (isConnected()) { - bool newConnected = (millis() - lastContactMsec < getPref_phone_timeout_secs() * 1000L); - if (!newConnected) + uint32_t now = millis(); + bool newContact = (now - lastContactMsec) < getPref_phone_timeout_secs() * 1000UL; + if (!newContact) { + DEBUG_MSG("Timed out on phone contact, dropping phone connection\n"); close(); + } } } diff --git a/src/mesh/RF95Interface.cpp b/src/mesh/RF95Interface.cpp index a94a8d12..e99ec2e3 100644 --- a/src/mesh/RF95Interface.cpp +++ b/src/mesh/RF95Interface.cpp @@ -36,8 +36,6 @@ bool RF95Interface::init() { RadioLibInterface::init(); - applyModemConfig(); - if (power == 0) power = POWER_DEFAULT; @@ -86,24 +84,25 @@ void INTERRUPT_ATTR RF95Interface::disableInterrupt() lora->clearDio0Action(); } - - bool RF95Interface::reconfigure() { - applyModemConfig(); + RadioLibInterface::reconfigure(); // set mode to standby setStandby(); // configure publicly accessible settings int err = lora->setSpreadingFactor(sf); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora->setBandwidth(bw); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora->setCodingRate(cr); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora->setSyncWord(syncWord); assert(err == ERR_NONE); @@ -115,12 +114,14 @@ bool RF95Interface::reconfigure() assert(err == ERR_NONE); err = lora->setFrequency(freq); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); if (power > MAX_POWER) // This chip has lower power limits than some power = MAX_POWER; err = lora->setOutputPower(power); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); startReceive(); // restart receiving diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 0ee23529..24cb8d73 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -1,12 +1,12 @@ -#include "configuration.h" #include "RadioInterface.h" #include "Channels.h" #include "MeshRadio.h" #include "MeshService.h" #include "NodeDB.h" -#include "assert.h" #include "Router.h" +#include "assert.h" +#include "configuration.h" #include "sleep.h" #include #include @@ -31,8 +31,8 @@ const RegionInfo regions[] = { /* Notes about the RU bandplan (from @denis-d in https://meshtastic.discourse.group/t/russian-band-plan-proposal/2786/2): -According to Annex 12 to GKRCh (National Radio Frequency Commission) decision № 18-46-03-1 (September 11th 2018) https://digital.gov.ru/uploaded/files/prilozhenie-12-k-reshenyu-gkrch-18-46-03-1.pdf 1 -We have 3 options for 868 MHz: +According to Annex 12 to GKRCh (National Radio Frequency Commission) decision № 18-46-03-1 (September 11th 2018) +https://digital.gov.ru/uploaded/files/prilozhenie-12-k-reshenyu-gkrch-18-46-03-1.pdf 1 We have 3 options for 868 MHz: 864,0 - 865,0 MHz ERP 25mW, Duty Cycle 0.1% (3.6 sec in hour) or LBT (Listen Before Talk), prohibited in airports. 866,0 - 868,0 MHz ERP 25mW, Duty Cycle 1% or LBT, PSD (Power Spectrum Density) 1000mW/MHz, prohibited in airports @@ -112,6 +112,8 @@ uint32_t RadioInterface::getPacketTime(MeshPacket *p) /** The delay to use for retransmitting dropped packets */ uint32_t RadioInterface::getRetransmissionMsec(const MeshPacket *p) { + assert(shortPacketMsec); // Better be non zero + // was 20 and 22 secs respectively, but now with shortPacketMsec as 2269, this should give the same range return random(9 * shortPacketMsec, 10 * shortPacketMsec); } @@ -153,7 +155,7 @@ void printPacket(const char *prefix, const MeshPacket *p) if (s.dest != 0) DEBUG_MSG(" dest=%08x", s.dest); - if(s.request_id) + if (s.request_id) DEBUG_MSG(" requestId=%0x", s.request_id); /* now inside Data and therefore kinda opaque @@ -185,6 +187,12 @@ RadioInterface::RadioInterface() // DEBUG_MSG("Set meshradio defaults name=%s\n", channelSettings.name); } +bool RadioInterface::reconfigure() +{ + applyModemConfig(); + return true; +} + bool RadioInterface::init() { DEBUG_MSG("Starting meshradio init...\n"); @@ -197,6 +205,8 @@ bool RadioInterface::init() // radioIf.setThisAddress(nodeDB.getNodeNum()); // Note: we must do this here, because the nodenum isn't inited at constructor // time. + applyModemConfig(); + return true; } diff --git a/src/mesh/RadioInterface.h b/src/mesh/RadioInterface.h index 9d19fa59..778ce251 100644 --- a/src/mesh/RadioInterface.h +++ b/src/mesh/RadioInterface.h @@ -104,7 +104,11 @@ class RadioInterface virtual bool sleep() { return true; } /// Disable this interface (while disabled, no packets can be sent or received) - void disable() { disabled = true; sleep(); } + void disable() + { + disabled = true; + sleep(); + } /** * Send a packet (possibly by enquing in a private fifo). This routine will @@ -126,7 +130,7 @@ class RadioInterface /// Apply any radio provisioning changes /// Make sure the Driver is properly configured before calling init(). /// \return true if initialisation succeeded. - virtual bool reconfigure() = 0; + virtual bool reconfigure(); /** The delay to use for retransmitting dropped packets */ uint32_t getRetransmissionMsec(const MeshPacket *p); @@ -174,13 +178,6 @@ class RadioInterface */ void limitPower(); - /** - * Convert our modemConfig enum into wf, sf, etc... - * - * These paramaters will be pull from the channelSettings global - */ - virtual void applyModemConfig(); - /** * Save the frequency we selected for later reuse. */ @@ -192,6 +189,13 @@ class RadioInterface virtual void saveChannelNum(uint32_t savedChannelNum); private: + /** + * Convert our modemConfig enum into wf, sf, etc... + * + * These paramaters will be pull from the channelSettings global + */ + void applyModemConfig(); + /// Return 0 if sleep is okay int preflightSleepCb(void *unused = NULL) { return canSleep() ? 0 : 1; } @@ -208,18 +212,6 @@ class SimRadio : public RadioInterface { public: virtual ErrorCode send(MeshPacket *p); - - // methods from radiohead - - /// Initialise the Driver transport hardware and software. - /// Make sure the Driver is properly configured before calling init(). - /// \return true if initialisation succeeded. - virtual bool init() { return true; } - - /// Apply any radio provisioning changes - /// Make sure the Driver is properly configured before calling init(). - /// \return true if initialisation succeeded. - virtual bool reconfigure() { return true; } }; /// Debug printing for packets diff --git a/src/mesh/SX1262Interface.cpp b/src/mesh/SX1262Interface.cpp index ad35d700..2a68bca3 100644 --- a/src/mesh/SX1262Interface.cpp +++ b/src/mesh/SX1262Interface.cpp @@ -23,8 +23,6 @@ bool SX1262Interface::init() pinMode(SX1262_POWER_EN, OUTPUT); #endif - RadioLibInterface::init(); - #ifdef SX1262_RXEN // set not rx or tx mode digitalWrite(SX1262_RXEN, LOW); // Set low before becoming an output pinMode(SX1262_RXEN, OUTPUT); @@ -38,11 +36,11 @@ bool SX1262Interface::init() float tcxoVoltage = 0; // None - we use an XTAL #else // Use DIO3 to power tcxo per https://github.com/jgromes/RadioLib/issues/12#issuecomment-520695575 - float tcxoVoltage = 1.8; + float tcxoVoltage = 1.8; #endif bool useRegulatorLDO = false; // Seems to depend on the connection to pin 9/DCC_SW - if an inductor DCDC? - applyModemConfig(); + RadioLibInterface::init(); if (power == 0) power = SX1262_MAX_POWER; @@ -72,20 +70,23 @@ bool SX1262Interface::init() bool SX1262Interface::reconfigure() { - applyModemConfig(); + RadioLibInterface::reconfigure(); // set mode to standby setStandby(); // configure publicly accessible settings int err = lora.setSpreadingFactor(sf); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora.setBandwidth(bw); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora.setCodingRate(cr); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); // Hmm - seems to lower SNR when the signal levels are high. Leaving off for now... err = lora.setRxGain(true); @@ -101,7 +102,8 @@ bool SX1262Interface::reconfigure() assert(err == ERR_NONE); err = lora.setFrequency(freq); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); if (power > 22) // This chip has lower power limits than some power = 22;