8000 Merge pull request #265 from Links2004/esp32 · Aeronaut/arduinoWebSockets@a67a8dd · GitHub
[go: up one dir, main page]

Skip to content

Commit a67a8dd

Browse files
authored
Merge pull request Links2004#265 from Links2004/esp32
ESP32 support improved test sorted examples
2 parents 642750e + 4759a66 commit a67a8dd

File tree

31 files changed

+438
-58
lines changed

31 files changed

+438
-58
lines changed

.travis.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,31 @@ sudo: false
22
language: bash
33
os:
44
- linux
5+
env:
6+
matrix:
7+
- CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80" IDE_VERSION=1.6.5
8+
- CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80,FlashSize=1M0,FlashMode=qio,FlashFreq=80" IDE_VERSION=1.8.5
9+
- CPU="esp8266" BOARD="esp8266com:esp8266:generic:CpuFrequency=80,Debug=Serial1" IDE_VERSION=1.6.5
10+
- CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" IDE_VERSION=1.6.5
11+
- CPU="esp32" BOARD="espressif:esp32:esp32:FlashFreq=80" IDE_VERSION=1.8.5
512

613
script:
714
- /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16
815
- sleep 3
916
- export DISPLAY=:1.0
10-
- wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz
11-
- tar xf arduino-1.6.5-linux64.tar.xz
12-
- mv arduino-1.6.5 $HOME/arduino_ide
17+
- wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz
18+
- tar xf arduino-$IDE_VERSION-linux64.tar.xz
19+
- mv arduino-$IDE_VERSION $HOME/arduino_ide
1320
- export PATH="$HOME/arduino_ide:$PATH"
1421
- which arduino
1522
- mkdir -p $HOME/Arduino/libraries
1623
- cp -r $TRAVIS_BUILD_DIR $HOME/Arduino/libraries/arduinoWebSockets
17-
- cd $HOME/arduino_ide/hardware
18-
- mkdir esp8266com
19-
- cd esp8266com
20-
- git clone https://github.com/esp8266/Arduino.git esp8266
21-
- cd esp8266/tools
22-
- python get.py
2324
- source $TRAVIS_BUILD_DIR/travis/common.sh
24-
- arduino --board esp8266com:esp8266:generic --save-prefs
25+
- get_core $CPU
26+
- cd $TRAVIS_BUILD_DIR
27+
- arduino --board $BOARD --save-prefs
2528
- arduino --get-pref sketchbook.path
26-
- build_sketches arduino $HOME/Arduino/libraries/arduinoWebSockets esp8266
29+
- build_sketches arduino $HOME/Arduino/libraries/arduinoWebSockets/examples/$CPU $CPU
2730

2831
notifications:
2932
email:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ a WebSocket Server and Client for Arduino based on RFC6455.
2323
- wss / SSL is not possible.
2424

2525
##### Supported Hardware #####
26-
- ESP8266 [Arduino for ESP8266](https://github.com/Links2004/Arduino)
26+
- ESP8266 [Arduino for ESP8266](https://github.com/esp8266/Arduino/)
27+
- ESP32 [Arduino for ESP32](https://github.com/espressif/arduino-esp32)
2728
- ESP31B
2829
- Particle with STM32 ARM Cortex M3
2930
- ATmega328 with Ethernet Shield (ATmega branch)

examples/ParticleWebSocketClient/.esp8266.skip

Whitespace-only changes.

examples/WebSocketClientAVR/.esp8266.skip

Whitespace-only changes.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* WebSocketClient.ino
3+
*
4+
* Created on: 24.05.2015
5+
*
6+
*/
7+
8+
#include <Arduino.h>
9+
10+
#include <WiFi.h>
11+
#include <WiFiMulti.h>
12+
#include <WiFiClientSecure.h>
13+
14+
#include <WebSocketsClient.h>
15+
16+
17+
WiFiMulti WiFiMulti;
18+
WebSocketsClient webSocket;
19+
20+
HardwareSerial Serial1(2);
21+
22+
#define USE_SERIAL Serial1
23+
24+
void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) {
25+
const uint8_t* src = (const uint8_t*) mem;
26+
USE_SERIAL.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len);
27+
for(uint32_t i = 0; i < len; i++) {
28+
if(i % cols == 0) {
29+
USE_SERIAL.printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i);
30+
}
31+
USE_SERIAL.printf("%02X ", *src);
32+
src++;
33+
}
34+
USE_SERIAL.printf("\n");
35+
}
36+
37+
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
38+
39+
switch(type) {
40+
case WStype_DISCONNECTED:
41+
USE_SERIAL.printf("[WSc] Disconnected!\n");
42+
break;
43+
case WStype_CONNECTED:
44+
USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload);
45+
46+
// send message to server when Connected
47+
webSocket.sendTXT("Connected");
48+
break;
49+
case WStype_TEXT:
50+
USE_SERIAL.printf("[WSc] get text: %s\n", payload);
51+
52+
// send message to server
53+
// webSocket.sendTXT("message here");
54+
break;
55+
case WStype_BIN:
56+
USE_SERIAL.printf("[WSc] get binary length: %u\n", length);
57+
hexdump(payload, length);
58+
59+
// send data to server
60+
// webSocket.sendBIN(payload, length);
61+
break;
62+
}
63+
64+
}
65+
66+
void setup() {
67+
// USE_SERIAL.begin(921600);
68+
USE_SERIAL.begin(115200);
69+
70+
//Serial.setDebugOutput(true);
71+
USE_SERIAL.setDebugOutput(true);
72+
73+
USE_SERIAL.println();
74+
USE_SERIAL.println();
75+
USE_SERIAL.println();
76+
77+
for(uint8_t t = 4; t > 0; t--) {
78+
USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t);
79+
USE_SERIAL.flush();
80+
delay(1000);
81+
}
82+
83+
WiFiMulti.addAP("SSID", "passpasspass");
84+
85+
//WiFi.disconnect();
86+
while(WiFiMulti.run() != WL_CONNECTED) {
87+
delay(100);
88+
}
89+
90+
// server address, port and URL
91+
webSocket.begin("192.168.0.123", 81, "/");
92+
93+
// event handler
94+
webSocket.onEvent(webSocketEvent);
95+
96+
// use HTTP Basic Authorization this is optional remove if not needed
97+
webSocket.setAuthorization("user", "Password");
98+
99+
// try ever 5000 again if connection has failed
100+
webSocket.setReconnectInterval(5000);
101+
102+
}
103+
104+
void loop() {
105+
webSocket.loop();
106+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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 <WiFi.h>
13+
#include <WiFiMulti.h>
14+
#include <WiFiClientSecure.h>
15+
16+
#include <WebSocketsClient.h>
17+
18+
19+
WiFiMulti WiFiMulti;
20+
WebSocketsClient webSocket;
21+
22+
HardwareSerial Serial1(2);
23+
24+
#define USE_SERIAL Serial1
25+
26+
void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) {
27+
const uint8_t* src = (const uint8_t*) mem;
28+
USE_SERIAL.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len);
29+
for(uint32_t i = 0; i < len; i++) {
30+
if(i % cols == 0) {
31+
USE_SERIAL.printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i);
32+
}
33+
USE_SERIAL.printf("%02X ", *src);
34+
src++;
35+
}
36+
USE_SERIAL.printf("\n");
37+
}
38+
39+
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
40+
41+
42+
switch(type) {
43+
case F438 WStype_DISCONNECTED:
44+
USE_SERIAL.printf("[WSc] Disconnected!\n");
45+
break;
46+
case WStype_CONNECTED:
47+
{
48+
USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload);
49+
50+
// send message to server when Connected
51+
webSocket.sendTXT("Connected");
52+
}
53+
break;
54+
case WStype_TEXT:
55+
USE_SERIAL.printf("[WSc] get text: %s\n", payload);
56+
57+
// send message to server
58+
// webSocket.sendTXT("message here");
59+
break;
60+
case WStype_BIN:
61+
USE_SERIAL.printf("[WSc] get binary length: %u\n", length);
62+
hexdump(payload, length);
63+
64+
// send data to server
65+
// webSocket.sendBIN(payload, length);
66+
break;
67+
}
68+
69+
}
70+
71+
void setup() {
72+
// USE_SERIAL.begin(921600);
73+
USE_SERIAL.begin(115200);
74+
75+
//Serial.setDebugOutput(true);
76+
USE_SERIAL.setDebugOutput(true);
77+
78+
USE_SERIAL.println();
79+
USE_SERIAL.println();
80+
USE_SERIAL.println();
81+
82+
for(uint8_t t = 4; t > 0; t--) {
83+
USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t);
84+
USE_SERIAL.flush();
85+
delay(1000);
86+
}
87+
88+
WiFiMulti.addAP("SSID", "passpasspass");
89+
90+
//WiFi.disconnect();
91+
while(WiFiMulti.run() != WL_CONNECTED) {
92+
delay(100);
93+
}
94+
95+
webSocket.beginSSL("192.168.0.123", 81);
96+
webSocket.onEvent(webSocketEvent);
97+
98+
}
99+
100+
void loop() {
101+
webSocket.loop();
102+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* WebSocketServer.ino
3+
*
4+
* Created on: 22.05.2015
5+
*
6+
*/
7+
8+
#include <Arduino.h>
9+
10+
#include <WiFi.h>
11+
#include <WiFiMulti.h>
12+
#include <WiFiClientSecure.h>
13+
14+
#include <WebSocketsServer.h>
15+
16+
WiFiMulti WiFiMulti;
17+
WebSocketsServer webSocket = WebSocketsServer(81);
18+
19+
HardwareSerial Serial1(2);
20+
21+
#define USE_SERIAL Serial1
22+
23+
void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) {
24+
const uint8_t* src = (const uint8_t*) mem;
25+
USE_SERIAL.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, 10000 len);
26+
for(uint32_t i = 0; i < len; i++) {
27+
if(i % cols == 0) {
28+
USE_SERIAL.printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i);
29+
}
30+
USE_SERIAL.printf("%02X ", *src);
31+
src++;
32+
}
33+
USE_SERIAL.printf("\n");
34+
}
35+
36+
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
37+
38+
switch(type) {
39+
case WStype_DISCONNECTED:
40+
USE_SERIAL.printf("[%u] Disconnected!\n", num);
41+
break;
42+
case WStype_CONNECTED:
43+
{
44+
IPAddress ip = webSocket.remoteIP(num);
45+
USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);
46+
47+
// send message to client
48+
webSocket.sendTXT(num, "Connected");
49+
}
50+
break;
51+
case WStype_TEXT:
52+
USE_SERIAL.printf("[%u] get Text: %s\n", num, payload);
53+
54+
// send message to client
55+
// webSocket.sendTXT(num, "message here");
56+
57+
// send data to all connected clients
58+
// webSocket.broadcastTXT("message here");
59+
break;
60+
case WStype_BIN:
61+
USE_SERIAL.printf("[%u] get binary length: %u\n", num, length);
62+
hexdump(payload, length);
63+
64+
// send message to client
65+
// webSocket.sendBIN(num, payload, length);
66+
break;
67+
}
68+
69+
}
70+
71+
void setup() {
72+
// USE_SERIAL.begin(921600);
73+
USE_SERIAL.begin(115200);
74+
75+
//Serial.setDebugOutput(true);
76+
USE_SERIAL.setDebugOutput(true);
77+
78+
USE_SERIAL.println();
79+
USE_SERIAL.println();
80+
USE_SERIAL.println();
81+
82+
for(uint8_t t = 4; t > 0; t--) {
83+
USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t);
84+
USE_SERIAL.flush();
85+
delay(1000);
86+
}
87+
88+
WiFiMulti.addAP("SSID", "passpasspass");
89+
90+
while(WiFiMulti.run() != WL_CONNECTED) {
91+
delay(100);
92+
}
93+
94+
webSocket.begin();
95+
webSocket.onEvent(webSocketEvent);
96+
}
97+
98+
void loop() {
99+
webSocket.loop();
100+
}

0 commit comments

Comments
 (0)
0