From acc32916c3c7b6ac36a0c9d6c23ff1a448ab69d8 Mon Sep 17 00:00:00 2001 From: Jim Whitelaw Date: Mon, 25 Mar 2024 05:33:57 -0600 Subject: [PATCH] Add multiple configuration options for a minimized build (GPS,WiFi,BT,MQTT,Screen). (#3469) Co-authored-by: Ben Meadors --- .vscode/extensions.json | 2 +- src/ButtonThread.cpp | 8 +++-- src/Power.cpp | 4 ++- src/configuration.h | 54 ++++++++++++++++++++++++------- src/gps/GPS.cpp | 9 ++++-- src/gps/GPS.h | 5 ++- src/gps/NMEAWPL.cpp | 5 ++- src/graphics/Screen.cpp | 13 ++++++-- src/main.cpp | 37 +++++++++++++++------ src/main.h | 1 + src/mesh/Channels.cpp | 6 ++++ src/mesh/MeshService.cpp | 21 ++++++++---- src/mesh/MeshService.h | 6 ++-- src/mesh/NodeDB.cpp | 9 ++++-- src/mesh/PhoneAPI.cpp | 14 +++++--- src/mesh/Router.cpp | 11 ++++--- src/mesh/eth/ethClient.cpp | 6 +++- src/mesh/http/ContentHandler.cpp | 2 ++ src/mesh/http/WebServer.cpp | 4 +-- src/mesh/wifi/WiFiAPClient.cpp | 11 +++++-- src/mesh/wifi/WiFiAPClient.h | 2 +- src/modules/AdminModule.cpp | 8 +++-- src/modules/AdminModule.h | 2 +- src/modules/Modules.cpp | 12 ++++--- src/modules/PositionModule.cpp | 5 ++- src/modules/SerialModule.cpp | 9 +++--- src/mqtt/MQTT.cpp | 3 +- src/nimble/NimbleBluetooth.cpp | 7 ++-- src/platform/esp32/main-esp32.cpp | 14 +++++--- src/platform/nrf52/main-nrf52.cpp | 5 ++- src/sleep.cpp | 16 ++++++--- 31 files changed, 225 insertions(+), 86 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 4fc84fa780..783791f0ba 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -6,4 +6,4 @@ "platformio.platformio-ide", "trunk.io" ], -} +} \ No newline at end of file diff --git a/src/ButtonThread.cpp b/src/ButtonThread.cpp index 84d4332852..a1f0170e82 100644 --- a/src/ButtonThread.cpp +++ b/src/ButtonThread.cpp @@ -1,10 +1,12 @@ #include "ButtonThread.h" +#include "configuration.h" +#if !MESHTASTIC_EXCLUDE_GPS #include "GPS.h" +#endif #include "MeshService.h" #include "PowerFSM.h" #include "RadioLibInterface.h" #include "buzz.h" -#include "graphics/Screen.h" #include "main.h" #include "modules/ExternalNotificationModule.h" #include "power.h" @@ -145,7 +147,7 @@ int32_t ButtonThread::runOnce() screen->print("Sent ad-hoc ping\n"); break; } - +#if HAS_GPS case BUTTON_EVENT_MULTI_PRESSED: { LOG_BUTTON("Multi press!\n"); if (!config.device.disable_triple_click && (gps != nullptr)) { @@ -155,7 +157,7 @@ int32_t ButtonThread::runOnce() } break; } - +#endif case BUTTON_EVENT_LONG_PRESSED: { LOG_BUTTON("Long press!\n"); powerFSM.trigger(EVENT_PRESS); diff --git a/src/Power.cpp b/src/Power.cpp index 71554daa3a..779e32ff56 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -24,11 +24,13 @@ #include "nrfx_power.h" #endif -#ifdef DEBUG_HEAP_MQTT +#if defined(DEBUG_HEAP_MQTT) && !MESHTASTIC_EXCLUDE_MQTT #include "mqtt/MQTT.h" #include "target_specific.h" +#if !MESTASTIC_EXCLUDE_WIFI #include #endif +#endif #ifndef DELAY_FOREVER #define DELAY_FOREVER portMAX_DELAY diff --git a/src/configuration.h b/src/configuration.h index c3dd2cb067..7ce1a0b8b3 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -171,17 +171,6 @@ along with this program. If not, see . /* Step #3: mop up with disabled values for HAS_ options not handled by the above two */ -// ----------------------------------------------------------------------------- -// GPS -// ----------------------------------------------------------------------------- - -#ifndef GPS_BAUDRATE -#define GPS_BAUDRATE 9600 -#endif -#ifndef GPS_THREAD_INTERVAL -#define GPS_THREAD_INTERVAL 100 -#endif - #ifndef HAS_WIFI #define HAS_WIFI 0 #endif @@ -232,7 +221,21 @@ along with this program. If not, see . #error HW_VENDOR must be defined #endif -// global switch to turn off all optional modules for a minimzed build +// ----------------------------------------------------------------------------- +// Global switches to turn off features for a minimized build +// ----------------------------------------------------------------------------- + +// #define MESHTASTIC_MINIMIZE_BUILD 1 +#ifdef MESHTASTIC_MINIMIZE_BUILD +#define MESHTASTIC_EXCLUDE_MODULES 1 +#define MESHTASTIC_EXCLUDE_WIFI 1 +#define MESHTASTIC_EXCLUDE_BLUETOOTH 1 +#define MESHTASTIC_EXCLUDE_GPS 1 +#define MESHTASTIC_EXCLUDE_SCREEN 1 +#define MESHTASTIC_EXCLUDE_MQTT 1 +#endif + +// Turn off all optional modules #ifdef MESHTASTIC_EXCLUDE_MODULES #define MESHTASTIC_EXCLUDE_AUDIO 1 #define MESHTASTIC_EXCLUDE_DETECTIONSENSOR 1 @@ -251,3 +254,30 @@ along with this program. If not, see . #define MESHTASTIC_EXCLUDE_INPUTBROKER 1 #define MESHTASTIC_EXCLUDE_SERIAL 1 #endif + +// // Turn off wifi even if HW supports wifi (webserver relies on wifi and is also disabled) +#ifdef MESHTASTIC_EXCLUDE_WIFI +#define MESHTASTIC_EXCLUDE_WEBSERVER 1 +#undef HAS_WIFI +#define HAS_WIFI 0 +#endif + +// // Turn off Bluetooth +#ifdef MESHTASTIC_EXCLUDE_BLUETOOTH +#undef HAS_BLUETOOTH +#define HAS_BLUETOOTH 0 +#endif + +// // Turn off GPS +#ifdef MESHTASTIC_EXCLUDE_GPS +#undef HAS_GPS +#define HAS_GPS 0 +#undef MESHTASTIC_EXCLUDE_RANGETEST +#define MESHTASTIC_EXCLUDE_RANGETEST 1 +#endif + +// Turn off Screen +#ifdef MESHTASTIC_EXCLUDE_SCREEN +#undef HAS_SCREEN +#define HAS_SCREEN 0 +#endif diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index df1d40fdf9..a6f68f2efb 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -1,8 +1,10 @@ -#include "GPS.h" +#include "configuration.h" +#if !MESHTASTIC_EXCLUDE_GPS #include "Default.h" +#include "GPS.h" #include "NodeDB.h" #include "RTC.h" -#include "configuration.h" + #include "main.h" // pmu_found #include "sleep.h" #include "ubx.h" @@ -1481,4 +1483,5 @@ void GPS::toggleGpsMode() LOG_DEBUG("Flag set to true to restore power. GpsMode: ENABLED\n"); enable(); } -} \ No newline at end of file +} +#endif // Exclude GPS \ No newline at end of file diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 502763bb63..49f27e29fe 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -1,4 +1,6 @@ #pragma once +#include "configuration.h" +#if !MESHTASTIC_EXCLUDE_GPS #include "GPSStatus.h" #include "Observer.h" @@ -268,4 +270,5 @@ class GPS : private concurrency::OSThread GnssModel_t gnssModel = GNSS_MODEL_UNKNOWN; }; -extern GPS *gps; \ No newline at end of file +extern GPS *gps; +#endif // Exclude GPS \ No newline at end of file diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index 9eff4d00e2..cdac3bb27e 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -1,3 +1,4 @@ +#if !MESHTASTIC_EXCLUDE_GPS #include "NMEAWPL.h" #include "GeoCoord.h" #include "RTC.h" @@ -93,4 +94,6 @@ uint32_t printGGA(char *buf, size_t bufsz, const meshtastic_Position &pos) } len += snprintf(buf + len, bufsz - len, "*%02X\r\n", chk); return len; -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 3c3777496b..2453faec96 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -25,7 +25,9 @@ along with this program. If not, see . #include #include "DisplayFormatters.h" +#if !MESHTASTIC_EXCLUDE_GPS #include "GPS.h" +#endif #include "MeshService.h" #include "NodeDB.h" #include "error.h" @@ -92,8 +94,10 @@ std::vector moduleFrames; // Stores the last 4 of our hardware ID, to make finding the device for pairing easier static char ourId[5]; +#if HAS_GPS // GeoCoord object for the screen GeoCoord geoCoord; +#endif #ifdef SHOW_REDRAWS static bool heartbeat = false; @@ -483,7 +487,7 @@ static void drawNodes(OLEDDisplay *display, int16_t x, int16_t y, const NodeStat if (config.display.heading_bold) display->drawString(x + 11, y - 2, usersString); } - +#if HAS_GPS // Draw GPS status summary static void drawGPS(OLEDDisplay *display, int16_t x, int16_t y, const GPSStatus *gps) { @@ -625,7 +629,7 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const } } } - +#endif namespace { @@ -1542,6 +1546,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 } else { drawNodes(display, x + (SCREEN_WIDTH * 0.25), y + 3, nodeStatus); } +#if HAS_GPS // Display GPS status if (config.position.gps_mode != meshtastic_Config_PositionConfig_GpsMode_ENABLED) { drawGPSpowerstat(display, x, y + 2, gpsStatus); @@ -1552,7 +1557,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 drawGPS(display, x + (SCREEN_WIDTH * 0.63), y + 3, gpsStatus); } } - +#endif display->setColor(WHITE); // Draw the channel name display->drawString(x, y + FONT_HEIGHT_SMALL, channelStr); @@ -1771,6 +1776,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat char chUtil[13]; snprintf(chUtil, sizeof(chUtil), "ChUtil %2.0f%%", airTime->channelUtilizationPercent()); display->drawString(x + SCREEN_WIDTH - display->getStringWidth(chUtil), y + FONT_HEIGHT_SMALL * 1, chUtil); +#if HAS_GPS if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED) { // Line 3 if (config.display.gps_format != @@ -1782,6 +1788,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat } else { drawGPSpowerstat(display, x, y + FONT_HEIGHT_SMALL * 2, gpsStatus); } +#endif /* Display a heartbeat pixel that blinks every time the frame is redrawn */ #ifdef SHOW_REDRAWS if (heartbeat) diff --git a/src/main.cpp b/src/main.cpp index f7d1a4bc0e..0c45e903a3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,7 @@ +#include "configuration.h" +#if !MESHTASTIC_EXCLUDE_GPS #include "GPS.h" +#endif #include "MeshRadio.h" #include "MeshService.h" #include "NodeDB.h" @@ -6,7 +9,7 @@ #include "ReliableRouter.h" #include "airtime.h" #include "buzz.h" -#include "configuration.h" + #include "error.h" #include "power.h" // #include "debug.h" @@ -36,9 +39,11 @@ #if !MESHTASTIC_EXCLUDE_WEBSERVER #include "mesh/http/WebServer.h" #endif +#if !MESHTASTIC_EXCLUDE_BLUETOOTH #include "nimble/NimbleBluetooth.h" NimbleBluetooth *nimbleBluetooth; #endif +#endif #ifdef ARCH_NRF52 #include "NRF52Bluetooth.h" @@ -54,16 +59,21 @@ NRF52Bluetooth *nrf52Bluetooth; #include "mesh/api/ethServerAPI.h" #include "mesh/eth/ethClient.h" #endif + +#if !MESHTASTIC_EXCLUDE_MQTT #include "mqtt/MQTT.h" +#endif #include "LLCC68Interface.h" #include "RF95Interface.h" #include "SX1262Interface.h" #include "SX1268Interface.h" #include "SX1280Interface.h" + #ifdef ARCH_STM32WL #include "STM32WLE5JCInterface.h" #endif + #if !HAS_RADIO && defined(ARCH_PORTDUINO) #include "platform/portduino/SimRadio.h" #endif @@ -80,6 +90,7 @@ NRF52Bluetooth *nrf52Bluetooth; #if HAS_BUTTON || defined(ARCH_PORTDUINO) #include "ButtonThread.h" #endif + #include "PowerFSMThread.h" #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) @@ -640,16 +651,21 @@ void setup() readFromRTC(); // read the main CPU RTC at first (in case we can't get GPS time) +#if !MESHTASTIC_EXCLUDE_GPS // If we're taking on the repeater role, ignore GPS - if (config.device.role != meshtastic_Config_DeviceConfig_Role_REPEATER && - config.position.gps_mode != meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT) { - gps = GPS::createGps(); - } - if (gps) { - gpsStatus->observe(&gps->newStatus); - } else { - LOG_DEBUG("Running without GPS.\n"); + if (HAS_GPS) { + if (config.device.role != meshtastic_Config_DeviceConfig_Role_REPEATER && + config.position.gps_mode != meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT) { + gps = GPS::createGps(); + if (gps) { + gpsStatus->observe(&gps->newStatus); + } else { + LOG_DEBUG("Running without GPS.\n"); + } + } } +#endif + nodeStatus->observe(&nodeDB->newStatus); #ifdef HAS_I2S @@ -852,9 +868,12 @@ void setup() } } +#if !MESHTASTIC_EXCLUDE_MQTT mqttInit(); +#endif #ifndef ARCH_PORTDUINO + // Initialize Wifi #if HAS_WIFI initWifi(); diff --git a/src/main.h b/src/main.h index 5af0b40827..132fd190be 100644 --- a/src/main.h +++ b/src/main.h @@ -54,6 +54,7 @@ extern int TCPPort; // set by Portduino // Global Screen singleton. extern graphics::Screen *screen; + // extern Observable newPowerStatus; //TODO: move this to main-esp32.cpp somehow or a helper class // extern meshtastic::PowerStatus *powerStatus; diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index 840e65bca8..079af4eca0 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -7,7 +7,9 @@ #include +#if !MESHTASTIC_EXCLUDE_MQTT #include "mqtt/MQTT.h" +#endif /// 16 bytes of random PSK for our _public_ default channel that all devices power up on (AES128) static const uint8_t defaultpsk[] = {0xd4, 0xf1, 0xbb, 0x3a, 0x20, 0x29, 0x07, 0x59, @@ -18,7 +20,9 @@ Channels channels; const char *Channels::adminChannel = "admin"; const char *Channels::gpioChannel = "gpio"; const char *Channels::serialChannel = "serial"; +#if !MESHTASTIC_EXCLUDE_MQTT const char *Channels::mqttChannel = "mqtt"; +#endif uint8_t xorHash(const uint8_t *p, size_t len) { @@ -195,10 +199,12 @@ void Channels::onConfigChanged() if (ch.role == meshtastic_Channel_Role_PRIMARY) primaryIndex = i; } +#if !MESHTASTIC_EXCLUDE_MQTT if (channels.anyMqttEnabled() && mqtt && !mqtt->isEnabled()) { LOG_DEBUG("MQTT is enabled on at least one channel, so set MQTT thread to run immediately\n"); mqtt->start(); } +#endif } meshtastic_Channel &Channels::getByIndex(ChannelIndex chIndex) diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 2df5d57976..2c1969e305 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -1,10 +1,11 @@ #include "configuration.h" -#include -#include + +#if !MESHTASTIC_EXCLUDE_GPS +#include "GPS.h" +#endif #include "../concurrency/Periodic.h" #include "BluetoothCommon.h" // needed for updateBatteryLevel, FIXME, eventually when we pull mesh out into a lib we shouldn't be whacking bluetooth from here -#include "GPS.h" #include "MeshService.h" #include "NodeDB.h" #include "PowerFSM.h" @@ -15,8 +16,10 @@ #include "modules/NodeInfoModule.h" #include "modules/PositionModule.h" #include "power.h" +#include +#include -#ifdef ARCH_ESP32 +#if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_BLUETOOTH #include "nimble/NimbleBluetooth.h" #endif @@ -71,10 +74,11 @@ MeshService::MeshService() void MeshService::init() { // moved much earlier in boot (called from setup()) - // nodeDB->init(); - + // nodeDB.init(); +#if HAS_GPS if (gps) gpsObserver.observe(&gps->newStatus); +#endif } int MeshService::handleFromRadio(const meshtastic_MeshPacket *mp) @@ -270,11 +274,13 @@ void MeshService::sendNetworkPing(NodeNum dest, bool wantReplies) assert(node); if (hasValidPosition(node)) { +#if HAS_GPS if (positionModule) { LOG_INFO("Sending position ping to 0x%x, wantReplies=%d, channel=%d\n", dest, wantReplies, node->channel); positionModule->sendOurPosition(dest, wantReplies, node->channel); } } else { +#endif if (nodeInfoModule) { LOG_INFO("Sending nodeinfo ping to 0x%x, wantReplies=%d, channel=%d\n", dest, wantReplies, node->channel); nodeInfoModule->sendOurNodeInfo(dest, wantReplies, node->channel); @@ -344,6 +350,7 @@ meshtastic_NodeInfoLite *MeshService::refreshLocalMeshNode() return node; } +#if HAS_GPS int MeshService::onGPSChanged(const meshtastic::GPSStatus *newStatus) { // Update our local node info with our position (even if we don't decide to update anyone else) @@ -377,7 +384,7 @@ int MeshService::onGPSChanged(const meshtastic::GPSStatus *newStatus) return 0; } - +#endif bool MeshService::isToPhoneQueueEmpty() { return toPhoneQueue.isEmpty(); diff --git a/src/mesh/MeshService.h b/src/mesh/MeshService.h index 68287efc23..8d1434030d 100644 --- a/src/mesh/MeshService.h +++ b/src/mesh/MeshService.h @@ -23,9 +23,10 @@ extern Allocator &mqttClientProxyMessagePool; */ class MeshService { +#if HAS_GPS CallbackObserver gpsObserver = CallbackObserver(this, &MeshService::onGPSChanged); - +#endif /// received packets waiting for the phone to process them /// FIXME, change to a DropOldestQueue and keep a count of the number of dropped packets to ensure /// we never hang because android hasn't been there in a while @@ -132,10 +133,11 @@ class MeshService ErrorCode sendQueueStatusToPhone(const meshtastic_QueueStatus &qs, ErrorCode res, uint32_t mesh_packet_id); private: +#if HAS_GPS /// Called when our gps position has changed - updates nodedb and sends Location message out into the mesh /// returns 0 to allow further processing int onGPSChanged(const meshtastic::GPSStatus *arg); - +#endif /// Handle a packet that just arrived from the radio. This method does _ReliableRouternot_ free the provided packet. If it /// needs to keep the packet around it makes a copy int handleFromRadio(const meshtastic_MeshPacket *p); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 3734309be5..262b0e0397 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -1,11 +1,12 @@ #include "configuration.h" - +#if !MESHTASTIC_EXCLUDE_GPS +#include "GPS.h" +#endif #include "../detect/ScanI2C.h" #include "Channels.h" #include "CryptoEngine.h" #include "Default.h" #include "FSCommon.h" -#include "GPS.h" #include "MeshRadio.h" #include "NodeDB.h" #include "PacketHistory.h" @@ -25,7 +26,9 @@ #include #ifdef ARCH_ESP32 +#if !MESHTASTIC_EXCLUDE_WIFI #include "mesh/wifi/WiFiAPClient.h" +#endif #include "modules/esp32/StoreForwardModule.h" #include #include @@ -230,7 +233,7 @@ void NodeDB::installDefaultConfig() config.has_position = true; config.has_power = true; config.has_network = true; - config.has_bluetooth = true; + config.has_bluetooth = (HAS_BLUETOOTH ? true : false); config.device.rebroadcast_mode = meshtastic_Config_DeviceConfig_RebroadcastMode_ALL; config.lora.sx126x_rx_boosted_gain = true; diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 48f7eb9403..f2d2a6e9d8 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -1,13 +1,16 @@ -#include "PhoneAPI.h" +#include "configuration.h" +#if !MESHTASTIC_EXCLUDE_GPS +#include "GPS.h" +#endif + #include "Channels.h" #include "Default.h" -#include "GPS.h" #include "MeshService.h" #include "NodeDB.h" +#include "PhoneAPI.h" #include "PowerFSM.h" #include "RadioInterface.h" #include "TypeConversions.h" -#include "configuration.h" #include "main.h" #include "xmodem.h" @@ -18,8 +21,9 @@ #if ToRadio_size > MAX_TO_FROM_RADIO_SIZE #error ToRadio is too big #endif - +#if !MESHTASTIC_EXCLUDE_MQTT #include "mqtt/MQTT.h" +#endif PhoneAPI::PhoneAPI() { @@ -104,6 +108,7 @@ bool PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength) LOG_INFO("Got xmodem packet\n"); xModem.handlePacket(toRadioScratch.xmodemPacket); break; +#if !MESHTASTIC_EXCLUDE_MQTT case meshtastic_ToRadio_mqttClientProxyMessage_tag: LOG_INFO("Got MqttClientProxy message\n"); if (mqtt && moduleConfig.mqtt.proxy_to_client_enabled && moduleConfig.mqtt.enabled && @@ -114,6 +119,7 @@ bool PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength) "not enabled\n"); } break; +#endif case meshtastic_ToRadio_heartbeat_tag: LOG_DEBUG("Got client heartbeat\n"); break; diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 7894b1b922..266c4f78d4 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -11,9 +11,9 @@ extern "C" { #include "mesh/compression/unishox2.h" } - +#if !MESHTASTIC_EXCLUDE_MQTT #include "mqtt/MQTT.h" - +#endif /** * Router todo * @@ -261,11 +261,12 @@ ErrorCode Router::send(meshtastic_MeshPacket *p) abortSendAndNak(encodeResult, p); return encodeResult; // FIXME - this isn't a valid ErrorCode } - +#if !MESHTASTIC_EXCLUDE_MQTT // Only publish to MQTT if we're the original transmitter of the packet if (moduleConfig.mqtt.enabled && p->from == nodeDB->getNodeNum() && mqtt) { mqtt->onSend(*p, *p_decoded, chIndex); } +#endif packetPool.release(p_decoded); } @@ -465,10 +466,12 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) cancelSending(p->from, p->id); skipHandle = true; } - +#if !MESHTASTIC_EXCLUDE_MQTT // Publish received message to MQTT if we're not the original transmitter of the packet if (!skipHandle && moduleConfig.mqtt.enabled && getFrom(p) != nodeDB->getNodeNum() && mqtt) mqtt->onSend(*p_encrypted, *p, p->channel); +#endif + } else { printPacket("packet decoding failed or skipped (no PSK?)", p); } diff --git a/src/mesh/eth/ethClient.cpp b/src/mesh/eth/ethClient.cpp index 97f5027bd1..5373f243e6 100644 --- a/src/mesh/eth/ethClient.cpp +++ b/src/mesh/eth/ethClient.cpp @@ -2,9 +2,12 @@ #include "NodeDB.h" #include "RTC.h" #include "concurrency/Periodic.h" +#include "configuration.h" #include "main.h" #include "mesh/api/ethServerAPI.h" +#if !MESHTASTIC_EXCLUDE_MQTT #include "mqtt/MQTT.h" +#endif #include "target_specific.h" #include #include @@ -66,11 +69,12 @@ static int32_t reconnectETH() ethStartupComplete = true; } - +#if !MESHTASTIC_EXCLUDE_MQTT // FIXME this is kinda yucky, instead we should just have an observable for 'wifireconnected' if (mqtt && !moduleConfig.mqtt.proxy_to_client_enabled && !mqtt->isConnectedDirectly()) { mqtt->reconnect(); } +#endif } #ifndef DISABLE_NTP diff --git a/src/mesh/http/ContentHandler.cpp b/src/mesh/http/ContentHandler.cpp index 1557948d8b..7f9df058dd 100644 --- a/src/mesh/http/ContentHandler.cpp +++ b/src/mesh/http/ContentHandler.cpp @@ -6,7 +6,9 @@ #include "main.h" #include "mesh/http/ContentHelper.h" #include "mesh/http/WebServer.h" +#if !MESHTASTIC_EXCLUDE_WIFI #include "mesh/wifi/WiFiAPClient.h" +#endif #include "mqtt/JSON.h" #include "power.h" #include "sleep.h" diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index 83fe20dd85..fc8535257b 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -1,14 +1,14 @@ +#include "configuration.h" #if !MESHTASTIC_EXCLUDE_WEBSERVER -#include "mesh/http/WebServer.h" #include "NodeDB.h" #include "graphics/Screen.h" #include "main.h" +#include "mesh/http/WebServer.h" #include "mesh/wifi/WiFiAPClient.h" #include "sleep.h" #include #include #include - #include #include diff --git a/src/mesh/wifi/WiFiAPClient.cpp b/src/mesh/wifi/WiFiAPClient.cpp index 88764d2be8..1de4d7669a 100644 --- a/src/mesh/wifi/WiFiAPClient.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -1,18 +1,24 @@ -#include "mesh/wifi/WiFiAPClient.h" +#include "configuration.h" +#if !MESHTASTIC_EXCLUDE_WIFI #include "NodeDB.h" #include "RTC.h" #include "concurrency/Periodic.h" -#include "configuration.h" +#include "mesh/wifi/WiFiAPClient.h" + #include "main.h" #include "mesh/api/WiFiServerAPI.h" +#if !MESHTASTIC_EXCLUDE_MQTT #include "mqtt/MQTT.h" +#endif #include "target_specific.h" #include #include #ifdef ARCH_ESP32 #if !MESHTASTIC_EXCLUDE_WEBSERVER +#if !MESHTASTIC_EXCLUDE_WEBSERVER #include "mesh/http/WebServer.h" #endif +#endif #include #include static void WiFiEvent(WiFiEvent_t event); @@ -408,3 +414,4 @@ uint8_t getWifiDisconnectReason() { return wifiDisconnectReason; } +#endif \ No newline at end of file diff --git a/src/mesh/wifi/WiFiAPClient.h b/src/mesh/wifi/WiFiAPClient.h index 6625d3e46e..5f4e2f5c90 100644 --- a/src/mesh/wifi/WiFiAPClient.h +++ b/src/mesh/wifi/WiFiAPClient.h @@ -5,7 +5,7 @@ #include #include -#if defined(HAS_WIFI) && !defined(ARCH_PORTDUINO) +#if HAS_WIFI && !defined(ARCH_PORTDUINO) #include #endif diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index c44048fd23..50cec824dd 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -4,7 +4,7 @@ #include "NodeDB.h" #include "PowerFSM.h" #include -#ifdef ARCH_ESP32 +#if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_BLUETOOTH #include "BleOta.h" #endif #include "Router.h" @@ -18,7 +18,9 @@ #endif #include "Default.h" +#if !MESHTASTIC_EXCLUDE_MQTT #include "mqtt/MQTT.h" +#endif AdminModule *adminModule; bool hasOpenEditTransaction; @@ -119,7 +121,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } case meshtastic_AdminMessage_reboot_ota_seconds_tag: { int32_t s = r->reboot_ota_seconds; -#ifdef ARCH_ESP32 +#if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_BLUETOOTH if (BleOta::getOtaAppVersion().isEmpty()) { LOG_INFO("No OTA firmware available, scheduling regular reboot in %d seconds\n", s); screen->startRebootScreen(); @@ -666,7 +668,9 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r if (Ethernet.linkStatus() == LinkON) { conn.ethernet.status.is_connected = true; conn.ethernet.status.ip_address = Ethernet.localIP(); +#if !MESHTASTIC_EXCLUDE_MQTT conn.ethernet.status.is_mqtt_connected = mqtt && mqtt->isConnectedDirectly(); +#endif conn.ethernet.status.is_syslog_connected = false; // FIXME wire this up } else { conn.ethernet.status.is_connected = false; diff --git a/src/modules/AdminModule.h b/src/modules/AdminModule.h index 6ecc888294..32b32c253a 100644 --- a/src/modules/AdminModule.h +++ b/src/modules/AdminModule.h @@ -1,6 +1,6 @@ #pragma once #include "ProtobufModule.h" -#if HAS_WIFI +#if HAS_WIFI && !MESHTASTIC_EXCLUDE_WIFI #include "mesh/wifi/WiFiAPClient.h" #endif diff --git a/src/modules/Modules.cpp b/src/modules/Modules.cpp index 97ed90cf15..5ac45577e3 100644 --- a/src/modules/Modules.cpp +++ b/src/modules/Modules.cpp @@ -21,7 +21,9 @@ #include "modules/NeighborInfoModule.h" #endif #include "modules/NodeInfoModule.h" +#if !MESHTASTIC_EXCLUDE_GPS #include "modules/PositionModule.h" +#endif #if !MESHTASTIC_EXCLUDE_REMOTEHARDWARE #include "modules/RemoteHardwareModule.h" #endif @@ -61,15 +63,13 @@ #if !MESHTASTIC_EXCLUDE_EXTERNALNOTIFICATION #include "modules/ExternalNotificationModule.h" #endif -#if !MESHTASTIC_EXCLUDE_RANGETEST +#if !MESHTASTIC_EXCLUDE_RANGETEST && !MESHTASTIC_EXCLUDE_GPS #include "modules/RangeTestModule.h" #endif -#if (defined(ARCH_ESP32) || defined(ARCH_NRF52) || defined(ARCH_RP2040)) && !defined(CONFIG_IDF_TARGET_ESP32S2) -#if !MESHTASTIC_EXCLUDE_SERIAL +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !MESHTASTIC_EXCLUDE_SERIAL #include "modules/SerialModule.h" #endif #endif -#endif /** * Create module instances here. If you are adding a new module, you must 'new' it here (or somewhere else) */ @@ -81,7 +81,9 @@ void setupModules() #endif adminModule = new AdminModule(); nodeInfoModule = new NodeInfoModule(); +#if !MESHTASTIC_EXCLUDE_GPS positionModule = new PositionModule(); +#endif #if !MESHTASTIC_EXCLUDE_WAYPOINT waypointModule = new WaypointModule(); #endif @@ -169,7 +171,7 @@ void setupModules() #if !MESHTASTIC_EXCLUDE_EXTERNALNOTIFICATION externalNotificationModule = new ExternalNotificationModule(); #endif -#if !MESHTASTIC_EXCLUDE_RANGETEST +#if !MESHTASTIC_EXCLUDE_RANGETEST && !MESHTASTIC_EXCLUDE_GPS new RangeTestModule(); #endif #endif diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index d22c6b6994..dcfe03f7f7 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -1,3 +1,4 @@ +#if !MESHTASTIC_EXCLUDE_GPS #include "PositionModule.h" #include "Default.h" #include "GPS.h" @@ -418,4 +419,6 @@ void PositionModule::handleNewPosition() lastGpsSend = now; } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index 663bc1d86c..96a99b13e3 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -179,14 +179,14 @@ int32_t SerialModule::runOnce() } else { if (moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_PROTO) { return runOncePart(); - } else if (moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_NMEA) { + } else if ((moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_NMEA) && HAS_GPS) { // in NMEA mode send out GGA every 2 seconds, Don't read from Port if (millis() - lastNmeaTime > 2000) { lastNmeaTime = millis(); printGGA(outbuf, sizeof(outbuf), localPosition); serialPrint->printf("%s", outbuf); } - } else if (moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_CALTOPO) { + } else if ((moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_CALTOPO) && HAS_GPS) { if (millis() - lastNmeaTime > 10000) { lastNmeaTime = millis(); uint32_t readIndex = 0; @@ -295,8 +295,9 @@ ProcessMessage SerialModuleRadio::handleReceived(const meshtastic_MeshPacket &mp serialPrint->println(); serialPrint->printf("%s: %s", sender, p.payload.bytes); serialPrint->println(); - } else if (moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_NMEA || - moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_CALTOPO) { + } else if ((moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_NMEA || + moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_CALTOPO) && + HAS_GPS) { // Decode the Payload some more meshtastic_Position scratch; meshtastic_Position *decoded = NULL; diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 8e7c8f2cc1..05d5486b21 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -2,6 +2,7 @@ #include "MeshService.h" #include "NodeDB.h" #include "PowerFSM.h" +#include "configuration.h" #include "main.h" #include "mesh/Channels.h" #include "mesh/Router.h" @@ -13,7 +14,7 @@ #endif #include "mesh/generated/meshtastic/remote_hardware.pb.h" #include "sleep.h" -#if HAS_WIFI +#if HAS_WIFI && !MESHTASTIC_EXCLUDE_WIFI #include "mesh/wifi/WiFiAPClient.h" #include #endif diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index 0b2a806c9d..bc94abf6eb 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -1,7 +1,9 @@ -#include "NimbleBluetooth.h" +#include "configuration.h" +#if !MESHTASTIC_EXCLUDE_BLUETOOTH #include "BluetoothCommon.h" +#include "NimbleBluetooth.h" #include "PowerFSM.h" -#include "configuration.h" + #include "main.h" #include "mesh/PhoneAPI.h" #include "mesh/mesh-pb-constants.h" @@ -227,3 +229,4 @@ void clearNVS() ESP.restart(); #endif } +#endif \ No newline at end of file diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index f97f6d121e..3fb6e77747 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -3,11 +3,14 @@ #include "esp_task_wdt.h" #include "main.h" -#if !defined(CONFIG_IDF_TARGET_ESP32S2) +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !MESHTASTIC_EXCLUDE_BLUETOOTH +#include "BleOta.h" #include "nimble/NimbleBluetooth.h" #endif -#include "BleOta.h" + +#if !MESHTASTIC_EXCLUDE_WIFI #include "mesh/wifi/WiFiAPClient.h" +#endif #include "meshUtils.h" #include "sleep.h" @@ -18,8 +21,7 @@ #include #include -#if !defined(CONFIG_IDF_TARGET_ESP32S2) - +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !MESHTASTIC_EXCLUDE_BLUETOOTH void setBluetoothEnable(bool enable) { if (!isWifiAvailable() && config.bluetooth.enabled == true) { @@ -108,12 +110,16 @@ void esp32Setup() preferences.putUInt("rebootCounter", rebootCounter); preferences.end(); LOG_DEBUG("Number of Device Reboots: %d\n", rebootCounter); +#if !MESHTASTIC_EXCLUDE_BLUETOOTH String BLEOTA = BleOta::getOtaAppVersion(); if (BLEOTA.isEmpty()) { LOG_DEBUG("No OTA firmware available\n"); } else { LOG_DEBUG("OTA firmware version %s\n", BLEOTA.c_str()); } +#else + LOG_DEBUG("No OTA firmware available\n"); +#endif // enableModemSleep(); diff --git a/src/platform/nrf52/main-nrf52.cpp b/src/platform/nrf52/main-nrf52.cpp index 2f670dee35..ecffb745d3 100644 --- a/src/platform/nrf52/main-nrf52.cpp +++ b/src/platform/nrf52/main-nrf52.cpp @@ -65,6 +65,7 @@ static void initBrownout() static const bool useSoftDevice = true; // Set to false for easier debugging +#if !MESHTASTIC_EXCLUDE_BLUETOOTH void setBluetoothEnable(bool enable) { if (enable && config.bluetooth.enabled) { @@ -88,7 +89,9 @@ void setBluetoothEnable(bool enable) } } } - +#else +void setBluetoothEnable(bool enable) {} +#endif /** * Override printf to use the SEGGER output library (note - this does not effect the printf method on the debug console) */ diff --git a/src/sleep.cpp b/src/sleep.cpp index f170e2ab7c..2f4bd09e14 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -1,17 +1,23 @@ -#include "sleep.h" +#include "configuration.h" + +#if !MESHTASTIC_EXCLUDE_GPS #include "GPS.h" +#endif + #include "MeshRadio.h" #include "MeshService.h" #include "NodeDB.h" -#include "configuration.h" #include "error.h" #include "main.h" +#include "sleep.h" #include "target_specific.h" #ifdef ARCH_ESP32 #include "esp32/pm.h" #include "esp_pm.h" +#if !MESHTASTIC_EXCLUDE_WIFI #include "mesh/wifi/WiFiAPClient.h" +#endif #include "rom/rtc.h" #include #include @@ -48,7 +54,7 @@ RTC_DATA_ATTR int bootCount = 0; */ void setCPUFast(bool on) { -#ifdef ARCH_ESP32 +#if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_WIFI if (isWifiAvailable()) { /* @@ -206,11 +212,11 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false) // pinMode(PIN_POWER_EN1, INPUT_PULLDOWN); #endif #endif - +#if HAS_GPS // Kill GPS power completely (even if previously we just had it in sleep mode) if (gps) gps->setGPSPower(false, false, 0); - +#endif setLed(false); #ifdef RESET_OLED