mirror of
https://gitlab.com/zwirbel/sprocket-device-bb1.git
synced 2025-12-15 01:42:24 +01:00
74 lines
2.3 KiB
C++
74 lines
2.3 KiB
C++
#include <config.h>
|
|
#include <WiFiNet.h>
|
|
#include <Sprocket.h>
|
|
#include <DisplayPlugin.h>
|
|
#include <WebServerConfig.h>
|
|
#include <WebServerPlugin.h>
|
|
#include <WebConfigPlugin.h>
|
|
#include <WebApiPlugin.h>
|
|
#include <MqttPlugin.h>
|
|
|
|
WiFiNet *network;
|
|
Sprocket *sprocket;
|
|
DisplayPlugin *displayPlugin;
|
|
WebServerPlugin *webServerPlugin;
|
|
WebConfigPlugin *webConfigPlugin;
|
|
WebApiPlugin *webApiPlugin;
|
|
MqttPlugin *mqttPlugin;
|
|
|
|
void enableOled()
|
|
{
|
|
pinMode(16, OUTPUT);
|
|
digitalWrite(16, LOW); // set GPIO16 low to reset OLED
|
|
delay(50);
|
|
digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high
|
|
}
|
|
|
|
void setup()
|
|
{
|
|
delay(3000);
|
|
enableOled();
|
|
sprocket = new Sprocket({STARTUP_DELAY, SERIAL_BAUD_RATE});
|
|
displayPlugin = new DisplayPlugin({0x3c, 4, 15, 12, 4, 0});
|
|
mqttPlugin = new MqttPlugin({MQTT_CLIENT_NAME, MQTT_HOST, MQTT_PORT, MQTT_TOPIC_IN, MQTT_TOPIC_OUT});
|
|
webServerPlugin = new WebServerPlugin({WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE, WEB_PORT});
|
|
webConfigPlugin = new WebConfigPlugin(webServerPlugin->server);
|
|
webApiPlugin = new WebApiPlugin(webServerPlugin->server);
|
|
sprocket->addPlugin(displayPlugin);
|
|
sprocket->addPlugin(webServerPlugin);
|
|
sprocket->addPlugin(webConfigPlugin);
|
|
sprocket->addPlugin(webApiPlugin);
|
|
sprocket->addPlugin(mqttPlugin);
|
|
|
|
displayPlugin->display->init();
|
|
displayPlugin->display->flipScreenVertically();
|
|
displayPlugin->splashScreen("Wibbly", "Wobbly", "0.0.1", "Sprocket");
|
|
|
|
network = new WiFiNet(
|
|
SPROCKET_MODE,
|
|
STATION_SSID,
|
|
STATION_PASSWORD,
|
|
AP_SSID,
|
|
AP_PASSWORD,
|
|
HOSTNAME,
|
|
CONNECT_TIMEOUT);
|
|
network->init();
|
|
if (network->connect())
|
|
{
|
|
sprocket->activate();
|
|
displayPlugin->display->flipScreenVertically();
|
|
sprocket->publish("ui/clear", "");
|
|
sprocket->publish("ui/print",
|
|
"Heap: " + String(ESP.getFreeHeap()) + "\n" +
|
|
"Host: " + String(network->config.hostname) + "\n" +
|
|
"AP: " + String(network->config.stationSSID) + "\n" +
|
|
"IP: " + WiFi.localIP().toString() + "\n" +
|
|
"Gateway: " + WiFi.gatewayIP().toString());
|
|
}
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
sprocket->loop();
|
|
yield();
|
|
} |