mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-05 03:50:43 +08:00

### Maintenance page * Add add tab color for mobile view * Add spellcheck off / autocorect off in input * Add disconnect button when authenticate enabled * Add Invalid user or password message when authentication failed ### Board support * Add ESP32 S2 support * Add ESP32 S3 support * Add ESP32 C3 support ### ESP commands * Add command 701 to control GCODE streaming * Remove command 901 as duplicate * Update command 420 to add more details * Use text as default output * All json on all commands for formated output ### Core * Add benchmak function to check transfer speed (for test only-not production) * Merge code for ESP3DLib support * Add better printer display support (M117 / Serial TFT) * Use ESP32 analogWrite instead of emulated one ### Modules * Display * Refactor code * Remove SPI ILI 9341 / 9488 support as not suitable * Add ST7789 support (135x240 / 240x240) * Filesystem * Bug fixes due to esp core updates * Better SD sharing mecanism * Better global FS management * FTP * Add SD sharing support * Better global FS management * GCODE Host * Add basic support for macro files * Add ESP command support * Use not blocking method to stream commands / handle response * Notifications * Add IFTTT notification service * Add WebUI notification * Add ESP3D display notification * WebDav * Add SD sharing support * Add bug fix from https://github.com/d-a-v/ESPWebDAV * Better global FS management * Websocket * Add function to handle zombies connections * WiFi * Fix connection to AP sometime fail * Fix low signal not diplayed in ESP420 even connected * Add AP Setup mode ### Libraries * Update SDFat-2.0.6 to 2.1.2 * Update ESP32SSDP 1.1.1 to 1.2.0 * Update TFT_eSPI-1.4.11 to 2.4.61 * Update arduinoWebSockets-2.3.5 to 2.3.6 * Update esp8266-oled-ssd1306-4.0.0 to 4.3.0 * Remove lvgl support ### Tools * Add I2C scanner script * Add python script to simulate/stress printer serial communication ### PlatformIO * Use latest 4.4.0 Espressif32 release (ESP32-arduino core 2.0.3) * Add fix for Flash more than 4MB * Add Esp32 S2/S3/C3 env * Add ESP32-ST7789 / esp32-TTGO_T_Display env
151 lines
4.4 KiB
C++
151 lines
4.4 KiB
C++
/*
|
|
WebSocketClientStompOverSockJs.ino
|
|
|
|
Example for connecting and maintining a connection with a SockJS+STOMP websocket connection.
|
|
In this example, we connect to a Spring application (see https://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html).
|
|
|
|
Created on: 18.07.2017
|
|
Author: Martin Becker <mgbckr>, Contact: becker@informatik.uni-wuerzburg.de
|
|
*/
|
|
|
|
// PRE
|
|
|
|
#define USE_SERIAL Serial
|
|
|
|
|
|
// LIBRARIES
|
|
|
|
#include <Arduino.h>
|
|
#include <Hash.h>
|
|
|
|
#include <ESP8266WiFi.h>
|
|
#include <WebSocketsClient.h>
|
|
|
|
|
|
// SETTINGS
|
|
|
|
const char* wlan_ssid = "yourssid";
|
|
const char* wlan_password = "somepassword";
|
|
|
|
const char* ws_host = "the.host.net";
|
|
const int ws_port = 80;
|
|
|
|
// base URL for SockJS (websocket) connection
|
|
// The complete URL will look something like this(cf. http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-36):
|
|
// ws://<ws_host>:<ws_port>/<ws_baseurl>/<3digits>/<randomstring>/websocket
|
|
// For the default config of Spring's SockJS/STOMP support, the default base URL is "/socketentry/".
|
|
const char* ws_baseurl = "/socketentry/"; // don't forget leading and trailing "/" !!!
|
|
|
|
|
|
// VARIABLES
|
|
|
|
WebSocketsClient webSocket;
|
|
|
|
|
|
// FUNCTIONS
|
|
|
|
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
|
|
|
|
switch (type) {
|
|
case WStype_DISCONNECTED:
|
|
USE_SERIAL.printf("[WSc] Disconnected!\n");
|
|
break;
|
|
case WStype_CONNECTED:
|
|
{
|
|
USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload);
|
|
}
|
|
break;
|
|
case WStype_TEXT:
|
|
{
|
|
// #####################
|
|
// handle SockJs+STOMP protocol
|
|
// #####################
|
|
|
|
String text = (char*) payload;
|
|
|
|
USE_SERIAL.printf("[WSc] get text: %s\n", payload);
|
|
|
|
if (payload[0] == 'h') {
|
|
|
|
USE_SERIAL.println("Heartbeat!");
|
|
|
|
} else if (payload[0] == 'o') {
|
|
|
|
// on open connection
|
|
char *msg = "[\"CONNECT\\naccept-version:1.1,1.0\\nheart-beat:10000,10000\\n\\n\\u0000\"]";
|
|
webSocket.sendTXT(msg);
|
|
|
|
} else if (text.startsWith("a[\"CONNECTED")) {
|
|
|
|
// subscribe to some channels
|
|
|
|
char *msg = "[\"SUBSCRIBE\\nid:sub-0\\ndestination:/user/queue/messages\\n\\n\\u0000\"]";
|
|
webSocket.sendTXT(msg);
|
|
delay(1000);
|
|
|
|
// and send a message
|
|
|
|
msg = "[\"SEND\\ndestination:/app/message\\n\\n{\\\"user\\\":\\\"esp\\\",\\\"message\\\":\\\"Hello!\\\"}\\u0000\"]";
|
|
webSocket.sendTXT(msg);
|
|
delay(1000);
|
|
}
|
|
|
|
break;
|
|
}
|
|
case WStype_BIN:
|
|
USE_SERIAL.printf("[WSc] get binary length: %u\n", length);
|
|
hexdump(payload, length);
|
|
|
|
// send data to server
|
|
// webSocket.sendBIN(payload, length);
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
void setup() {
|
|
|
|
// setup serial
|
|
|
|
// USE_SERIAL.begin(921600);
|
|
USE_SERIAL.begin(115200);
|
|
|
|
// USE_SERIAL.setDebugOutput(true);
|
|
|
|
USE_SERIAL.println();
|
|
|
|
|
|
// connect to WiFi
|
|
|
|
USE_SERIAL.print("Logging into WLAN: "); Serial.print(wlan_ssid); Serial.print(" ...");
|
|
WiFi.mode(WIFI_STA);
|
|
WiFi.begin(wlan_ssid, wlan_password);
|
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
delay(500);
|
|
USE_SERIAL.print(".");
|
|
}
|
|
USE_SERIAL.println(" success.");
|
|
USE_SERIAL.print("IP: "); USE_SERIAL.println(WiFi.localIP());
|
|
|
|
|
|
// #####################
|
|
// create socket url according to SockJS protocol (cf. http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-36)
|
|
// #####################
|
|
String socketUrl = ws_baseurl;
|
|
socketUrl += random(0, 999);
|
|
socketUrl += "/";
|
|
socketUrl += random(0, 999999); // should be a random string, but this works (see )
|
|
socketUrl += "/websocket";
|
|
|
|
// connect to websocket
|
|
webSocket.begin(ws_host, ws_port, socketUrl);
|
|
webSocket.setExtraHeaders(); // remove "Origin: file://" header because it breaks the connection with Spring's default websocket config
|
|
// webSocket.setExtraHeaders("foo: I am so funny\r\nbar: not"); // some headers, in case you feel funny
|
|
webSocket.onEvent(webSocketEvent);
|
|
}
|
|
|
|
void loop() {
|
|
webSocket.loop();
|
|
}
|