mirror of
https://github.com/Links2004/arduinoWebSockets.git
synced 2025-07-17 17:22:05 +02:00
Remove redundant method header and fix indent
This commit is contained in:
@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* WebSocketClientSockJsAndStomp.ino
|
WebSocketClientSockJsAndStomp.ino
|
||||||
*
|
|
||||||
* Example for connecting and maintining a connection with a SockJS+STOMP websocket connection.
|
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).
|
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
|
Created on: 18.07.2017
|
||||||
* Author: Martin Becker <mgbckr>, Contact: becker@informatik.uni-wuerzburg.de
|
Author: Martin Becker <mgbckr>, Contact: becker@informatik.uni-wuerzburg.de
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// PRE
|
// PRE
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ WebSocketsClient webSocket;
|
|||||||
|
|
||||||
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
|
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
|
||||||
|
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case WStype_DISCONNECTED:
|
case WStype_DISCONNECTED:
|
||||||
USE_SERIAL.printf("[WSc] Disconnected!\n");
|
USE_SERIAL.printf("[WSc] Disconnected!\n");
|
||||||
break;
|
break;
|
||||||
@ -52,43 +52,43 @@ void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
|
|||||||
USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload);
|
USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WStype_TEXT: {
|
case WStype_TEXT:
|
||||||
|
{
|
||||||
|
// #####################
|
||||||
|
// handle STOMP protocol
|
||||||
|
// #####################
|
||||||
|
|
||||||
// #####################
|
String text = (char*) payload;
|
||||||
// handle STOMP protocol
|
|
||||||
// #####################
|
|
||||||
|
|
||||||
String text = (char*) payload;
|
USE_SERIAL.printf("[WSc] get text: %s\n", payload);
|
||||||
|
|
||||||
USE_SERIAL.printf("[WSc] get text: %s\n", payload);
|
if (payload[0] == 'h') {
|
||||||
|
|
||||||
if (payload[0] == 'h') {
|
USE_SERIAL.println("Heartbeat!");
|
||||||
|
|
||||||
USE_SERIAL.println("Heartbeat!");
|
} else if (payload[0] == 'o') {
|
||||||
|
|
||||||
} 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);
|
||||||
|
|
||||||
// on open connection
|
} else if (text.startsWith("a[\"CONNECTED")) {
|
||||||
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
|
||||||
|
|
||||||
// subscribe to some channels
|
char *msg = "[\"SUBSCRIBE\\nid:sub-0\\ndestination:/user/queue/messages\\n\\n\\u0000\"]";
|
||||||
|
webSocket.sendTXT(msg);
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
char *msg = "[\"SUBSCRIBE\\nid:sub-0\\ndestination:/user/queue/messages\\n\\n\\u0000\"]";
|
// and send a message
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
msg = "[\"SEND\\ndestination:/app/message\\n\\n{\\\"user\\\":\\\"esp\\\",\\\"message\\\":\\\"Hello!\\\"}\\u0000\"]";
|
break;
|
||||||
webSocket.sendTXT(msg);
|
|
||||||
delay(1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case WStype_BIN:
|
case WStype_BIN:
|
||||||
USE_SERIAL.printf("[WSc] get binary length: %u\n", length);
|
USE_SERIAL.printf("[WSc] get binary length: %u\n", length);
|
||||||
hexdump(payload, length);
|
hexdump(payload, length);
|
||||||
@ -107,7 +107,7 @@ void setup() {
|
|||||||
// USE_SERIAL.begin(921600);
|
// USE_SERIAL.begin(921600);
|
||||||
USE_SERIAL.begin(115200);
|
USE_SERIAL.begin(115200);
|
||||||
|
|
||||||
// USE_SERIAL.setDebugOutput(true);
|
// USE_SERIAL.setDebugOutput(true);
|
||||||
|
|
||||||
USE_SERIAL.println();
|
USE_SERIAL.println();
|
||||||
|
|
||||||
@ -119,8 +119,8 @@ void setup() {
|
|||||||
WiFi.begin(wlan_ssid, wlan_password);
|
WiFi.begin(wlan_ssid, wlan_password);
|
||||||
|
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(500);
|
delay(500);
|
||||||
USE_SERIAL.print(".");
|
USE_SERIAL.print(".");
|
||||||
}
|
}
|
||||||
USE_SERIAL.println(" success.");
|
USE_SERIAL.println(" success.");
|
||||||
USE_SERIAL.print("IP: "); USE_SERIAL.println(WiFi.localIP());
|
USE_SERIAL.print("IP: "); USE_SERIAL.println(WiFi.localIP());
|
||||||
@ -130,15 +130,15 @@ void setup() {
|
|||||||
// create socket url according to SockJS protocol (cf. http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-36)
|
// 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;
|
String socketUrl = ws_baseurl;
|
||||||
socketUrl += random(0,999);
|
socketUrl += random(0, 999);
|
||||||
socketUrl += "/";
|
socketUrl += "/";
|
||||||
socketUrl += random(0,999999); // should be a random string, but this works (see )
|
socketUrl += random(0, 999999); // should be a random string, but this works (see )
|
||||||
socketUrl += "/websocket";
|
socketUrl += "/websocket";
|
||||||
|
|
||||||
// connect to websocket
|
// connect to websocket
|
||||||
webSocket.begin(ws_host, ws_port, socketUrl);
|
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(); // 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.setExtraHeaders("foo: I am so funny\r\nbar: not"); // some headers, in case you feel funny
|
||||||
webSocket.onEvent(webSocketEvent);
|
webSocket.onEvent(webSocketEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,6 @@ class WebSocketsClient: private WebSockets {
|
|||||||
void setAuthorization(const char * auth);
|
void setAuthorization(const char * auth);
|
||||||
|
|
||||||
void setExtraHeaders(const char * extraHeaders = NULL);
|
void setExtraHeaders(const char * extraHeaders = NULL);
|
||||||
void setExtraHeaders(char * extraHeaders);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
String _host;
|
String _host;
|
||||||
|
Reference in New Issue
Block a user