8000 add beginSSL · robokoding/arduinoWebSockets@098c488 · GitHub
[go: up one dir, main page]

Skip to content

Commit 098c488

Browse files
committed
add beginSSL
1 parent 093797a commit 098c488

File tree

4 files changed

+105
-1
lines changed

4 files changed

+105
-1
lines changed

examples/WebSocketClient/WebSocketClient.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void webSocketEvent(WStype_t type, uint8_t * payload, size_t lenght) {
3232
USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload);
3333

3434
// send message to server when Connected
35-
webSocket.sendTXT(num, "Connected");
35+
webSocket.sendTXT("Connected");
3636
}
3737
break;
3838
case WStype_TEXT:
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* WebSocketClientSSL.ino
3+
*
4+
* Created on: 10.12.2015
5+
*
6+
* note SSL is only possible with the ESP8266
7+
*
8+
*/
9+
10+
#include <Arduino.h>
11+
12+
#include <ESP8266WiFi.h>
13+
#include <ESP8266WiFiMulti.h>
14+
15+
#include <WebSocketsClient.h>
16+
17+
#include <Hash.h>
18+
19+
ESP8266WiFiMulti WiFiMulti;
20+
WebSocketsClient webSocket;
21+
22+
23+
#define USE_SERIAL Serial1
24+
25+
void webSocketEvent(WStype_t type, uint8_t * payload, size_t lenght) {
26+
27+
28+
switch(type) {
29+
case WStype_DISCONNECTED:
30+
USE_SERIAL.printf("[WSc] Disconnected!\n");
31+
break;
32+
case WStype_CONNECTED:
33+
{
34+
USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload);
35+
36+
// send message to server when Connected
37+
webSocket.sendTXT("Connected");
38+
}
39+
break;
40+
case WStype_TEXT:
41+
USE_SERIAL.printf("[WSc] get text: %s\n", payload);
42+
43+
// send message to server
44+
// webSocket.sendTXT("message here");
45+
break;
46+
case WStype_BIN:
47+
USE_SERIAL.printf("[WSc] get binary lenght: %u\n", lenght);
48+
hexdump(payload, lenght);
49+
50+
// send data to server
51+
// webSocket.sendBIN(payload, lenght);
52+
break;
53+
}
54+
55+
}
56+
57+
void setup() {
58+
// USE_SERIAL.begin(921600);
59+
USE_SERIAL.begin(115200);
60+
61+
//Serial.setDebugOutput(true);
62+
USE_SERIAL.setDebugOutput(true);
63+
64+
USE_SERIAL.println();
65+
USE_SERIAL.println();
66+
USE_SERIAL.println();
67+
68+
for(uint8_t t = 4; t > 0; t--) {
69+
USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t);
70+
USE_SERIAL.flush();
71+
delay(1000);
72+
}
73+
74+
WiFiMulti.addAP("SSID", "passpasspass");
75+
76+
//WiFi.disconnect();
77+
while(WiFiMulti.run() != WL_CONNECTED) {
78+
delay(100);
79+
}
80+
81+
webSocket.beginSSL("192.168.0.123", 81);
82+
webSocket.onEvent(webSocketEvent);
83+
84+
}
85+
86+
void loop() {
87+
webSocket.loop();
88+
}

src/WebSocketsClient.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ void WebSocketsClient::begin(String host, uint16_t port, String url) {
7070
begin(host.c_str(), port, url.c_str());
7171
}
7272

73+
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
74+
void WebSocketsClient::beginSSL(const char *host, uint16_t port, const char * url) {
75+
begin(host, port, url);
76+
_client.isSSL = true;
77+
}
78+
79+
void WebSocketsClient::beginSSL(String host, uint16_t port, String url) {
80+
beginSSL(host.c_str(), port, url.c_str());
81+
}
82+
#endif
83+
7384
/**
7485
* called in arduino loop
7586
*/

src/WebSocketsClient.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class WebSocketsClient: private WebSockets {
5050
void begin(const char *host, uint16_t port, const char * url = "/");
5151
void begin(String host, uint16_t port, String url = "/");
5252

53+
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
54+
void beginSSL(const char *host, uint16_t port, const char * url = "/");
55+
void beginSSL(String host, uint16_t port, String url = "/");
56+
#endif
57+
5358
void loop(void);
5459

5560
void onEvent(WebSocketClientEvent cbEvent);

0 commit comments

Comments
 (0)
0