mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-15 01:42:22 +01:00
update mqtt, implement basic chat fnc
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"mqttClientName" : "illucat00",
|
"mqttClientName" : "illucat",
|
||||||
"mqttBrokerHost" : "192.168.1.2",
|
"mqttBrokerHost" : "192.168.1.2",
|
||||||
"mqttBrokerPort" : 1883,
|
"mqttBrokerPort" : 1883,
|
||||||
"mqttInTopicRoot" : "wirelos/led-in/",
|
"mqttRootTopic" : "wirelos/led"
|
||||||
"mqttOutTopicRoot" : "wirelos/led-out/"
|
|
||||||
}
|
}
|
||||||
@@ -86,3 +86,18 @@ lib_deps = ${common.lib_deps}
|
|||||||
https://gitlab.com/wirelos/sprocket-plugin-web.git
|
https://gitlab.com/wirelos/sprocket-plugin-web.git
|
||||||
https://gitlab.com/wirelos/sprocket-plugin-mqtt.git
|
https://gitlab.com/wirelos/sprocket-plugin-mqtt.git
|
||||||
PubSubClient
|
PubSubClient
|
||||||
|
|
||||||
|
[env:illuchat]
|
||||||
|
src_filter = +<*> -<var/> +<var/illuchat/>
|
||||||
|
platform = ${common.platform}
|
||||||
|
board = ${common.board}
|
||||||
|
upload_speed = ${common.upload_speed}
|
||||||
|
monitor_baud = ${common.monitor_baud}
|
||||||
|
framework = ${common.framework}
|
||||||
|
build_flags = -Wl,-Teagle.flash.4m1m.ld
|
||||||
|
-DSPROCKET_PRINT=1
|
||||||
|
lib_deps = ${common.lib_deps}
|
||||||
|
https://gitlab.com/wirelos/sprocket-network-wifi.git
|
||||||
|
https://gitlab.com/wirelos/sprocket-plugin-web.git
|
||||||
|
https://gitlab.com/wirelos/sprocket-plugin-mqtt.git
|
||||||
|
PubSubClient
|
||||||
56
src/var/illuchat/illuchat_config.h
Normal file
56
src/var/illuchat/illuchat_config.h
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#ifndef __ILLUCHAT_CONFIG__
|
||||||
|
#define __ILLUCHAT_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 0
|
||||||
|
#define WIFI_CHANNEL 11
|
||||||
|
#define AP_SSID "illucat"
|
||||||
|
#define AP_PASSWORD "illumination"
|
||||||
|
#define MESH_PREFIX "illucat-mesh"
|
||||||
|
#define MESH_PASSWORD "th3r31sn0sp00n"
|
||||||
|
#define STATION_SSID "MyAP"
|
||||||
|
#define STATION_PASSWORD "th3r31sn0sp00n"
|
||||||
|
#define HOSTNAME "illucat"
|
||||||
|
#define CONNECT_TIMEOUT 10000
|
||||||
|
|
||||||
|
// config files
|
||||||
|
#define PIXEL_CONFIG_FILE "/pixelConfig.json"
|
||||||
|
#define MQTT_CONFIG_FILE "/mqttConfig.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
|
||||||
|
|
||||||
|
// mqtt config
|
||||||
|
#define MQTT_CLIENT_NAME "illucat"
|
||||||
|
#define MQTT_HOST "192.168.1.2"
|
||||||
|
#define MQTT_PORT 1883
|
||||||
|
#define MQTT_ROOT_TOPIC "wirelos/illucat"
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
69
src/var/illuchat/main.cpp
Normal file
69
src/var/illuchat/main.cpp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#include "illuchat_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 <MqttPlugin.h>
|
||||||
|
|
||||||
|
WiFiNet *network;
|
||||||
|
Sprocket *sprocket;
|
||||||
|
WebServerPlugin *webServerPlugin;
|
||||||
|
WebConfigPlugin *webConfigPlugin;
|
||||||
|
WebApiPlugin *webApiPlugin;
|
||||||
|
PixelPlugin *pixelPlugin;
|
||||||
|
MqttPlugin *mqttPlugin;
|
||||||
|
|
||||||
|
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});
|
||||||
|
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);
|
||||||
|
sprocket->addPlugin(pixelPlugin);
|
||||||
|
sprocket->addPlugin(webServerPlugin);
|
||||||
|
sprocket->addPlugin(webConfigPlugin);
|
||||||
|
sprocket->addPlugin(webApiPlugin);
|
||||||
|
sprocket->addPlugin(mqttPlugin);
|
||||||
|
|
||||||
|
network = new WiFiNet(
|
||||||
|
WIFI_MODE,
|
||||||
|
STATION_SSID,
|
||||||
|
STATION_PASSWORD,
|
||||||
|
AP_SSID,
|
||||||
|
AP_PASSWORD,
|
||||||
|
HOSTNAME,
|
||||||
|
CONNECT_TIMEOUT);
|
||||||
|
network->connect();
|
||||||
|
|
||||||
|
webServerPlugin->server->serveStatic(PIXEL_CONFIG_FILE, SPIFFS, "pixelConfig.json");
|
||||||
|
webServerPlugin->server->serveStatic(MQTT_CONFIG_FILE, SPIFFS, "mqttConfig.json");
|
||||||
|
|
||||||
|
const char* mqttChatTopic = (String(MQTT_ROOT_TOPIC) + "/out/chat/log").c_str();
|
||||||
|
sprocket->subscribe("chat/log", [](String msg) {
|
||||||
|
PRINT_MSG(Serial, "CHAT", msg.c_str());
|
||||||
|
});
|
||||||
|
|
||||||
|
sprocket->subscribe("mqtt/connect", [mqttChatTopic](String msg) {
|
||||||
|
if (msg.length() > 0)
|
||||||
|
{
|
||||||
|
mqttPlugin->client->subscribe(mqttChatTopic);
|
||||||
|
sprocket->subscribe("/out/chat/log", [](String msg) {
|
||||||
|
PRINT_MSG(Serial, "CHAT", String("incoming: " + msg).c_str());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sprocket->activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
sprocket->loop();
|
||||||
|
yield();
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ void setup()
|
|||||||
{
|
{
|
||||||
sprocket = new Sprocket({STARTUP_DELAY, SERIAL_BAUD_RATE});
|
sprocket = new Sprocket({STARTUP_DELAY, SERIAL_BAUD_RATE});
|
||||||
pixelPlugin = new PixelPlugin({LED_STRIP_PIN, LED_STRIP_LENGTH, LED_STRIP_BRIGHTNESS, LED_STRIP_UPDATE_INTERVAL});
|
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_TOPIC_IN, MQTT_TOPIC_OUT});
|
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});
|
webServerPlugin = new WebServerPlugin({WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE, WEB_PORT});
|
||||||
webConfigPlugin = new WebConfigPlugin(webServerPlugin->server);
|
webConfigPlugin = new WebConfigPlugin(webServerPlugin->server);
|
||||||
webApiPlugin = new WebApiPlugin(webServerPlugin->server);
|
webApiPlugin = new WebApiPlugin(webServerPlugin->server);
|
||||||
|
|||||||
@@ -40,8 +40,7 @@
|
|||||||
#define MQTT_CLIENT_NAME "illucat"
|
#define MQTT_CLIENT_NAME "illucat"
|
||||||
#define MQTT_HOST "192.168.1.2"
|
#define MQTT_HOST "192.168.1.2"
|
||||||
#define MQTT_PORT 1883
|
#define MQTT_PORT 1883
|
||||||
#define MQTT_TOPIC_IN "wirelos/led-in/"
|
#define MQTT_ROOT_TOPIC "wirelos/illucat"
|
||||||
#define MQTT_TOPIC_OUT "wirelos/led-out/"
|
|
||||||
|
|
||||||
// OTA config
|
// OTA config
|
||||||
#define OTA_PORT 8266
|
#define OTA_PORT 8266
|
||||||
|
|||||||
Reference in New Issue
Block a user