1
0
Fork 0

initial commit

This commit is contained in:
Siwat Sirichai 2024-10-08 15:27:01 +07:00
commit 7dbf37007a
8 changed files with 189 additions and 0 deletions

56
src/main.cpp Normal file
View file

@ -0,0 +1,56 @@
#include <main.hpp>
ESPMegaPRO espmega = ESPMegaPRO();
void setup()
{
// Initialize both displayports
INTERNAL_DISPLAY_UART.begin(INTERNAL_DISPLAY_BAUDRATE);
ESP_LOGI("OS", "Starting Initialization");
INTERNAL_DISPLAY_UART.write(0xFF);
INTERNAL_DISPLAY_UART.write(0xFF);
INTERNAL_DISPLAY_UART.write(0xFF);
INTERNAL_DISPLAY_UART.print("rest");
INTERNAL_DISPLAY_UART.write(0xFF);
INTERNAL_DISPLAY_UART.write(0xFF);
INTERNAL_DISPLAY_UART.write(0xFF);
// Wait for the display to reset
vTaskDelay(1000 / portTICK_PERIOD_MS);
// Initialize the ESPMegaPRO
ESP_LOGV("OS", "Initializing ESPMegaPRO");
espmega.begin();
espmega.inputs.preloadInputBuffer();
// Initialize IoT Modules
ESP_LOGV("OS", "Initializing IoT Modules");
espmega.setTimezone("ICT-7");
espmega.enableIotModule();
// Setup Ethernet
ESP_LOGV("OS", "Initializing Ethernet");
ETH.begin();
ESP_LOGD("OS", "Binding Ethernet Interface");
espmega.iot->bindEthernetInterface(&ETH);
// Connect to Network
ESP_LOGV("OS", "Connecting to Network");
espmega.iot->loadNetworkConfig();
espmega.iot->connectNetwork();
// Connect to the MQTT Broker
ESP_LOGV("OS", "Connecting to MQTT Broker");
espmega.iot->loadMqttConfig();
vTaskDelay(3000 / portTICK_PERIOD_MS); // Wait for the network to stabilize
espmega.iot->connectToMqtt();
// Enable Web Server
ESP_LOGV("OS", "Enabling Web Server");
espmega.enableWebServer(80);
ESP_LOGV("OS", "Initializing Internal Display");
espmega.enableInternalDisplay(&INTERNAL_DISPLAY_UART);
// Register all cards with iot
ESP_LOGV("OS", "Registering Cards with IoT");
espmega.iot->registerCard(0);
espmega.iot->registerCard(1);
}
void loop()
{
espmega.loop();
}

6
src/main.hpp Normal file
View file

@ -0,0 +1,6 @@
#pragma once
#include <ESPMegaProOS.hpp>
#include <ETH.h>
#define INTERNAL_DISPLAY_UART Serial
#define INTERNAL_DISPLAY_BAUDRATE 115200