5
5
* In this example we connect to a Spring application (see https://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html).
6
6
*
7
7
* 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
9
9
*/
10
10
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
18
12
19
13
#define USE_SERIAL Serial
20
14
28
22
// SETTINGS
29
23
30
24
const char * wlan_ssid = " yourssid" ;
31
- const char * wlan_password = " password " ;
25
+ const char * wlan_password = " somepassword " ;
32
26
33
- const char * ws_host = " the.host.com " ;
27
+ const char * ws_host = " the.host.net " ;
34
28
const int ws_port = 80 ;
35
29
36
30
// base URL for SockJS (websocket) connection
@@ -117,11 +111,6 @@ void setup() {
117
111
118
112
USE_SERIAL.println ();
119
113
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
- }
125
114
126
115
// connect to WiFi
127
116
@@ -135,6 +124,7 @@ void setup() {
135
124
}
136
125
USE_SERIAL.println (" success." );
137
126
USE_SERIAL.print (" IP: " ); USE_SERIAL.println (WiFi.localIP ());
127
+
138
128
139
129
// #####################
140
130
// 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() {
147
137
148
138
// connect to websocket
149
139
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
150
142
webSocket.onEvent (webSocketEvent);
151
143
}
152
144
0 commit comments