Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update STOMP examples to work with Spring STOMP tutorial #262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions examples/WebSocketClientStomp/WebSocketClientStomp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Example for connecting and maintining a connection with a 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 particular, we use the default STOMP WebSocket example by Spring: https://github.com/spring-guides/gs-messaging-stomp-websocket
That is, we connect to the Spring server, send a "hello" and get back a "greeting".

Created on: 25.09.2017
Author: Martin Becker <mgbckr>, Contact: [email protected]
Expand All @@ -24,15 +26,16 @@

// SETTINGS

const char* wlan_ssid = "yourssid";
const char* wlan_password = "somepassword";
const char* wlan_ssid = "<ssid>";
const char* wlan_password = "<password>";

const char* ws_host = "the.host.net";
const int ws_port = 80;
const char* ws_host = "<ip>";
const int ws_port = 8080; // the Spring webapp runs on port 8080 by default (instead of 80 for standard HTTP)

// URL for STOMP endpoint.
// For the default config of Spring's STOMP support, the default URL is "/socketentry/websocket".
const char* stompUrl = "/socketentry/websocket"; // don't forget the leading "/" !!!
// For the default config of Spring's STOMP support, the preset URL is "/socketentry/websocket".
// Here, we use the URL defined by the Spring example mentioned in the preamble.
const char* stompUrl = "/gs-guide-websocket/websocket"; // don't forget the leading "/" !!!


// VARIABLES
Expand Down Expand Up @@ -82,13 +85,13 @@ void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {

// subscribe to some channels

String msg = "SUBSCRIBE\nid:sub-0\ndestination:/user/queue/messages\n\n";
String msg = "SUBSCRIBE\nid:sub-0\ndestination:/topic/greetings\n\n";
sendMessage(msg);
delay(1000);

// and send a message

msg = "SEND\ndestination:/app/message\n\n{\"user\":\"esp\",\"message\":\"Hello!\"}";
msg = "SEND\ndestination:/app/hello\n\n{\"name\":\"blubb\"}";
sendMessage(msg);
delay(1000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

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 particular, we use the default STOMP WebSocket example by Spring: https://github.com/spring-guides/gs-messaging-stomp-websocket
That is, we connect to the Spring server, send a "hello" and get back a "greeting".

Created on: 18.07.2017
Author: Martin Becker <mgbckr>, Contact: [email protected]
Expand All @@ -24,17 +26,20 @@

// SETTINGS

const char* wlan_ssid = "yourssid";
const char* wlan_password = "somepassword";
const char* wlan_ssid = "<ssid>";
const char* wlan_password = "<password>";

const char* ws_host = "the.host.net";
const int ws_port = 80;
const char* ws_host = "<ip>";
const int ws_port = 8080; // the Spring webapp runs on port 8080 by default (instead of 80 for standard HTTP)

// 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 "/" !!!
// 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 preset base URL is "/socketentry/".
// Here, we use the URL defined by the Spring example mentioned in the preamble.
const char* ws_baseurl = "/gs-guide-websocket/"; // don't forget leading and trailing "/" !!!


// VARIABLES
Expand Down Expand Up @@ -79,13 +84,13 @@ void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {

// subscribe to some channels

char *msg = "[\"SUBSCRIBE\\nid:sub-0\\ndestination:/user/queue/messages\\n\\n\\u0000\"]";
char *msg = "[\"SUBSCRIBE\\nid:sub-0\\ndestination:/topic/greetings\\n\\n\\u0000\"]";
webSocket.sendTXT(msg);
delay(1000);

// and send a message

msg = "[\"SEND\\ndestination:/app/message\\n\\n{\\\"user\\\":\\\"esp\\\",\\\"message\\\":\\\"Hello!\\\"}\\u0000\"]";
msg = "[\"SEND\\ndestination:/app/hello\\n\\n{\\\"name\\\":\\\"blubb\\\"}\\u0000\"]";
webSocket.sendTXT(msg);
delay(1000);
}
Expand Down