Skip to content

Commit 177ec82

Browse files
committed
Merge branch 'master' of github.com:Links2004/arduinoWebSockets
2 parents e675c75 + 615926a commit 177ec82

File tree

8 files changed

+54
-22
lines changed

8 files changed

+54
-22
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,38 @@ The mode can be activated in the ```WebSockets.h``` (see WEBSOCKETS_NETWORK_TYPE
5353
[ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP) libary is required.
5454

5555

56+
### High Level Client API ###
57+
58+
- `begin` : Initiate connection sequence to the websocket host.
59+
```
60+
void begin(const char *host, uint16_t port, const char * url = "/", const char * protocol = "arduino");
61+
void begin(String host, uint16_t port, String url = "/", String protocol = "arduino");
62+
```
63+
- `onEvent`: Callback to handle for websocket events
64+
65+
```
66+
void onEvent(WebSocketClientEvent cbEvent);
67+
```
68+
69+
- `WebSocketClientEvent`: Handler for websocket events
70+
```
71+
void (*WebSocketClientEvent)(WStype_t type, uint8_t * payload, size_t length)
72+
```
73+
Where `WStype_t type` is defined as:
74+
```
75+
typedef enum {
76+
WStype_ERROR,
77+
WStype_DISCONNECTED,
78+
WStype_CONNECTED,
79+
WStype_TEXT,
80+
WStype_BIN,
81+
WStype_FRAGMENT_TEXT_START,
82+
WStype_FRAGMENT_BIN_START,
83+
WStype_FRAGMENT,
84+
WStype_FRAGMENT_FIN,
85+
} WStype_t;
86+
```
87+
5688
### Issues ###
5789
Submit issues to: https://github.com/Links2004/arduinoWebSockets/issues
5890

examples/WebSocketClient/WebSocketClient.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ WebSocketsClient webSocket;
2020

2121
#define USE_SERIAL Serial1
2222

23-
void webSocketEvent(WStype_t type, uint8_t * payload, size_t lenght) {
23+
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
2424

2525

2626
switch(type) {
@@ -42,11 +42,11 @@ void webSocketEvent(WStype_t type, uint8_t * payload, size_t lenght) {
4242
// webSocket.sendTXT("message here");
4343
break;
4444
case WStype_BIN:
45-
USE_SERIAL.printf("[WSc] get binary lenght: %u\n", lenght);
46-
hexdump(payload, lenght);
45+
USE_SERIAL.printf("[WSc] get binary length: %u\n", length);
46+
hexdump(payload, length);
4747

4848
// send data to server
49-
// webSocket.sendBIN(payload, lenght);
49+
// webSocket.sendBIN(payload, length);
5050
break;
5151
}
5252

examples/WebSocketClientSocketIO/WebSocketClientSocketIO.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ uint64_t messageTimestamp = 0;
2727
uint64_t heartbeatTimestamp = 0;
2828
bool isConnected = false;
2929

30-
void webSocketEvent(WStype_t type, uint8_t * payload, size_t lenght) {
30+
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
3131

3232

3333
switch(type) {
@@ -52,11 +52,11 @@ void webSocketEvent(WStype_t type, uint8_t * payload, size_t lenght) {
5252
// webSocket.sendTXT("message here");
5353
break;
5454
case WStype_BIN:
55-
USE_SERIAL.printf("[WSc] get binary lenght: %u\n", lenght);
56-
hexdump(payload, lenght);
55+
USE_SERIAL.printf("[WSc] get binary length: %u\n", length);
56+
hexdump(payload, length);
5757

5858
// send data to server
59-
// webSocket.sendBIN(payload, lenght);
59+
// webSocket.sendBIN(payload, length);
6060
break;
6161
}
6262

examples/WebSocketServer/WebSocketServer.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ WebSocketsServer webSocket = WebSocketsServer(81);
1818

1919
#define USE_SERIAL Serial1
2020

21-
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght) {
21+
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
2222

2323
switch(type) {
2424
case WStype_DISCONNECTED:
@@ -43,11 +43,11 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
4343
// webSocket.broadcastTXT("message here");
4444
break;
4545
case WStype_BIN:
46-
USE_SERIAL.printf("[%u] get binary lenght: %u\n", num, lenght);
47-
hexdump(payload, lenght);
46+
USE_SERIAL.printf("[%u] get binary length: %u\n", num, length);
47+
hexdump(payload, length);
4848

4949
// send message to client
50-
// webSocket.sendBIN(num, payload, lenght);
50+
// webSocket.sendBIN(num, payload, length);
5151
break;
5252
}
5353

examples/WebSocketServer/WebSocketServerFragmentation.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ WebSocketsServer webSocket = WebSocketsServer(81);
2020

2121
String fragmentBuffer = "";
2222

23-
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght) {
23+
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
2424

2525
switch(type) {
2626
case WStype_DISCONNECTED:
@@ -38,8 +38,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
3838
USE_SERIAL.printf("[%u] get Text: %s\n", num, payload);
3939
break;
4040
case WStype_BIN:
41-
USE_SERIAL.printf("[%u] get binary lenght: %u\n", num, lenght);
42-
hexdump(payload, lenght);
41+
USE_SERIAL.printf("[%u] get binary length: %u\n", num, length);
42+
hexdump(payload, length);
4343
break;
4444

4545
// Fragmentation / continuation opcode handling

examples/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ESP8266WiFiMulti WiFiMulti;
2626
ESP8266WebServer server = ESP8266WebServer(80);
2727
WebSocketsServer webSocket = WebSocketsServer(81);
2828

29-
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght) {
29+
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
3030

3131
switch(type) {
3232
case WStype_DISCONNECTED:

src/WebSocketsClient.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ void WebSocketsClient::setAuthorization(const char * auth) {
270270
* @param client WSclient_t * ptr to the client struct
271271
* @param opcode WSopcode_t
272272
* @param payload uint8_t *
273-
* @param lenght size_t
273+
* @param length size_t
274274
*/
275-
void WebSocketsClient::messageReceived(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t lenght, bool fin) {
275+
void WebSocketsClient::messageReceived(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin) {
276276
WStype_t type = WStype_ERROR;
277277

278278
switch(opcode) {
@@ -287,7 +287,7 @@ void WebSocketsClient::messageReceived(WSclient_t * client, WSopcode_t opcode, u
287287
break;
288288
}
289289

290-
runCbEvent(type, payload, lenght);
290+
runCbEvent(type, payload, length);
291291

292292
}
293293

src/WebSocketsServer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,9 @@ bool WebSocketsServer::newClient(WEBSOCKETS_NETWORK_CLASS * TCPclient) {
468468
* @param client WSclient_t * ptr to the client struct
469469
* @param opcode WSopcode_t
470470
* @param payload uint8_t *
471-
* @param lenght size_t
471+
* @param length size_t
472472
*/
473-
void WebSocketsServer::messageReceived(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t lenght, bool fin) {
473+
void WebSocketsServer::messageReceived(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin) {
474474
WStype_t type = WStype_ERROR;
475475

476476
switch(opcode) {
@@ -485,7 +485,7 @@ void WebSocketsServer::messageReceived(WSclient_t * client, WSopcode_t opcode, u
485485
break;
486486
}
487487

488-
runCbEvent(client->num, type, payload, lenght);
488+
runCbEvent(client->num, type, payload, length);
489489

490490
}
491491

0 commit comments

Comments
 (0)