Skip to content

Commit 9e6f6a2

Browse files
committed
Move websockets to sandbox
1 parent 1986467 commit 9e6f6a2

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

examples/examples-communication/websockets/client-send/client/client.ino renamed to examples/sandbox/websockets/client-as-source/client/client.ino

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/**
22
* @brief A simple WebSocket client sketch that sends out some PCM audio
3-
* data using the https://github.com/Links2004/arduinoWebSockets library
3+
* data using the https://github.com/Links2004/arduinoWebSockets library.AdapterAudioStreamToAudioOutput.AdapterAudioStreamToAudioOutput
4+
* The WebSocket API is asynchronous, so we need to slow down the sending
5+
* to the playback speed, to prevent any buffer overflows at the receiver.
46
* @author Phil Schatzmann
57
*/
68

79
#include <WebSocketsClient.h> // https://github.com/Links2004/arduinoWebSockets
810
#include <WiFiMulti.h>
9-
1011
#include "AudioTools.h"
1112
#include "AudioTools/Communication/WebSocketOutput.h"
1213

@@ -18,7 +19,8 @@ WebSocketOutput out(webSocket);
1819
AudioInfo info(44100, 2, 16);
1920
SineWaveGenerator<int16_t> sineWave(32000);
2021
GeneratedSoundStream<int16_t> sound(sineWave);
21-
StreamCopy copier(out, sound);
22+
Throttle throttle(out)
23+
StreamCopy copier(throttle, sound);
2224

2325
void setup() {
2426
Serial.begin(115200);
@@ -28,14 +30,17 @@ void setup() {
2830
while (WiFiMulti.run() != WL_CONNECTED) {
2931
delay(100);
3032
}
33+
WiFi.setSleep(false);
3134

3235
// start client connecting to server address, port and URL
33-
webSocket.begin("192.168.0.123", 81, "/");
36+
webSocket.begin("192.168.1.34", 81, "/");
3437

3538
// try ever 5000 again if connection has failed
3639
webSocket.setReconnectInterval(5000);
3740

3841
sineWave.begin(info, N_B4);
42+
// WebSockets are async, so we need to slow down the sending
43+
throttle.begin(info);
3944
}
4045

4146
void loop() {

examples/examples-communication/websockets/client-send/server/server.ino renamed to examples/sandbox/websockets/client-as-source/server/server.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include <WiFi.h>
1010
#include <WiFiClientSecure.h>
1111
#include <WiFiMulti.h>
12-
1312
#include "AudioTools.h"
13+
#include "AudioTools/AudioLibs/AudioBoardStream.h"
1414

1515
WiFiMulti WiFiMulti;
1616
WebSocketsServer webSocket(81);
@@ -33,6 +33,8 @@ void setup() {
3333
while (WiFiMulti.run() != WL_CONNECTED) {
3434
delay(100);
3535
}
36+
WiFi.setSleep(false);
37+
Serial.println(WiFi.localIP());
3638

3739
// start server
3840
webSocket.begin();

examples/examples-communication/websockets/server-send/client/client.ino renamed to examples/sandbox/websockets/server-as-source/client/client.ino

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
*/
88
#include <WebSocketsClient.h> // https://github.com/Links2004/arduinoWebSockets
99
#include <WiFiMulti.h>
10-
1110
#include "AudioTools.h"
12-
#include "AudioTools/Communication/WebSocketOutput.h"
11+
#include "AudioTools/AudioLibs/AudioBoardStream.h"
1312

1413
// websocket
1514
WiFiMulti WiFiMulti;
1615
WebSocketsClient webSocket;
17-
WebSocketOutput out(webSocket); // or replace with I2SStream
1816
// audio
1917
AudioInfo info(44100, 2, 16);
2018
AudioBoardStream i2s(AudioKitEs8388V1); // Access I2S as stream
@@ -35,9 +33,10 @@ void setup() {
3533
while (WiFiMulti.run() != WL_CONNECTED) {
3634
delay(100);
3735
}
36+
WiFi.setSleep(false);
3837

3938
// start client connecting to server address, port and URL
40-
webSocket.begin("192.168.0.123", 81, "/");
39+
webSocket.begin("192.168.1.34", 81, "/");
4140

4241
// event handler
4342
webSocket.onEvent(webSocketEvent);
@@ -53,5 +52,4 @@ void setup() {
5352

5453
void loop() {
5554
webSocket.loop();
56-
copier.copy();
5755
}

examples/examples-communication/websockets/server-send/server/server.ino renamed to examples/sandbox/websockets/server-as-source/server/server.ino

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
* @brief A simple WebSocket server sketch using the
33
* https://github.com/Links2004/arduinoWebSockets library to send out some
44
* PCM audio data when some clients are connnected.
5+
* The WebSocket API is asynchronous, so we need to slow down the sending
6+
* to the playback speed, to prevent any buffer overflows at the receiver.
57
* @author Phil Schatzmann
68
*/
79

810
#include <WebSocketsServer.h> // https://github.com/Links2004/arduinoWebSockets
911
#include <WiFi.h>
1012
#include <WiFiMulti.h>
11-
1213
#include "AudioTools.h"
1314
#include "AudioTools/Communication/WebSocketOutput.h"
1415

@@ -20,7 +21,8 @@ WebSocketOutput out(webSocket);
2021
AudioInfo info(44100, 2, 16);
2122
SineWaveGenerator<int16_t> sineWave(32000);
2223
GeneratedSoundStream<int16_t> sound(sineWave);
23-
StreamCopy copier(out, sound); // copies sound into i2s
24+
Throttle throttle(out);
25+
StreamCopy copier(throttle, sound); // copies sound into i2s
2426

2527
void setup() {
2628
// Serial.begin(921600);
@@ -32,12 +34,16 @@ void setup() {
3234
while (WiFiMulti.run() != WL_CONNECTED) {
3335
delay(100);
3436
}
37+
WiFi.setSleep(false);
38+
Serial.println(WiFi.localIP());
3539

3640
// start server
3741
webSocket.begin();
3842

39-
// start i2s
43+
// start sine generation
4044
sineWave.begin(info, N_B4);
45+
throttle.begin(info);
46+
4147
}
4248

4349
void loop() {

0 commit comments

Comments
 (0)