55 * In this example we connect to a Spring application (see https://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html).
66 *
77 * Created on: 18.07.2017
8- * Author: Martin Becker <mgbckr>, contact : becker@informatik.uni-wuerzburg.de
8+ * Author: Martin Becker <mgbckr>, Contact : becker@informatik.uni-wuerzburg.de
99 */
1010
11- // CONSTANTS AND MACROS
12-
13- #define DEBUG_WEBSOCKETS
14- #define DEBUG_WEBSOCKETS (...) Serial.printf( __VA_ARGS__ )
15-
16- #define WEBSOCKETS_NETWORK_TYPE NETWORK_ESP8266
17- #define WEBSOCKETS_HEADERS_NO_ORIGIN
11+ // PRE
1812
1913#define USE_SERIAL Serial
2014
2822// SETTINGS
2923
3024const char * wlan_ssid = " yourssid" ;
31- const char * wlan_password = " password " ;
25+ const char * wlan_password = " somepassword " ;
3226
33- const char * ws_host = " the.host.com " ;
27+ const char * ws_host = " the.host.net " ;
3428const int ws_port = 80 ;
3529
3630// base URL for SockJS (websocket) connection
@@ -117,11 +111,6 @@ void setup() {
117111
118112 USE_SERIAL.println ();
119113
120- for (uint8_t t = 4 ; t > 0 ; t--) {
121- USE_SERIAL.printf (" [SETUP] BOOT WAIT %d...\n " , t);
122- USE_SERIAL.flush ();
123- delay (1000 );
124- }
125114
126115 // connect to WiFi
127116
@@ -135,6 +124,7 @@ void setup() {
135124 }
136125 USE_SERIAL.println (" success." );
137126 USE_SERIAL.print (" IP: " ); USE_SERIAL.println (WiFi.localIP ());
127+
138128
139129 // #####################
140130 // create socket url according to SockJS protocol (cf. http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-36)
@@ -147,6 +137,8 @@ void setup() {
147137
148138 // connect to websocket
149139 webSocket.begin (ws_host, ws_port, socketUrl);
140+ webSocket.setExtraHeaders (" " ); // remove "Origin: file://" header because it breaks the connection with Spring's default websocket config
141+ // webSocket.setExtraHeaders("foo: I am so funny\r\nbar: not"); // some headers, in case you feel funny
150142 webSocket.onEvent (webSocketEvent);
151143}
152144
0 commit comments