mirror of
https://github.com/Links2004/arduinoWebSockets.git
synced 2025-07-14 15:56:30 +02:00
add beginSSL
This commit is contained in:
@ -32,7 +32,7 @@ void webSocketEvent(WStype_t type, uint8_t * payload, size_t lenght) {
|
||||
USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload);
|
||||
|
||||
// send message to server when Connected
|
||||
webSocket.sendTXT(num, "Connected");
|
||||
webSocket.sendTXT("Connected");
|
||||
}
|
||||
break;
|
||||
case WStype_TEXT:
|
||||
|
88
examples/WebSocketClientSSL/WebSocketClientSSL.ino
Normal file
88
examples/WebSocketClientSSL/WebSocketClientSSL.ino
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* WebSocketClientSSL.ino
|
||||
*
|
||||
* Created on: 10.12.2015
|
||||
*
|
||||
* note SSL is only possible with the ESP8266
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WiFiMulti.h>
|
||||
|
||||
#include <WebSocketsClient.h>
|
||||
|
||||
#include <Hash.h>
|
||||
|
||||
ESP8266WiFiMulti WiFiMulti;
|
||||
WebSocketsClient webSocket;
|
||||
|
||||
|
||||
#define USE_SERIAL Serial1
|
||||
|
||||
void webSocketEvent(WStype_t type, uint8_t * payload, size_t lenght) {
|
||||
|
||||
|
||||
switch(type) {
|
||||
case WStype_DISCONNECTED:
|
||||
USE_SERIAL.printf("[WSc] Disconnected!\n");
|
||||
break;
|
||||
case WStype_CONNECTED:
|
||||
{
|
||||
USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload);
|
||||
|
||||
// send message to server when Connected
|
||||
webSocket.sendTXT("Connected");
|
||||
}
|
||||
break;
|
||||
case WStype_TEXT:
|
||||
USE_SERIAL.printf("[WSc] get text: %s\n", payload);
|
||||
|
||||
// send message to server
|
||||
// webSocket.sendTXT("message here");
|
||||
break;
|
||||
case WStype_BIN:
|
||||
USE_SERIAL.printf("[WSc] get binary lenght: %u\n", lenght);
|
||||
hexdump(payload, lenght);
|
||||
|
||||
// send data to server
|
||||
// webSocket.sendBIN(payload, lenght);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// USE_SERIAL.begin(921600);
|
||||
USE_SERIAL.begin(115200);
|
||||
|
||||
//Serial.setDebugOutput(true);
|
||||
USE_SERIAL.setDebugOutput(true);
|
||||
|
||||
USE_SERIAL.println();
|
||||
USE_SERIAL.println();
|
||||
USE_SERIAL.println();
|
||||
|
||||
for(uint8_t t = 4; t > 0; t--) {
|
||||
USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t);
|
||||
USE_SERIAL.flush();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
WiFiMulti.addAP("SSID", "passpasspass");
|
||||
|
||||
//WiFi.disconnect();
|
||||
while(WiFiMulti.run() != WL_CONNECTED) {
|
||||
delay(100);
|
||||
}
|
||||
|
||||
webSocket.beginSSL("192.168.0.123", 81);
|
||||
webSocket.onEvent(webSocketEvent);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
webSocket.loop();
|
||||
}
|
@ -70,6 +70,17 @@ void WebSocketsClient::begin(String host, uint16_t port, String url) {
|
||||
begin(host.c_str(), port, url.c_str());
|
||||
}
|
||||
|
||||
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
|
||||
void WebSocketsClient::beginSSL(const char *host, uint16_t port, const char * url) {
|
||||
begin(host, port, url);
|
||||
_client.isSSL = true;
|
||||
}
|
||||
|
||||
void WebSocketsClient::beginSSL(String host, uint16_t port, String url) {
|
||||
beginSSL(host.c_str(), port, url.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* called in arduino loop
|
||||
*/
|
||||
|
@ -50,6 +50,11 @@ class WebSocketsClient: private WebSockets {
|
||||
void begin(const char *host, uint16_t port, const char * url = "/");
|
||||
void begin(String host, uint16_t port, String url = "/");
|
||||
|
||||
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
|
||||
void beginSSL(const char *host, uint16_t port, const char * url = "/");
|
||||
void beginSSL(String host, uint16_t port, String url = "/");
|
||||
#endif
|
||||
|
||||
void loop(void);
|
||||
|
||||
void onEvent(WebSocketClientEvent cbEvent);
|
||||
|
Reference in New Issue
Block a user