completed InputCard

This commit is contained in:
Siwat Sirichai 2023-12-28 23:28:21 +07:00
parent 9f6512bf71
commit 75aa6f490b
8 changed files with 77 additions and 84 deletions

View file

@ -1,10 +1,20 @@
#include <ESPMegaPRO_OOP.hpp>
#include <ETH.h>
ESPMegaPRO espmega = ESPMegaPRO();
void input_change_callback(uint8_t pin, uint8_t value) {
Serial.print("Input change callback: ");
Serial.print(pin);
Serial.print(" ");
Serial.println(value);
}
void setup() {
espmega.begin();
espmega.enableIotModule();
ETH.begin();
espmega.iot.bindEthernetInterface(&ETH);
NetworkConfig config = {
.ip = {192, 168, 0, 11},
.gateway = {192, 168, 0, 1},
@ -18,17 +28,28 @@ void setup() {
strcpy(config.ssid, "ssid");
strcpy(config.password, "password");
strcpy(config.hostname, "espmega");
Serial.println("Setting network config");
espmega.iot.setNetworkConfig(config);
Serial.println("Connecting to network");
espmega.iot.connectNetwork();
Serial.println("Begin MQTT Modules");
MqttConfig mqtt_config = {
.mqtt_port = 1883,
.mqtt_useauth = false
};
Serial.println("Setting MQTT Server");
strcpy(mqtt_config.mqtt_server, "192.168.0.26");
strcpy(mqtt_config.base_topic, "/espmegaoop");
Serial.println("Loading MQTT Config Struct to IoT Module");
espmega.iot.setMqttConfig(mqtt_config);
Serial.println("Connecting to MQTT");
espmega.iot.connectToMqtt();
Serial.println("Registering cards");
espmega.iot.registerCard(0);
espmega.iot.registerCard(1);
Serial.println("Initialization Routine Complete");
((DigitalInputIoT*)espmega.iot.getComponent(0)) -> registerChangeCallback(input_change_callback);
}
void loop() {