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

58 lines
1.7 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
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() {
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");
2023-12-28 13:20:49 +00:00
espmega.iot.setNetworkConfig(config);
2023-12-28 16:28:21 +00:00
Serial.println("Connecting to network");
2023-12-28 13:20:49 +00:00
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");
2023-12-28 13:20:49 +00:00
espmega.iot.setMqttConfig(mqtt_config);
2023-12-28 16:28:21 +00:00
Serial.println("Connecting to MQTT");
2023-12-28 13:20:49 +00:00
espmega.iot.connectToMqtt();
2023-12-28 16:28:21 +00:00
Serial.println("Registering cards");
2023-12-28 13:20:49 +00:00
espmega.iot.registerCard(0);
espmega.iot.registerCard(1);
2023-12-28 16:28:21 +00:00
Serial.println("Initialization Routine Complete");
2023-12-29 17:49:09 +00:00
espmega.inputs.registerCallback(input_change_callback);
2023-12-28 13:20:49 +00:00
}
void loop() {
espmega.loop();
}