From 4e69dbc471aa1805d61a08e296bcd44a3a2a1cd5 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Mon, 19 Nov 2018 21:19:56 +0100 Subject: [PATCH 1/7] update mqtt, implement basic chat fnc --- data/mqttConfig.json | 5 +-- platformio.ini | 15 +++++++ src/var/illuchat/illuchat_config.h | 56 ++++++++++++++++++++++++ src/var/illuchat/main.cpp | 69 ++++++++++++++++++++++++++++++ src/var/mqcatt/main.cpp | 2 +- src/var/mqcatt/mqcatt_config.h | 3 +- 6 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 src/var/illuchat/illuchat_config.h create mode 100644 src/var/illuchat/main.cpp diff --git a/data/mqttConfig.json b/data/mqttConfig.json index 7b1b6e6..df0e9dc 100644 --- a/data/mqttConfig.json +++ b/data/mqttConfig.json @@ -1,7 +1,6 @@ { - "mqttClientName" : "illucat00", + "mqttClientName" : "illucat", "mqttBrokerHost" : "192.168.1.2", "mqttBrokerPort" : 1883, - "mqttInTopicRoot" : "wirelos/led-in/", - "mqttOutTopicRoot" : "wirelos/led-out/" + "mqttRootTopic" : "wirelos/led" } \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 8699069..cb18957 100644 --- a/platformio.ini +++ b/platformio.ini @@ -79,6 +79,21 @@ 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 + +[env:illuchat] +src_filter = +<*> - + +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} diff --git a/src/var/illuchat/illuchat_config.h b/src/var/illuchat/illuchat_config.h new file mode 100644 index 0000000..cad44b8 --- /dev/null +++ b/src/var/illuchat/illuchat_config.h @@ -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 \ No newline at end of file diff --git a/src/var/illuchat/main.cpp b/src/var/illuchat/main.cpp new file mode 100644 index 0000000..debf392 --- /dev/null +++ b/src/var/illuchat/main.cpp @@ -0,0 +1,69 @@ +#include "illuchat_config.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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(); +} \ No newline at end of file diff --git a/src/var/mqcatt/main.cpp b/src/var/mqcatt/main.cpp index ec7d85d..c6f688f 100644 --- a/src/var/mqcatt/main.cpp +++ b/src/var/mqcatt/main.cpp @@ -21,7 +21,7 @@ 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_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}); webConfigPlugin = new WebConfigPlugin(webServerPlugin->server); webApiPlugin = new WebApiPlugin(webServerPlugin->server); diff --git a/src/var/mqcatt/mqcatt_config.h b/src/var/mqcatt/mqcatt_config.h index 9d5b9fa..fe82687 100644 --- a/src/var/mqcatt/mqcatt_config.h +++ b/src/var/mqcatt/mqcatt_config.h @@ -40,8 +40,7 @@ #define MQTT_CLIENT_NAME "illucat" #define MQTT_HOST "192.168.1.2" #define MQTT_PORT 1883 -#define MQTT_TOPIC_IN "wirelos/led-in/" -#define MQTT_TOPIC_OUT "wirelos/led-out/" +#define MQTT_ROOT_TOPIC "wirelos/illucat" // OTA config #define OTA_PORT 8266 From f754e7640f40f4d87314e5957f3f890c54a25a8b Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Mon, 19 Nov 2018 21:20:13 +0100 Subject: [PATCH 2/7] update mqtt, implement basic chat fnc --- src/var/illuchat/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/var/illuchat/main.cpp b/src/var/illuchat/main.cpp index debf392..2a437c3 100644 --- a/src/var/illuchat/main.cpp +++ b/src/var/illuchat/main.cpp @@ -45,10 +45,9 @@ void setup() 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) { + sprocket->subscribe("chat/log", [mqttChatTopic](String msg) { PRINT_MSG(Serial, "CHAT", msg.c_str()); }); - sprocket->subscribe("mqtt/connect", [mqttChatTopic](String msg) { if (msg.length() > 0) { From 6f1afc1bc189e7ec0ecec12166c8987f860df01d Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Mon, 19 Nov 2018 22:58:44 +0100 Subject: [PATCH 3/7] chat backend --- src/var/illuchat/main.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/var/illuchat/main.cpp b/src/var/illuchat/main.cpp index 2a437c3..3f8e40e 100644 --- a/src/var/illuchat/main.cpp +++ b/src/var/illuchat/main.cpp @@ -44,16 +44,23 @@ void setup() 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", [mqttChatTopic](String msg) { - PRINT_MSG(Serial, "CHAT", msg.c_str()); - }); - sprocket->subscribe("mqtt/connect", [mqttChatTopic](String msg) { + const char* mqChatTopic = "wirelos/chat/log"; + const char* outChatTopic = "out/chat/log"; + const char* chatUser = "user"; + + sprocket->subscribe("mqtt/connect", [mqChatTopic, outChatTopic, chatUser](String msg) { if (msg.length() > 0) { - mqttPlugin->client->subscribe(mqttChatTopic); - sprocket->subscribe("/out/chat/log", [](String msg) { + mqttPlugin->client->subscribe(mqChatTopic); + sprocket->subscribe(mqChatTopic, [](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, chatUser](String msg) { + PRINT_MSG(Serial, "CHAT", msg.c_str()); + mqttPlugin->client->publish(mqChatTopic, (String(chatUser) + ": " + msg).c_str()); }); } }); From 62186af303dc128dc2946a0cb5344396ca2aa670 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Fri, 23 Nov 2018 09:46:41 +0100 Subject: [PATCH 4/7] separate fw variation for chat --- data/mqttConfig.json | 2 +- data/www/favicon-32x32.png | Bin 0 -> 3155 bytes data/www/gradients.json | 4 -- data/www/index.html | 6 +++ data/www/script.js | 92 +++++++++++++++++++++++++++++++++++-- data/www/styles.css | 23 +++++++++- platformio.ini | 2 +- src/var/illuchat/main.cpp | 18 +++++--- 8 files changed, 130 insertions(+), 17 deletions(-) create mode 100644 data/www/favicon-32x32.png diff --git a/data/mqttConfig.json b/data/mqttConfig.json index df0e9dc..f55046a 100644 --- a/data/mqttConfig.json +++ b/data/mqttConfig.json @@ -2,5 +2,5 @@ "mqttClientName" : "illucat", "mqttBrokerHost" : "192.168.1.2", "mqttBrokerPort" : 1883, - "mqttRootTopic" : "wirelos/led" + "mqttRootTopic" : "wirelos/illucat" } \ No newline at end of file diff --git a/data/www/favicon-32x32.png b/data/www/favicon-32x32.png new file mode 100644 index 0000000000000000000000000000000000000000..0e5d4f68d380cf5eec8d24882e448b6911afadb4 GIT binary patch literal 3155 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 CU9*h< literal 0 HcmV?d00001 diff --git a/data/www/gradients.json b/data/www/gradients.json index 2b8556f..d184f8d 100644 --- a/data/www/gradients.json +++ b/data/www/gradients.json @@ -3,10 +3,6 @@ "text": "None", "value": ["#000000", "#000000"] }, - { - "text": "Stadler", - "value": ["#0B3F75", "#0B3F75"] - }, { "text": "Blu", "value": ["#00416A", "#E4E5E6"] diff --git a/data/www/index.html b/data/www/index.html index c1ee593..34223a0 100644 --- a/data/www/index.html +++ b/data/www/index.html @@ -60,6 +60,12 @@ +
+ IlluChat +
+
+
+
Settings
diff --git a/data/www/script.js b/data/www/script.js index 15b4f74..152482a 100644 --- a/data/www/script.js +++ b/data/www/script.js @@ -10793,7 +10793,9 @@ __WEBPACK_IMPORTED_MODULE_0_jquery___default()(() => { let app = new __WEBPACK_IMPORTED_MODULE_1__core_App__["a" /* default */](__WEBPACK_IMPORTED_MODULE_0_jquery___default()('body')) .components(__WEBPACK_IMPORTED_MODULE_2__components_exports__) .websocket(new WebSocket(endpoint.indexOf('/') === 0 ? "ws://" + window.location.host + endpoint : endpoint)); - + app.ws.onmessage = (msg) => { + app.mediator.trigger('out/chat/log', {topic: 'out/chat/log', payload: msg.data}); + }; app.mediator.on('pixels/hue', (payload) => { let colors = payload.split(','); let msg = JSON.stringify({ @@ -10814,6 +10816,8 @@ __WEBPACK_IMPORTED_MODULE_0_jquery___default()(() => { app.mediator.trigger('pixels/color2', colors[1]); //console.log('pixels/hue: ' + msg); app.ws.send(msg); + + }); // TODO make components @@ -11045,6 +11049,9 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); /* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "ParamSelect", function() { return __WEBPACK_IMPORTED_MODULE_11__ParamSelect__["a"]; }); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_12__LedStripPatternSwitch__ = __webpack_require__(29); /* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "LedStripPatternSwitch", function() { return __WEBPACK_IMPORTED_MODULE_12__LedStripPatternSwitch__["a"]; }); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_13__Chat_Chat__ = __webpack_require__(30); +/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "Chat", function() { return __WEBPACK_IMPORTED_MODULE_13__Chat_Chat__["a"]; }); + @@ -12115,10 +12122,10 @@ class ParamWs extends __WEBPACK_IMPORTED_MODULE_1__base_TextInput_TextInput__["a obj[this.config.name] = this.value; //this.store.save(obj); console.log(this.value); - this.ctx.ws.send({ + this.ctx.ws.send(JSON.stringify({ topic: this.config.topic, payload: this.value - }); + })); this.ctx.mediator.trigger(this.config.endpoint, this.value); } @@ -12241,5 +12248,84 @@ class LedStripPatternSwitch extends __WEBPACK_IMPORTED_MODULE_1__base_Switch_Swi /* harmony export (immutable) */ __webpack_exports__["a"] = LedStripPatternSwitch; +/***/ }), +/* 30 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_jquery__ = __webpack_require__(0); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_jquery___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_jquery__); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Chat_html__ = __webpack_require__(31); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Chat_html___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__Chat_html__); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__core_Component__ = __webpack_require__(1); + + + + +class Chat extends __WEBPACK_IMPORTED_MODULE_2__core_Component__["a" /* default */] { + + constructor(ctx, node, template) { + super(ctx, node, template || __WEBPACK_IMPORTED_MODULE_1__Chat_html___default.a); + this.render(this.config); + this.ctx.mediator.on(this.config.topic, this.onMessage.bind(this)); + this.node.delegate('input.msg', 'keypress', this.onInput.bind(this)); + this.node.delegate('button', 'click', this.send.bind(this)); + } + + templates() { + return { + message: (user, msg) => ` +
  • + ${user} + ${msg} +
  • + ` + }; + } + + onMessage(msg) { + let payload = msg.payload; //.replace(/<.+?>/g, ''); + //console.log('onMsg: ' + msg); + let msgParts = payload.split(':'); + let messages = this.node.find('.messages'); + messages.append( + this.templates().message(msgParts[0], msgParts[1] ? msgParts[1] : '') + ); + this.node.find('.message-container').animate({ + scrollTop: messages[0].scrollHeight + }, 250); + } + sanitizeInput(val) { + return val.replace(/<.+?>/g, ''); + } + send(evt) { + evt.preventDefault(); + let username = this.node.find('input.username'); + let msg = this.node.find('input.msg'); + if (username.length > 0 && msg.length > 0) { + let message = JSON.stringify({ + topic: this.sanitizeInput(this.config.topic), + payload: this.sanitizeInput(username.val() + ':' + msg.val()) + }); + this.ctx.ws.send(message); + msg.val(''); + } + } + onInput(evt) { + if (evt.keyCode === 13) { + this.send(evt); + } + } + +} +/* harmony export (immutable) */ __webpack_exports__["a"] = Chat; + + +/***/ }), +/* 31 */ +/***/ (function(module, exports) { + +module.exports = "
    \n
      \n
    • \n \n \n
    • \n
    \n
    \n
      \n
      \n
        \n
      • \n \n \n
      • \n
      \n \n
      " + /***/ }) /******/ ]); \ No newline at end of file diff --git a/data/www/styles.css b/data/www/styles.css index fb13cdf..dd04a28 100644 --- a/data/www/styles.css +++ b/data/www/styles.css @@ -31,7 +31,7 @@ .sui label { color: #b3b2b2; } -.sui button, .sui input[type=file] { +.sui button { background: #097479; color: #eeeeee; font-size: 0.9em; @@ -306,3 +306,24 @@ form .form-row input[type="checkbox"] { .sui select option { background: #333333; } +.Chat .message-container { + max-height: 200px; + overflow: auto; +} +.Chat .message-container .messages { + list-style-type: none; +} +.Chat .message-container .messages .user-label { + color: lightblue; +} +.Chat .message-container .messages .user-label:before { + color: #097479; + content: '<'; +} +.Chat .message-container .messages .user-label:after { + color: #097479; + content: '>'; +} +.Chat .message-container .messages .message-text { + font-weight: normal; +} diff --git a/platformio.ini b/platformio.ini index cb18957..5253e31 100644 --- a/platformio.ini +++ b/platformio.ini @@ -86,7 +86,7 @@ lib_deps = ${common.lib_deps} https://gitlab.com/wirelos/sprocket-plugin-web.git https://gitlab.com/wirelos/sprocket-plugin-mqtt.git PubSubClient - + [env:illuchat] src_filter = +<*> - + platform = ${common.platform} diff --git a/src/var/illuchat/main.cpp b/src/var/illuchat/main.cpp index 3f8e40e..ecf0dcb 100644 --- a/src/var/illuchat/main.cpp +++ b/src/var/illuchat/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include WiFiNet *network; Sprocket *sprocket; @@ -16,6 +17,7 @@ WebConfigPlugin *webConfigPlugin; WebApiPlugin *webApiPlugin; PixelPlugin *pixelPlugin; MqttPlugin *mqttPlugin; +OtaTcpPlugin *otaTcpPlugin; void setup() { @@ -25,11 +27,14 @@ void setup() 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); network = new WiFiNet( WIFI_MODE, @@ -44,11 +49,10 @@ void setup() webServerPlugin->server->serveStatic(PIXEL_CONFIG_FILE, SPIFFS, "pixelConfig.json"); webServerPlugin->server->serveStatic(MQTT_CONFIG_FILE, SPIFFS, "mqttConfig.json"); - const char* mqChatTopic = "wirelos/chat/log"; - const char* outChatTopic = "out/chat/log"; - const char* chatUser = "user"; + const char *mqChatTopic = "wirelos/chat/log"; + const char *outChatTopic = "out/chat/log"; - sprocket->subscribe("mqtt/connect", [mqChatTopic, outChatTopic, chatUser](String msg) { + sprocket->subscribe("mqtt/connect", [mqChatTopic, outChatTopic](String msg) { if (msg.length() > 0) { mqttPlugin->client->subscribe(mqChatTopic); @@ -58,9 +62,9 @@ void setup() }); // send message from WS to this topic - sprocket->subscribe(outChatTopic, [mqChatTopic, chatUser](String msg) { - PRINT_MSG(Serial, "CHAT", msg.c_str()); - mqttPlugin->client->publish(mqChatTopic, (String(chatUser) + ": " + msg).c_str()); + sprocket->subscribe(outChatTopic, [mqChatTopic](String msg) { + PRINT_MSG(Serial, "CHAT", String("outgoing: " + msg).c_str()); + mqttPlugin->client->publish(mqChatTopic, msg.c_str()); }); } }); From f7ba31c2d2b87e2c578a4eb21f34a9c0bb088c04 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Fri, 23 Nov 2018 17:15:56 +0100 Subject: [PATCH 5/7] change chat to irc --- .project | 11 ++++++++ data/ircConfig.json | 6 +++++ data/pixelConfig.json | 2 +- data/www/index.html | 8 +++--- data/www/script.js | 40 +++++++++++++++++++++++++----- platformio.ini | 4 +-- src/var/illuchat/illuchat_config.h | 10 ++++---- src/var/illuchat/main.cpp | 34 +++++++++++-------------- 8 files changed, 78 insertions(+), 37 deletions(-) create mode 100644 .project create mode 100644 data/ircConfig.json diff --git a/.project b/.project new file mode 100644 index 0000000..1a19211 --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ + + + illucat + + + + + + + + diff --git a/data/ircConfig.json b/data/ircConfig.json new file mode 100644 index 0000000..4390db3 --- /dev/null +++ b/data/ircConfig.json @@ -0,0 +1,6 @@ +{ + "ircServer": "chat.freenode.net", + "ircPort": 6665, + "ircNickname": "redcat", + "ircUser": "redcat" +} \ No newline at end of file diff --git a/data/pixelConfig.json b/data/pixelConfig.json index d45d7b9..8adce06 100644 --- a/data/pixelConfig.json +++ b/data/pixelConfig.json @@ -1,7 +1,7 @@ { "pin": 4, "length": 8, - "brightness": 100, + "brightness": 127, "updateInterval": 100, "defaultColor": 100 } \ No newline at end of file diff --git a/data/www/index.html b/data/www/index.html index 34223a0..a42d1a2 100644 --- a/data/www/index.html +++ b/data/www/index.html @@ -2,7 +2,7 @@ - ESP Kit + IlluCat @@ -73,8 +73,10 @@

      NeoPixel

      -

      MQTT

      -
      + +

      IRC

      +
      diff --git a/data/www/script.js b/data/www/script.js index 152482a..b2f0c68 100644 --- a/data/www/script.js +++ b/data/www/script.js @@ -12268,8 +12268,11 @@ class Chat extends __WEBPACK_IMPORTED_MODULE_2__core_Component__["a" /* default super(ctx, node, template || __WEBPACK_IMPORTED_MODULE_1__Chat_html___default.a); this.render(this.config); this.ctx.mediator.on(this.config.topic, this.onMessage.bind(this)); + this.ctx.mediator.on("chat/connected", this.connected.bind(this)); + //this.ctx.mediator.on("irc/configValid", this.configValid.bind(this)); this.node.delegate('input.msg', 'keypress', this.onInput.bind(this)); - this.node.delegate('button', 'click', this.send.bind(this)); + this.node.delegate('button.send', 'click', this.send.bind(this)); + this.node.delegate('button.join', 'click', this.join.bind(this)); } templates() { @@ -12279,17 +12282,43 @@ class Chat extends __WEBPACK_IMPORTED_MODULE_2__core_Component__["a" /* default ${user} ${msg} + `, + serverMessage: (msg) => ` +
    • + ${msg} +
    • ` }; } + configValid() { + this.node.text("Please configure first"); + } + + join(evt) { + evt.preventDefault(); + let message = JSON.stringify({ + topic: 'irc/join', + payload: this.sanitizeInput(this.node.find('.channel').val()) + }); + this.ctx.ws.send(message); + this.node.find('.controls').show(); + //this.node.find('button.join').hide(); + } + connected() { + this.node.find('.controls').show(); + this.node.find('button.connect').hide(); + } + onMessage(msg) { let payload = msg.payload; //.replace(/<.+?>/g, ''); //console.log('onMsg: ' + msg); let msgParts = payload.split(':'); let messages = this.node.find('.messages'); messages.append( - this.templates().message(msgParts[0], msgParts[1] ? msgParts[1] : '') + msgParts.length == 2 ? + this.templates().message(msgParts[0], this.sanitizeInput(msgParts[1])) + : this.templates().serverMessage(this.sanitizeInput(payload)) ); this.node.find('.message-container').animate({ scrollTop: messages[0].scrollHeight @@ -12300,12 +12329,11 @@ class Chat extends __WEBPACK_IMPORTED_MODULE_2__core_Component__["a" /* default } send(evt) { evt.preventDefault(); - let username = this.node.find('input.username'); let msg = this.node.find('input.msg'); - if (username.length > 0 && msg.length > 0) { + if (msg.length > 0) { let message = JSON.stringify({ topic: this.sanitizeInput(this.config.topic), - payload: this.sanitizeInput(username.val() + ':' + msg.val()) + payload: this.sanitizeInput(msg.val()) }); this.ctx.ws.send(message); msg.val(''); @@ -12325,7 +12353,7 @@ class Chat extends __WEBPACK_IMPORTED_MODULE_2__core_Component__["a" /* default /* 31 */ /***/ (function(module, exports) { -module.exports = "
      \n
        \n
      • \n \n \n
      • \n
      \n
      \n
        \n
        \n
          \n
        • \n \n \n
        • \n
        \n \n
        " +module.exports = "
        \n
          \n
        • \n \n \n \n \n \n
        • \n
        \n
        \n
          \n
          \n
            \n
          • \n \n \n
          • \n
          \n
          " /***/ }) /******/ ]); \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 5253e31..8860265 100644 --- a/platformio.ini +++ b/platformio.ini @@ -99,5 +99,5 @@ build_flags = -Wl,-Teagle.flash.4m1m.ld 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 \ No newline at end of file + https://gitlab.com/wirelos/sprocket-plugin-irc.git + ArduinoIRC diff --git a/src/var/illuchat/illuchat_config.h b/src/var/illuchat/illuchat_config.h index cad44b8..2acadb1 100644 --- a/src/var/illuchat/illuchat_config.h +++ b/src/var/illuchat/illuchat_config.h @@ -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 diff --git a/src/var/illuchat/main.cpp b/src/var/illuchat/main.cpp index ecf0dcb..ea8015b 100644 --- a/src/var/illuchat/main.cpp +++ b/src/var/illuchat/main.cpp @@ -7,8 +7,7 @@ #include #include #include -#include -#include +#include 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() From efa9849f1bb137fe44283b8bcb49d62277a08b64 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sat, 24 Nov 2018 14:15:17 +0100 Subject: [PATCH 6/7] enable ota over tcp --- src/var/illuchat/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/var/illuchat/main.cpp b/src/var/illuchat/main.cpp index ea8015b..d6abeec 100644 --- a/src/var/illuchat/main.cpp +++ b/src/var/illuchat/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include WiFiNet *network; Sprocket *sprocket; @@ -16,6 +17,7 @@ WebConfigPlugin *webConfigPlugin; WebApiPlugin *webApiPlugin; PixelPlugin *pixelPlugin; IrcPlugin *ircPlugin; +OtaTcpPlugin *otaTcp; void setup() { @@ -26,11 +28,13 @@ void setup() webServerPlugin = new WebServerPlugin({WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE, WEB_PORT}); webConfigPlugin = new WebConfigPlugin(webServerPlugin->server); webApiPlugin = new WebApiPlugin(webServerPlugin->server); + otaTcp = new OtaTcpPlugin({OTA_PORT, OTA_PASSWORD}); sprocket->addPlugin(pixelPlugin); sprocket->addPlugin(webServerPlugin); sprocket->addPlugin(webConfigPlugin); sprocket->addPlugin(webApiPlugin); + sprocket->addPlugin(otaTcp); sprocket->addPlugin(ircPlugin); network = new WiFiNet( From b24077de526916a34ac49d6b49ba1ceabfc07118 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sat, 24 Nov 2018 17:27:21 +0100 Subject: [PATCH 7/7] reenable ota --- data/mqttConfig.json | 2 +- data/www/index.html | 4 ++-- platformio.ini | 2 ++ src/var/illuchat/illuchat_config.h | 6 ++++++ src/var/illuchat/main.cpp | 5 +++++ src/var/mqcatt/mqcatt_config.h | 9 +++++---- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/data/mqttConfig.json b/data/mqttConfig.json index f55046a..789897d 100644 --- a/data/mqttConfig.json +++ b/data/mqttConfig.json @@ -2,5 +2,5 @@ "mqttClientName" : "illucat", "mqttBrokerHost" : "192.168.1.2", "mqttBrokerPort" : 1883, - "mqttRootTopic" : "wirelos/illucat" + "mqttRootTopic" : "wirelos/led/illucat" } \ No newline at end of file diff --git a/data/www/index.html b/data/www/index.html index a42d1a2..69e9946 100644 --- a/data/www/index.html +++ b/data/www/index.html @@ -73,8 +73,8 @@

          NeoPixel

          - +

          MQTT

          +

          IRC

          diff --git a/platformio.ini b/platformio.ini index 8860265..7616473 100644 --- a/platformio.ini +++ b/platformio.ini @@ -100,4 +100,6 @@ 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-irc.git + https://gitlab.com/wirelos/sprocket-plugin-mqtt.git + PubSubClient ArduinoIRC diff --git a/src/var/illuchat/illuchat_config.h b/src/var/illuchat/illuchat_config.h index 2acadb1..41b90b7 100644 --- a/src/var/illuchat/illuchat_config.h +++ b/src/var/illuchat/illuchat_config.h @@ -52,5 +52,11 @@ #define WEB_DEFAULT_FILE "index.html" #define WEB_PORT 80 +// mqtt config +#define MQTT_CLIENT_NAME "illucat" +#define MQTT_HOST "192.168.1.2" +#define MQTT_PORT 1883 +#define MQTT_ROOT_TOPIC "wirelos/led/illucat" + #endif \ No newline at end of file diff --git a/src/var/illuchat/main.cpp b/src/var/illuchat/main.cpp index d6abeec..c6ecb61 100644 --- a/src/var/illuchat/main.cpp +++ b/src/var/illuchat/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include WiFiNet *network; Sprocket *sprocket; @@ -18,6 +19,7 @@ WebApiPlugin *webApiPlugin; PixelPlugin *pixelPlugin; IrcPlugin *ircPlugin; OtaTcpPlugin *otaTcp; +MqttPlugin *mqttPlugin; void setup() { @@ -25,6 +27,7 @@ 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, chipName, chipName}); + 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); @@ -36,6 +39,7 @@ void setup() sprocket->addPlugin(webApiPlugin); sprocket->addPlugin(otaTcp); sprocket->addPlugin(ircPlugin); + sprocket->addPlugin(mqttPlugin); network = new WiFiNet( WIFI_MODE, @@ -49,6 +53,7 @@ void setup() webServerPlugin->server->serveStatic(PIXEL_CONFIG_FILE, SPIFFS, "pixelConfig.json"); webServerPlugin->server->serveStatic(IRC_CONFIG_FILE, SPIFFS, "ircConfig.json"); + webServerPlugin->server->serveStatic(MQTT_CONFIG_FILE, SPIFFS, "mqttConfig.json"); sprocket->subscribe("irc/connected", [](String msg) { if (atoi(msg.c_str())) diff --git a/src/var/mqcatt/mqcatt_config.h b/src/var/mqcatt/mqcatt_config.h index fe82687..00b9bc5 100644 --- a/src/var/mqcatt/mqcatt_config.h +++ b/src/var/mqcatt/mqcatt_config.h @@ -36,16 +36,17 @@ #define COLOR_CONNECTED LED_STRIP_DEFAULT_COLOR #define COLOR_NOT_CONNECTED 255 + +// OTA config +#define OTA_PORT 8266 +#define OTA_PASSWORD "" + // 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"