mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-16 18:05:05 +01:00
change chat to irc
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
// 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
|
||||
@@ -36,11 +37,10 @@
|
||||
#define COLOR_CONNECTED LED_STRIP_DEFAULT_COLOR
|
||||
#define COLOR_NOT_CONNECTED 255
|
||||
|
||||
// mqtt config
|
||||
#define MQTT_CLIENT_NAME "illucat"
|
||||
#define MQTT_HOST "192.168.1.2"
|
||||
#define MQTT_PORT 1883
|
||||
#define MQTT_ROOT_TOPIC "wirelos/illucat"
|
||||
#define IRC_SERVER "chat.freenode.net"
|
||||
#define IRC_PORT 6665
|
||||
#define IRC_NICKNAME ""
|
||||
#define IRC_USER ""
|
||||
|
||||
// OTA config
|
||||
#define OTA_PORT 8266
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
#include <WebConfigPlugin.h>
|
||||
#include <WebApiPlugin.h>
|
||||
#include <PixelPlugin.h>
|
||||
#include <MqttPlugin.h>
|
||||
#include <OtaTcpPlugin.cpp>
|
||||
#include <IrcPlugin.h>
|
||||
|
||||
WiFiNet *network;
|
||||
Sprocket *sprocket;
|
||||
@@ -16,25 +15,23 @@ WebServerPlugin *webServerPlugin;
|
||||
WebConfigPlugin *webConfigPlugin;
|
||||
WebApiPlugin *webApiPlugin;
|
||||
PixelPlugin *pixelPlugin;
|
||||
MqttPlugin *mqttPlugin;
|
||||
OtaTcpPlugin *otaTcpPlugin;
|
||||
IrcPlugin *ircPlugin;
|
||||
|
||||
void setup()
|
||||
{
|
||||
const char *chipName = String("Sprocket" + String(ESP.getChipId())).c_str();
|
||||
sprocket = new Sprocket({STARTUP_DELAY, SERIAL_BAUD_RATE});
|
||||
pixelPlugin = new PixelPlugin({LED_STRIP_PIN, LED_STRIP_LENGTH, LED_STRIP_BRIGHTNESS, LED_STRIP_UPDATE_INTERVAL});
|
||||
mqttPlugin = new MqttPlugin({MQTT_CLIENT_NAME, MQTT_HOST, MQTT_PORT, MQTT_ROOT_TOPIC});
|
||||
ircPlugin = new IrcPlugin({IRC_SERVER, IRC_PORT, chipName, chipName});
|
||||
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});
|
||||
|
||||
sprocket->addPlugin(pixelPlugin);
|
||||
sprocket->addPlugin(webServerPlugin);
|
||||
sprocket->addPlugin(webConfigPlugin);
|
||||
sprocket->addPlugin(webApiPlugin);
|
||||
sprocket->addPlugin(mqttPlugin);
|
||||
sprocket->addPlugin(otaTcpPlugin);
|
||||
sprocket->addPlugin(ircPlugin);
|
||||
|
||||
network = new WiFiNet(
|
||||
WIFI_MODE,
|
||||
@@ -47,29 +44,26 @@ void setup()
|
||||
network->connect();
|
||||
|
||||
webServerPlugin->server->serveStatic(PIXEL_CONFIG_FILE, SPIFFS, "pixelConfig.json");
|
||||
webServerPlugin->server->serveStatic(MQTT_CONFIG_FILE, SPIFFS, "mqttConfig.json");
|
||||
webServerPlugin->server->serveStatic(IRC_CONFIG_FILE, SPIFFS, "ircConfig.json");
|
||||
|
||||
const char *mqChatTopic = "wirelos/chat/log";
|
||||
const char *outChatTopic = "out/chat/log";
|
||||
|
||||
sprocket->subscribe("mqtt/connect", [mqChatTopic, outChatTopic](String msg) {
|
||||
if (msg.length() > 0)
|
||||
sprocket->subscribe("irc/connected", [](String msg) {
|
||||
if (atoi(msg.c_str()))
|
||||
{
|
||||
mqttPlugin->client->subscribe(mqChatTopic);
|
||||
sprocket->subscribe(mqChatTopic, [](String msg) {
|
||||
sprocket->subscribe("irc/log", [](String msg) {
|
||||
PRINT_MSG(Serial, "CHAT", String("incoming: " + msg).c_str());
|
||||
webApiPlugin->ws->textAll(msg);
|
||||
});
|
||||
|
||||
// send message from WS to this topic
|
||||
sprocket->subscribe(outChatTopic, [mqChatTopic](String msg) {
|
||||
sprocket->subscribe("out/chat/log", [](String msg) {
|
||||
PRINT_MSG(Serial, "CHAT", String("outgoing: " + msg).c_str());
|
||||
mqttPlugin->client->publish(mqChatTopic, msg.c_str());
|
||||
sprocket->publish("irc/sendMessage", msg);
|
||||
webApiPlugin->ws->textAll("You:"+msg);
|
||||
});
|
||||
sprocket->publish("chat/connected", "");
|
||||
}
|
||||
});
|
||||
|
||||
sprocket->activate();
|
||||
sprocket->publish("irc/connect","");
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
||||
Reference in New Issue
Block a user