From 4fcb4667339702696b8478e61a80acbb751fced6 Mon Sep 17 00:00:00 2001 From: ZakaryW Date: Tue, 5 Mar 2024 20:28:52 -0800 Subject: [PATCH] Small fix for external function access --- .../Connectivity/Loom_Wifi/Loom_Wifi.h | 59 +++++++++---------- .../Logging/MQTTComponent/MQTTComponent.h | 48 +++++++-------- 2 files changed, 53 insertions(+), 54 deletions(-) diff --git a/src/Internet/Connectivity/Loom_Wifi/Loom_Wifi.h b/src/Internet/Connectivity/Loom_Wifi/Loom_Wifi.h index 6cdc70f..4b3b958 100644 --- a/src/Internet/Connectivity/Loom_Wifi/Loom_Wifi.h +++ b/src/Internet/Connectivity/Loom_Wifi/Loom_Wifi.h @@ -11,7 +11,7 @@ /** * Communication mode for routing traffic between the feather and Max client - */ + */ enum CommunicationMode{ CLIENT, // Connect to a remote router to handle traffic AP // Set the feather itself as an access point @@ -26,20 +26,20 @@ typedef struct { /** * WiFi 101 library integrated with the manager to allow for easy sleep - * + * * @author Will Richards - */ + */ class Loom_WIFI : public NetworkComponent{ protected: /* These aren't used with the Wifi manager */ - void measure() override {}; + void measure() override {}; bool getNetworkTime(int* year, int* month, int* day, int* hour, int* minute, int* second, float* tz) override; // Initialize the device and connect to the network void initialize() override; - void package() override; + void package() override; // Reconnect to the network void power_up() override; @@ -47,9 +47,6 @@ class Loom_WIFI : public NetworkComponent{ // Disconnect from the network void power_down() override; - // Overridden isConnected for the NetworkComponent - bool isConnected() override; - public: /** @@ -57,50 +54,53 @@ class Loom_WIFI : public NetworkComponent{ * @param man Reference to the manager to control all aspects of every module * @param mode Whether or not to try to connect to an access point or create our own * @param name The name of the WiFi access point we are going to connect to - * @param password The password (if applicable) to connect to the access point - */ + * @param password The password (if applicable) to connect to the access point + */ Loom_WIFI(Manager& man, CommunicationMode mode, const char* name = "", const char* password = "", int connectionRetries = 5); /** * Construct a new WiFi manager, passing the credentials in as a json document - * @param man Reference to the manager + * @param man Reference to the manager * @param jsonString JSON string to pull the credentials from - */ + */ Loom_WIFI(Manager& man); + // Overridden isConnected for the NetworkComponent + bool isConnected() override; + /** * Load the Wifi credentials from a JSON string, used to pull credentials from a file - * + * * This automatically frees the input json - * - * @param jsonString JSON formatted string containing the SSID and password + * + * @param jsonString JSON formatted string containing the SSID and password */ void loadConfigFromJSON(char* json); /** * Returns a reference to the WifiClient * @return wifiClient - */ + */ WiFiClient& getClient() { return wifiClient; }; /** * Get a reference to the UDP communication handler - */ + */ WiFiUDP* getUDP() { return new WiFiUDP(); }; /** * Attempt to ping Google, this tests if we are truly connected to the internet - */ + */ bool verifyConnection(); /** * Connect to an already existing access point - */ + */ void connect_to_network(); /** * Create our own access point - */ + */ void start_ap(); /* Take in new WiFi information store it to flash and restart the WiFi chip to put the new credentials into effect*/ @@ -108,28 +108,27 @@ class Loom_WIFI : public NetworkComponent{ /** * Get the IP address of the WiFi module - */ + */ IPAddress getIPAddress(); /** * Get the subnet mask of the connected network - */ + */ IPAddress getSubnetMask(); /** * Get the gateway IP of the network - */ + */ IPAddress getGateway(); /** * Get the broadcast IP of the network - */ + */ IPAddress getBroadcast(); - /** * Called by max to ignore WiFi verification requests - */ + */ void useMax() {usingMax = true; }; /** @@ -144,8 +143,8 @@ class Loom_WIFI : public NetworkComponent{ /** * Convert an IP address to a string - */ - void ipToString(IPAddress ip, char array[16]) { + */ + void ipToString(IPAddress ip, char array[16]) { snprintf(array, 16, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); }; @@ -165,7 +164,7 @@ class Loom_WIFI : public NetworkComponent{ bool firstInit = true; CommunicationMode mode; // Current WiFi mode we are in - IPAddress remoteIP; // IP address to send the UDP requests to + IPAddress remoteIP; // IP address to send the UDP requests to + - }; \ No newline at end of file diff --git a/src/Internet/Logging/MQTTComponent/MQTTComponent.h b/src/Internet/Logging/MQTTComponent/MQTTComponent.h index 42f3070..5130b1f 100644 --- a/src/Internet/Logging/MQTTComponent/MQTTComponent.h +++ b/src/Internet/Logging/MQTTComponent/MQTTComponent.h @@ -9,7 +9,7 @@ /** * MQTT Abstraction class that provides basic MQTT communciation functionality - * + * * @author Will Richards */ class MQTTComponent : public Module{ @@ -21,63 +21,57 @@ class MQTTComponent : public Module{ /** * Publish an MQTT message to a given topic and broker - * + * * @param topic The MQTT topic we want to publish our message to * @param message The message we want to publish to the given topic * @param retain Whether or not we want to the message to be retained on the specified topic (default = false) * @param qos What quality-of-service we want to upload the message with (default = 2) - * + * * @return The status of the publish attempt */ - bool publishMessage(const char* topic, const char* message, bool retain = false, int qos = 2); + bool publishMessage(const char* topic, const char* message, bool retain = false, int qos = 2); /** * Subscribe to a given topic to get the retained message and then immediately unsubscribe - * + * * @param topic The topic we want to retrieve the message from * @param message The buffer we want to store the retrieved message in - * + * * @param The status of the retrieval attempt */ - bool getCurrentRetained(const char* topic, char message[MAX_JSON_SIZE]); + bool getCurrentRetained(const char* topic, char message[MAX_JSON_SIZE]); /** * Publishes a message to a given topic with size 0 and the retain flag set to true so that the current retained message is removed - * + * * @param topic The topic we want to delete the retained message on - * + * * @return The result of the deletion attempt - * */ + * */ bool deleteRetained(const char* topic); /** - * Length of time the broker should keep the connection open for default + * Length of time the broker should keep the connection open for default * @param time Length of time in MILLISECONDS the connection will be kept open - */ + */ void setKeepAlive(int time) { keep_alive = time; }; - - /** - * Set the maximum number of reconnection attempts to make before failing - * @param retries The number of retries we want to make - */ - void setMaxRetries(int retries) { maxRetries = retries; }; /** * Set the client ID for the specific MQTT connection - * + * * @param id The new ID to set */ void setClientID(const char* id) { mqttClient.setId(id); }; /** * Wrapper for specifying that we want to use a clean session or not (defaults to true) - * + * * @param cleanSession Wether or not the session should be clean */ void setCleanSession(bool cleanSession) { mqttClient.setCleanSession(cleanSession); }; /* On power up we want to connect to the broker, this can be overridden but you will need to call connectToBroker again */ - virtual void power_up() override { connectToBroker(); }; + virtual void power_up() override { connectToBroker(); }; /* On initialize we just want to call the power_up function to connect to the broker, this can also be overriden but you should call power_up or connectToBroker again */ virtual void initialize() override; @@ -92,9 +86,9 @@ class MQTTComponent : public Module{ /** * Constructor for base MQTTComponent - * + * * @param compName Name for the underlying module - * @param internet_client The Client object from a internet platform + * @param internet_client The Client object from a internet platform */ MQTTComponent(const char* compName, Client& internet_client) : Module(compName), mqttClient(internet_client) { /* Clear all connection parameters */ @@ -113,9 +107,15 @@ class MQTTComponent : public Module{ */ virtual void loadConfigFromJSON(char* json) = 0; + /** + * Set the maximum number of reconnection attempts to make before failing + * @param retries The number of retries we want to make + */ + void setMaxRetries(int retries) { maxRetries = retries; }; + private: MqttClient mqttClient; // Instance of the MQTT client int keep_alive = 60000; // How long the broker should keep the connection open, defaults to a minute int maxRetries = 4; // How many times we want to retry the connection -}; \ No newline at end of file +}; \ No newline at end of file