diff --git a/Template Project/lib/ESPMegaPRO/AnalogIoT.hpp b/Template Project/lib/ESPMegaPRO/AnalogIoT.hpp index 07447b3..40b02c7 100644 --- a/Template Project/lib/ESPMegaPRO/AnalogIoT.hpp +++ b/Template Project/lib/ESPMegaPRO/AnalogIoT.hpp @@ -5,7 +5,7 @@ class AnalogIoT : public IoTComponent { public: AnalogIoT(); ~AnalogIoT(); - bool begin(AnalogCard *card); + bool begin(AnalogCard *card, void (*publishRelative)(uint8_t, char *, char *), PubSubClient *mqtt, char *base_topic); void handleMqttMessage(char *topic, char *payload); void publishADCs(); void setADCsPublishInterval(uint32_t interval); diff --git a/Template Project/lib/ESPMegaPRO/DigitalInputIoT.hpp b/Template Project/lib/ESPMegaPRO/DigitalInputIoT.hpp index c910175..38a3071 100644 --- a/Template Project/lib/ESPMegaPRO/DigitalInputIoT.hpp +++ b/Template Project/lib/ESPMegaPRO/DigitalInputIoT.hpp @@ -5,7 +5,7 @@ class DigitalInputIoT : public IoTComponent { public: - bool begin(DigitalInputCard *card); + bool begin(DigitalInputCard *card, void (*publishRelative)(uint8_t, char *, char *), PubSubClient *mqtt, char *base_topic); void handleMqttMessage(char *topic, char *payload); void publishDigitalInputs(); void setDigitalInputsPublishEnabled(bool enabled); @@ -15,6 +15,5 @@ class DigitalInputIoT : public IoTComponent { uint8_t getType(); private: bool digital_inputs_publish_enabled = false; - DigitalInputCard *card; }; \ No newline at end of file diff --git a/Template Project/lib/ESPMegaPRO/DigitalOutputIoT.cpp b/Template Project/lib/ESPMegaPRO/DigitalOutputIoT.cpp index d9c8bab..3d88d77 100644 --- a/Template Project/lib/ESPMegaPRO/DigitalOutputIoT.cpp +++ b/Template Project/lib/ESPMegaPRO/DigitalOutputIoT.cpp @@ -10,7 +10,10 @@ DigitalOutputIoT::~DigitalOutputIoT() { delete[] this->value_report_topic; } -bool DigitalOutputIoT::begin(ExpansionCard *card) { +bool DigitalOutputIoT::begin(ExpansionCard *card, void (*publishRelative)(uint8_t, char *, char *), PubSubClient *mqtt, char *base_topic) { + this->mqtt = mqtt; + this->base_topic = base_topic; + this->publishRelative = publishRelative; this->card = (DigitalOutputCard *) card; this->set_state_length = strlen(SET_STATE_TOPIC); this->set_value_length = strlen(SET_VALUE_TOPIC); diff --git a/Template Project/lib/ESPMegaPRO/DigitalOutputIoT.hpp b/Template Project/lib/ESPMegaPRO/DigitalOutputIoT.hpp index 5d30070..7c81da2 100644 --- a/Template Project/lib/ESPMegaPRO/DigitalOutputIoT.hpp +++ b/Template Project/lib/ESPMegaPRO/DigitalOutputIoT.hpp @@ -7,7 +7,7 @@ class DigitalOutputIoT : public IoTComponent { public: DigitalOutputIoT(); ~DigitalOutputIoT(); - bool begin(ExpansionCard *card); + bool begin(ExpansionCard *card, void (*publishRelative)(uint8_t, char *, char *), PubSubClient *mqtt, char *base_topic); void handleMqttMessage(char *topic, char *payload); void publishDigitalOutputs(); void publishDigitalOutput(uint8_t pin); diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaIoT.cpp b/Template Project/lib/ESPMegaPRO/ESPMegaIoT.cpp index bd1a364..9891da2 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaIoT.cpp +++ b/Template Project/lib/ESPMegaPRO/ESPMegaIoT.cpp @@ -19,3 +19,28 @@ void ESPMegaIoT::mqttCallback(char *topic, byte *payload, unsigned int length) { components[card_id]->handleMqttMessage(topic_without_base + 3, payload_buffer); } +void ESPMegaIoT::setBaseTopic(char *base_topic) { + strcpy(this->base_topic, base_topic); + base_topic_length = strlen(base_topic); +} + +void ESPMegaIoT::begin() { + +} +void ESPMegaIoT::loop(); +void ESPMegaIoT::registerCard(uint8_t card_id); +void ESPMegaIoT::deregisterCard(uint8_t card_id); +void ESPMegaIoT::publishCard(uint8_t card_id); +void ESPMegaIoT::subscribeToTopic(char *topic); +void ESPMegaIoT::unsubscribeFromTopic(char *topic); +void ESPMegaIoT::connectToEthernet(); +bool ESPMegaIoT::ethernetConnected(); +void ESPMegaIoT::connectToWifi(char *ssid, char *password); +void ESPMegaIoT::connectToWifi(char *ssid); +void ESPMegaIoT::disconnectFromWifi(); +bool ESPMegaIoT::wifiConnected(); +void ESPMegaIoT::connectToMqtt(char *mqtt_server, uint16_t mqtt_port, char *mqtt_user, char *mqtt_password); +void ESPMegaIoT::connectToMqtt(char *mqtt_server, uint16_t mqtt_port); +void ESPMegaIoT::disconnectFromMqtt(); +void ESPMegaIoT::publishToTopic(char *topic, char *payload); +void ESPMegaIoT::registerMqttCallback(void (*callback)(char *, char *)); diff --git a/Template Project/lib/ESPMegaPRO/ESPMegaIoT.hpp b/Template Project/lib/ESPMegaPRO/ESPMegaIoT.hpp index 7eed58c..7f5f4cd 100644 --- a/Template Project/lib/ESPMegaPRO/ESPMegaIoT.hpp +++ b/Template Project/lib/ESPMegaPRO/ESPMegaIoT.hpp @@ -30,15 +30,19 @@ class ESPMegaIoT void disconnectFromMqtt(); void publishToTopic(char *topic, char *payload); void registerMqttCallback(void (*callback)(char *, char *)); + void setBaseTopic(char *base_topic); + private: void sessionKeepAlive(); void mqttReconnect(); void wifiReconnect(); void mqttCallback(char *topic, byte *payload, unsigned int length); + void publishRelative(char *topic, char *payload); PubSubClient mqtt; IoTComponent *components[255]; bool card_publish_enabled[255]; char payload_buffer[200]; char base_topic[100]; + uint8_t base_topic_length; }; \ No newline at end of file diff --git a/Template Project/lib/ESPMegaPRO/IoTComponent.hpp b/Template Project/lib/ESPMegaPRO/IoTComponent.hpp index 3321857..8211aac 100644 --- a/Template Project/lib/ESPMegaPRO/IoTComponent.hpp +++ b/Template Project/lib/ESPMegaPRO/IoTComponent.hpp @@ -3,11 +3,13 @@ #include class IoTComponent { public: - virtual bool begin(ExpansionCard *card); + virtual bool begin(ExpansionCard *card, void (*publishRelative)(uint8_t, char *, char *), PubSubClient *mqtt, char *base_topic); virtual void handleMqttMessage(char *topic, char *payload); void setMqttClient(PubSubClient *mqtt); virtual void publishReport(); virtual uint8_t getType(); protected: + char *base_topic; + void (*publishRelative)(uint8_t, char *, char *); PubSubClient *mqtt; };