mirror of
https://gitlab.com/zwirbel/tardis.git
synced 2025-12-16 18:05:05 +01:00
tardis base
This commit is contained in:
62
src/config.h
Normal file
62
src/config.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#ifndef __TARDIS_CONFIG__
|
||||
#define __TARDIS_CONFIG__
|
||||
|
||||
// Scheduler config
|
||||
#define _TASK_SLEEP_ON_IDLE_RUN
|
||||
#define _TASK_STD_FUNCTION
|
||||
#define _TASK_PRIORITY
|
||||
|
||||
// Chip config
|
||||
#define SPROCKET_TYPE "ILLUCAT"
|
||||
#define SERIAL_BAUD_RATE 115200
|
||||
#define STARTUP_DELAY 1000
|
||||
|
||||
// Network config
|
||||
#define WIFI_MODE 1
|
||||
#define WIFI_CHANNEL 11
|
||||
#define AP_SSID "tardis"
|
||||
#define AP_PASSWORD "th3r31sn0sp00n"
|
||||
#define STATION_SSID "MyAP"
|
||||
#define STATION_PASSWORD "th3r31sn0sp00n"
|
||||
#define HOSTNAME "tardis"
|
||||
#define CONNECT_TIMEOUT 10000
|
||||
|
||||
// config files
|
||||
#define PIXEL_CONFIG_FILE "/pixelConfig.json"
|
||||
#define MQTT_CONFIG_FILE "/mqttConfig.json"
|
||||
#define IRC_CONFIG_FILE "/ircConfig.json"
|
||||
|
||||
// NeoPixel
|
||||
#define LED_STRIP_PIN D2
|
||||
#define LED_STRIP_LENGTH 8
|
||||
#define LED_STRIP_BRIGHTNESS 48
|
||||
#define LED_STRIP_UPDATE_INTERVAL 200
|
||||
#define LED_STRIP_DEFAULT_COLOR 100
|
||||
#define COLOR_CONNECTED LED_STRIP_DEFAULT_COLOR
|
||||
#define COLOR_NOT_CONNECTED 255
|
||||
|
||||
#define IRC_SERVER "chat.freenode.net"
|
||||
#define IRC_PORT 6665
|
||||
#define IRC_NICKNAME ""
|
||||
#define IRC_USER ""
|
||||
|
||||
// OTA config
|
||||
#define OTA_PORT 8266
|
||||
#define OTA_PASSWORD ""
|
||||
|
||||
// WebServer
|
||||
#define WEB_CONTEXT_PATH "/"
|
||||
#define WEB_DOC_ROOT "/www"
|
||||
#define WEB_DEFAULT_FILE "index.html"
|
||||
#define WEB_PORT 80
|
||||
|
||||
// mqtt config
|
||||
#define MQTT_CLIENT_NAME "tardis"
|
||||
#define MQTT_HOST "192.168.1.2"
|
||||
#define MQTT_PORT 1883
|
||||
#define MQTT_ROOT_TOPIC "wirelos/led/tardis"
|
||||
|
||||
// RC Switch
|
||||
#define PIN_RC_TX D8
|
||||
|
||||
#endif
|
||||
106
src/main.cpp
Normal file
106
src/main.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "config.h"
|
||||
#include <WiFiNet.h>
|
||||
#include <Sprocket.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <WebServerConfig.h>
|
||||
#include <WebServerPlugin.h>
|
||||
#include <WebConfigPlugin.h>
|
||||
#include <WebApiPlugin.h>
|
||||
#include <PixelPlugin.h>
|
||||
#include <IrcPlugin.h>
|
||||
#include <OtaTcpPlugin.cpp>
|
||||
#include <MqttPlugin.h>
|
||||
#include <RcSwitchPlugin.h>
|
||||
|
||||
WiFiNet *network;
|
||||
Sprocket *sprocket;
|
||||
WebServerPlugin *webServerPlugin;
|
||||
WebConfigPlugin *webConfigPlugin;
|
||||
WebApiPlugin *webApiPlugin;
|
||||
PixelPlugin *pixelPlugin;
|
||||
IrcPlugin *ircPlugin;
|
||||
OtaTcpPlugin *otaTcpPlugin;
|
||||
MqttPlugin *mqttPlugin;
|
||||
RcSwitchPlugin *rcSwitchPlugin;
|
||||
|
||||
void serveWebConfig(AsyncWebServer *server)
|
||||
{
|
||||
server->serveStatic(PIXEL_CONFIG_FILE, SPIFFS, "pixelConfig.json");
|
||||
server->serveStatic(IRC_CONFIG_FILE, SPIFFS, "ircConfig.json");
|
||||
server->serveStatic(MQTT_CONFIG_FILE, SPIFFS, "mqttConfig.json");
|
||||
}
|
||||
|
||||
void subscribeChat(Sprocket *sprocket)
|
||||
{
|
||||
sprocket->subscribe("irc/connected", [sprocket](String msg) {
|
||||
if (atoi(msg.c_str()))
|
||||
{
|
||||
sprocket->subscribe("irc/log", [sprocket](String msg) {
|
||||
PRINT_MSG(Serial, "CHAT", String("irc/log: " + msg).c_str());
|
||||
sprocket->publish("ws/broadcast", msg);
|
||||
});
|
||||
sprocket->subscribe("out/chat/log", [sprocket](String msg) {
|
||||
PRINT_MSG(Serial, "CHAT", String("out/chat/log: " + msg).c_str());
|
||||
sprocket->publish("irc/sendMessage", msg);
|
||||
sprocket->publish("ws/broadcast", "You:" + msg);
|
||||
});
|
||||
sprocket->publish("chat/connected", "");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void subscribeTardis(Sprocket *sprocket, NeoPattern *pixels)
|
||||
{
|
||||
sprocket->subscribe("tardis/wibbly", [pixels](String msg) {
|
||||
pixels->Fade(0, pixels->Color(255, 255, 255), 4, 100, FORWARD);
|
||||
});
|
||||
sprocket->subscribe("tardis/wobbly", [pixels](String msg) {
|
||||
pixels->Scanner(pixels->Color(0, 255, 255), 100);
|
||||
});
|
||||
sprocket->subscribe("irc/connected", [sprocket](String msg) {
|
||||
sprocket->publish("tardis/wobbly", msg);
|
||||
});
|
||||
}
|
||||
|
||||
void start(Sprocket *sprocket)
|
||||
{
|
||||
sprocket->activate();
|
||||
sprocket->publish("tardis/wibbly", "");
|
||||
sprocket->publish("irc/connect", "");
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
sprocket = new Sprocket({STARTUP_DELAY, SERIAL_BAUD_RATE});
|
||||
pixelPlugin = new PixelPlugin({LED_STRIP_PIN, LED_STRIP_LENGTH, LED_STRIP_BRIGHTNESS, LED_STRIP_UPDATE_INTERVAL});
|
||||
ircPlugin = new IrcPlugin({IRC_SERVER, IRC_PORT, IRC_NICKNAME, IRC_USER});
|
||||
mqttPlugin = new MqttPlugin({MQTT_CLIENT_NAME, MQTT_HOST, MQTT_PORT, MQTT_ROOT_TOPIC});
|
||||
webServerPlugin = new WebServerPlugin({WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE, WEB_PORT});
|
||||
webConfigPlugin = new WebConfigPlugin(webServerPlugin->server);
|
||||
webApiPlugin = new WebApiPlugin(webServerPlugin->server);
|
||||
otaTcpPlugin = new OtaTcpPlugin({OTA_PORT, OTA_PASSWORD});
|
||||
rcSwitchPlugin = new RcSwitchPlugin({PIN_RC_TX});
|
||||
network = new WiFiNet(WIFI_MODE, STATION_SSID, STATION_PASSWORD, AP_SSID, AP_PASSWORD, HOSTNAME, CONNECT_TIMEOUT);
|
||||
|
||||
sprocket->addPlugin(pixelPlugin);
|
||||
sprocket->addPlugin(webServerPlugin);
|
||||
sprocket->addPlugin(webConfigPlugin);
|
||||
sprocket->addPlugin(webApiPlugin);
|
||||
sprocket->addPlugin(otaTcpPlugin);
|
||||
sprocket->addPlugin(ircPlugin);
|
||||
sprocket->addPlugin(rcSwitchPlugin);
|
||||
sprocket->addPlugin(mqttPlugin);
|
||||
network->connect();
|
||||
|
||||
serveWebConfig(webServerPlugin->server);
|
||||
subscribeChat(sprocket);
|
||||
subscribeTardis(sprocket, pixelPlugin->pixels);
|
||||
start(sprocket);
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
sprocket->loop();
|
||||
yield();
|
||||
}
|
||||
Reference in New Issue
Block a user