IoT Structure

This commit is contained in:
Siwat Sirichai 2023-12-28 03:09:41 +07:00
parent a88a65e437
commit 822eb66285
8 changed files with 72 additions and 2 deletions

View File

@ -0,0 +1,17 @@
#pragma once
#include <AnalogCard.hpp>
class AnalogIoT {
public:
bool begin(AnalogCard *card);
void handleMqttMessage(char *topic, char *payload);
void publishADCs();
void setADCsPublishInterval(uint32_t interval);
void setADCsPublishEnabled(bool enabled);
private:
char *adc_topic;
char *dac_topic;
uint32_t adc_publish_interval = 1000;
uint32_t last_adc_publish = 0;
bool adc_publish_enabled = false;
AnalogCard *card;
};

View File

@ -0,0 +1,15 @@
#include <DigitalInputCard.hpp>
class DigitalInputIoT {
public:
bool begin(DigitalInputCard *card);
void handleMqttMessage(char *topic, char *payload);
void publishDigitalInputs();
void setDigitalInputsPublishEnabled(bool enabled);
void handleValueChange(uint8_t pin, uint8_t value);
void registerValueChangeCallback(void (*callback)(uint8_t, uint8_t));
private:
char *digital_inputs_topic;
bool digital_inputs_publish_enabled = false;
DigitalInputCard *card;
};

View File

@ -0,0 +1,36 @@
#include <ExpansionCard.hpp>
#include <AnalogCard.hpp>
#include <DigitalInputCard.hpp>
#include <DigitalOutputCard.hpp>
#include <PubSubClient.h>
#include <ETH.h>
class ESPMegaIoT
{
public:
void begin();
void loop();
void registerCard(uint8_t card_id);
void deregisterCard(uint8_t card_id);
void publishCard(uint8_t card_id);
void subscribeToTopic(char *topic);
void unsubscribeFromTopic(char *topic);
void connectToEthernet();
bool ethernetConnected();
void connectToWifi(char *ssid, char *password);
void connectToWifi(char *ssid);
void disconnectFromWifi();
bool wifiConnected();
void connectToMqtt(char *mqtt_server, uint16_t mqtt_port, char *mqtt_user, char *mqtt_password);
void disconnectFromMqtt();
void publishToTopic(char *topic, char *payload);
void registerMqttCallback(void (*callback)(char *, char *));
private:
void sessionKeepAlive();
void mqttReconnect();
void wifiReconnect();
PubSubClient mqtt;
ExpansionCard *expansionCards[255];
bool card_publish_enabled[255];
}

View File

@ -5,12 +5,12 @@ ESPMegaPRO::ESPMegaPRO() {
bool ESPMegaPRO::begin() {
Wire.begin(14, 33);
Serial.begin(115200);
if(!inputs.begin()) {
if(!this->installCard(0, &inputs)) {
Serial.println("Failed to initialize inputs");
Serial.println("Is this an ESPMegaPRO device?");
return false;
}
outputs.begin();
this->installCard(1, &outputs);
if(!fram.begin(FRAM_ADDRESS)) {
Serial.println("Failed to initialize FRAM");
Serial.println("Is this an ESPMegaPRO device?");

View File

@ -0,0 +1 @@
#include <ESPMegaTouch.hpp>

View File

@ -0,0 +1 @@
#include <EasyNextion.h>