ESPMegaPRO-v3-SDK/ESPMegaPRO-firmware/src/iot_framdemo.cpp

78 lines
2.6 KiB
C++
Raw Normal View History

2023-12-28 13:20:49 +00:00
#include <ESPMegaPRO_OOP.hpp>
2023-12-29 14:41:19 +00:00
#include <InternalDisplay.hpp>
2023-12-28 16:28:21 +00:00
#include <ETH.h>
2023-12-30 08:39:16 +00:00
#include <ClimateCard.hpp>
2023-12-28 13:20:49 +00:00
2023-12-30 11:47:52 +00:00
2023-12-30 11:27:39 +00:00
// Demo PLC firmware using the ESPMegaPRO OOP library
2023-12-28 13:20:49 +00:00
ESPMegaPRO espmega = ESPMegaPRO();
2023-12-28 16:28:21 +00:00
void input_change_callback(uint8_t pin, uint8_t value) {
Serial.print("Input change callback: ");
Serial.print(pin);
Serial.print(" ");
Serial.println(value);
}
2023-12-28 13:20:49 +00:00
void setup() {
2023-12-30 11:47:52 +00:00
// Set each class's log level
esp_log_level_set("ESPMegaPRO", ESP_LOG_VERBOSE);
esp_log_level_set("DigitalOutputCard", ESP_LOG_VERBOSE);
esp_log_level_set("DigitalOutputIoT", ESP_LOG_VERBOSE);
esp_log_level_set("DigitalInputCard", ESP_LOG_VERBOSE);
esp_log_level_set("DigitalInputIoT", ESP_LOG_VERBOSE);
esp_log_level_set("AnalogCard", ESP_LOG_VERBOSE);
esp_log_level_set("AnalogIoT", ESP_LOG_VERBOSE);
esp_log_level_set("ClimateCard", ESP_LOG_VERBOSE);
esp_log_level_set("ClimateIoT", ESP_LOG_VERBOSE);
esp_log_level_set("InternalDisplay", ESP_LOG_VERBOSE);
esp_log_level_set("InternalDisplayIoT", ESP_LOG_VERBOSE);
2023-12-28 13:20:49 +00:00
espmega.begin();
espmega.enableIotModule();
2023-12-28 16:28:21 +00:00
ETH.begin();
espmega.iot->bindEthernetInterface(&ETH);
2023-12-28 13:20:49 +00:00
NetworkConfig config = {
.ip = {192, 168, 0, 11},
.gateway = {192, 168, 0, 1},
.subnet = {255, 255, 255, 0},
.dns1 = {192, 168, 0, 1},
.dns2 = {192, 168, 0, 1},
.useStaticIp = true,
.useWifi = false,
.wifiUseAuth = false,
};
strcpy(config.ssid, "ssid");
strcpy(config.password, "password");
strcpy(config.hostname, "espmega");
2023-12-28 16:28:21 +00:00
Serial.println("Setting network config");
espmega.iot->setNetworkConfig(config);
2023-12-28 16:28:21 +00:00
Serial.println("Connecting to network");
espmega.iot->connectNetwork();
2023-12-28 16:28:21 +00:00
Serial.println("Begin MQTT Modules");
2023-12-28 13:20:49 +00:00
MqttConfig mqtt_config = {
.mqtt_port = 1883,
.mqtt_useauth = false
};
2023-12-28 16:28:21 +00:00
Serial.println("Setting MQTT Server");
2023-12-28 13:20:49 +00:00
strcpy(mqtt_config.mqtt_server, "192.168.0.26");
2023-12-28 16:28:21 +00:00
strcpy(mqtt_config.base_topic, "/espmegaoop");
Serial.println("Loading MQTT Config Struct to IoT Module");
espmega.iot->setMqttConfig(mqtt_config);
2023-12-28 16:28:21 +00:00
Serial.println("Connecting to MQTT");
espmega.iot->connectToMqtt();
2023-12-30 11:27:39 +00:00
Serial.println("Registering Output Card");
espmega.iot->registerCard(0);
2023-12-30 11:27:39 +00:00
Serial.println("Registering Input Card");
espmega.iot->registerCard(1);
2023-12-30 11:27:39 +00:00
Serial.println("Registering Input Change Callback");
2023-12-29 17:49:09 +00:00
espmega.inputs.registerCallback(input_change_callback);
2023-12-30 11:27:39 +00:00
Serial.println("Enabling Internal Display");
espmega.enableInternalDisplay(&Serial);
2023-12-30 11:27:39 +00:00
Serial.println("Initialization Routine Complete");
2023-12-28 13:20:49 +00:00
}
void loop() {
espmega.loop();
}