diff --git a/src/DebugConfiguration.cpp b/src/DebugConfiguration.cpp index 9df402e77b..d9ecd9fe39 100644 --- a/src/DebugConfiguration.cpp +++ b/src/DebugConfiguration.cpp @@ -26,7 +26,7 @@ SOFTWARE.*/ #include "DebugConfiguration.h" -#if HAS_WIFI || HAS_ETHERNET +#if HAS_NETWORKING Syslog::Syslog(UDP &client) { diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index 874d63bca1..ebe9da8d44 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -1,5 +1,6 @@ -#ifndef SYSLOG_H -#define SYSLOG_H +#pragma once + +#include "configuration.h" // DEBUG LED #ifndef LED_INVERTED @@ -125,7 +126,7 @@ #include #endif // HAS_WIFI -#if HAS_WIFI || HAS_ETHERNET +#if HAS_NETWORKING class Syslog { @@ -160,6 +161,4 @@ class Syslog bool vlogf(uint16_t pri, const char *appName, const char *fmt, va_list args) __attribute__((format(printf, 3, 0))); }; -#endif // HAS_ETHERNET || HAS_WIFI - -#endif // SYSLOG_H \ No newline at end of file +#endif // HAS_ETHERNET || HAS_WIFI \ No newline at end of file diff --git a/src/Power.cpp b/src/Power.cpp index 18a527cee7..cea373806c 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -27,7 +27,7 @@ #if defined(DEBUG_HEAP_MQTT) && !MESHTASTIC_EXCLUDE_MQTT #include "mqtt/MQTT.h" #include "target_specific.h" -#if !MESTASTIC_EXCLUDE_WIFI +#if HAS_WIFI #include #endif #endif diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index 555e45401f..14264ba21e 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -16,7 +16,7 @@ #include "platform/portduino/PortduinoGlue.h" #endif -#if HAS_WIFI || HAS_ETHERNET +#if HAS_NETWORKING extern Syslog syslog; #endif void RedirectablePrint::rpInit() @@ -138,7 +138,7 @@ void RedirectablePrint::log_to_serial(const char *logLevel, const char *format, void RedirectablePrint::log_to_syslog(const char *logLevel, const char *format, va_list arg) { -#if (HAS_WIFI || HAS_ETHERNET) && !defined(ARCH_PORTDUINO) +#if HAS_NETWORKING && !defined(ARCH_PORTDUINO) // if syslog is in use, collect the log messages and send them to syslog if (syslog.isEnabled()) { int ll = 0; diff --git a/src/configuration.h b/src/configuration.h index 3d10feeaaf..854d3dadfe 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -242,9 +242,6 @@ along with this program. If not, see . #define HAS_BLUETOOTH 0 #endif -#include "DebugConfiguration.h" -#include "RF95Configuration.h" - #ifndef HW_VENDOR #error HW_VENDOR must be defined #endif @@ -290,6 +287,9 @@ along with this program. If not, see . #define HAS_WIFI 0 #endif +// Allow code that needs internet to just check HAS_NETWORKING rather than HAS_WIFI || HAS_ETHERNET +#define HAS_NETWORKING (HAS_WIFI || HAS_ETHERNET) + // // Turn off Bluetooth #ifdef MESHTASTIC_EXCLUDE_BLUETOOTH #undef HAS_BLUETOOTH @@ -308,4 +308,7 @@ along with this program. If not, see . #ifdef MESHTASTIC_EXCLUDE_SCREEN #undef HAS_SCREEN #define HAS_SCREEN 0 -#endif \ No newline at end of file +#endif + +#include "DebugConfiguration.h" +#include "RF95Configuration.h" \ No newline at end of file diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 1dc6d7883e..84872e4714 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -26,7 +26,7 @@ #include #ifdef ARCH_ESP32 -#if !MESHTASTIC_EXCLUDE_WIFI +#if HAS_WIFI #include "mesh/wifi/WiFiAPClient.h" #endif #include "modules/esp32/StoreForwardModule.h" diff --git a/src/mesh/http/ContentHandler.cpp b/src/mesh/http/ContentHandler.cpp index 7f9df058dd..b309484e23 100644 --- a/src/mesh/http/ContentHandler.cpp +++ b/src/mesh/http/ContentHandler.cpp @@ -6,7 +6,7 @@ #include "main.h" #include "mesh/http/ContentHelper.h" #include "mesh/http/WebServer.h" -#if !MESHTASTIC_EXCLUDE_WIFI +#if HAS_WIFI #include "mesh/wifi/WiFiAPClient.h" #endif #include "mqtt/JSON.h" diff --git a/src/mesh/wifi/WiFiAPClient.cpp b/src/mesh/wifi/WiFiAPClient.cpp index ffb16bd3e5..e733d18011 100644 --- a/src/mesh/wifi/WiFiAPClient.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -1,5 +1,5 @@ #include "configuration.h" -#if !MESHTASTIC_EXCLUDE_WIFI +#if HAS_WIFI #include "NodeDB.h" #include "RTC.h" #include "concurrency/Periodic.h" diff --git a/src/modules/AdminModule.h b/src/modules/AdminModule.h index 32b32c253a..6ecc888294 100644 --- a/src/modules/AdminModule.h +++ b/src/modules/AdminModule.h @@ -1,6 +1,6 @@ #pragma once #include "ProtobufModule.h" -#if HAS_WIFI && !MESHTASTIC_EXCLUDE_WIFI +#if HAS_WIFI #include "mesh/wifi/WiFiAPClient.h" #endif diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 74f3ca5a32..a64720c78c 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -14,7 +14,7 @@ #endif #include "mesh/generated/meshtastic/remote_hardware.pb.h" #include "sleep.h" -#if HAS_WIFI && !MESHTASTIC_EXCLUDE_WIFI +#if HAS_WIFI #include "mesh/wifi/WiFiAPClient.h" #include #endif @@ -175,7 +175,7 @@ void mqttInit() new MQTT(); } -#ifdef HAS_NETWORKING +#if HAS_NETWORKING MQTT::MQTT() : concurrency::OSThread("mqtt"), pubSub(mqttClient), mqttQueue(MAX_MQTT_QUEUE) #else MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE) @@ -206,7 +206,7 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE) moduleConfig.mqtt.map_report_settings.publish_interval_secs, default_map_publish_interval_secs); } -#ifdef HAS_NETWORKING +#if HAS_NETWORKING if (!moduleConfig.mqtt.proxy_to_client_enabled) pubSub.setCallback(mqttCallback); #endif @@ -226,7 +226,7 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE) bool MQTT::isConnectedDirectly() { -#ifdef HAS_NETWORKING +#if HAS_NETWORKING return pubSub.connected(); #else return false; @@ -244,7 +244,7 @@ bool MQTT::publish(const char *topic, const char *payload, bool retained) service.sendMqttMessageToClientProxy(msg); return true; } -#ifdef HAS_NETWORKING +#if HAS_NETWORKING else if (isConnectedDirectly()) { return pubSub.publish(topic, payload, retained); } @@ -264,7 +264,7 @@ bool MQTT::publish(const char *topic, const uint8_t *payload, size_t length, boo service.sendMqttMessageToClientProxy(msg); return true; } -#ifdef HAS_NETWORKING +#if HAS_NETWORKING else if (isConnectedDirectly()) { return pubSub.publish(topic, payload, length, retained); } @@ -284,7 +284,7 @@ void MQTT::reconnect() publishStatus(); return; // Don't try to connect directly to the server } -#ifdef HAS_NETWORKING +#if HAS_NETWORKING // Defaults int serverPort = 1883; const char *serverAddr = default_mqtt_address; @@ -357,7 +357,7 @@ void MQTT::reconnect() void MQTT::sendSubscriptions() { -#ifdef HAS_NETWORKING +#if HAS_NETWORKING size_t numChan = channels.getNumChannels(); for (size_t i = 0; i < numChan; i++) { const auto &ch = channels.getByIndex(i); @@ -396,7 +396,7 @@ bool MQTT::wantsLink() const int32_t MQTT::runOnce() { -#ifdef HAS_NETWORKING +#if HAS_NETWORKING if (!moduleConfig.mqtt.enabled || !(moduleConfig.mqtt.map_reporting_enabled || channels.anyMqttEnabled())) return disable(); diff --git a/src/mqtt/MQTT.h b/src/mqtt/MQTT.h index f2eb6b1204..1ebba4afe9 100644 --- a/src/mqtt/MQTT.h +++ b/src/mqtt/MQTT.h @@ -8,17 +8,15 @@ #include "mqtt/JSON.h" #if HAS_WIFI #include -#define HAS_NETWORKING 1 #if !defined(ARCH_PORTDUINO) #include #endif #endif #if HAS_ETHERNET #include -#define HAS_NETWORKING 1 #endif -#ifdef HAS_NETWORKING +#if HAS_NETWORKING #include #endif @@ -43,7 +41,7 @@ class MQTT : private concurrency::OSThread #endif public: -#ifdef HAS_NETWORKING +#if HAS_NETWORKING PubSubClient pubSub; #endif MQTT(); diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index 1dd7a389af..aa51e810a8 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -8,7 +8,7 @@ #include "nimble/NimbleBluetooth.h" #endif -#if !MESHTASTIC_EXCLUDE_WIFI +#if HAS_WIFI #include "mesh/wifi/WiFiAPClient.h" #endif @@ -24,23 +24,22 @@ #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !MESHTASTIC_EXCLUDE_BLUETOOTH void setBluetoothEnable(bool enable) { -#ifndef MESHTASTIC_EXCLUDE_WIFI +#if HAS_WIFI if (!isWifiAvailable() && config.bluetooth.enabled == true) +#else + if (config.bluetooth.enabled == true) #endif -#ifdef MESHTASTIC_EXCLUDE_WIFI - if (config.bluetooth.enabled == true) -#endif - { - if (!nimbleBluetooth) { - nimbleBluetooth = new NimbleBluetooth(); - } - if (enable && !nimbleBluetooth->isActive()) { - nimbleBluetooth->setup(); - } - // For ESP32, no way to recover from bluetooth shutdown without reboot - // BLE advertising automatically stops when MCU enters light-sleep(?) - // For deep-sleep, shutdown hardware with nimbleBluetooth->deinit(). Requires reboot to reverse + { + if (!nimbleBluetooth) { + nimbleBluetooth = new NimbleBluetooth(); } + if (enable && !nimbleBluetooth->isActive()) { + nimbleBluetooth->setup(); + } + // For ESP32, no way to recover from bluetooth shutdown without reboot + // BLE advertising automatically stops when MCU enters light-sleep(?) + // For deep-sleep, shutdown hardware with nimbleBluetooth->deinit(). Requires reboot to reverse + } } #else void setBluetoothEnable(bool enable) {} diff --git a/src/sleep.cpp b/src/sleep.cpp index 1c1a6e9ac4..735ebcf6ad 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -17,7 +17,7 @@ #ifdef ARCH_ESP32 #include "esp32/pm.h" #include "esp_pm.h" -#if !MESHTASTIC_EXCLUDE_WIFI +#if HAS_WIFI #include "mesh/wifi/WiFiAPClient.h" #endif #include "rom/rtc.h" @@ -56,7 +56,7 @@ RTC_DATA_ATTR int bootCount = 0; */ void setCPUFast(bool on) { -#if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_WIFI +#if defined(ARCH_ESP32) && HAS_WIFI if (isWifiAvailable()) { /*