-
Notifications
You must be signed in to change notification settings - Fork 1
/
voco-mini-satellite.ino
222 lines (190 loc) · 6.61 KB
/
voco-mini-satellite.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/* ************************************************************************* *
Matrix Voice Audio Streamer
This program is written to be a streaming audio server running on the Matrix
Voice. This is typically used for Rhasspy.
See https://rhasspy.readthedocs.io/en/latest/ for more information
Original Author: Paul Romkes
Date: Januari 2021
Version: 7.0
Requirements
============
Look at the list of required libraries in General.hpp. For example:
install https://github.com/me-no-dev/ESPAsyncWebServer
install 'RingBuffer' library from Locoduino https://github.com/Locoduino/RingBuffer
install 'PubSubClient' library from https://github.com/knolleary/pubsubclient.git
https://github.com/matrix-io/matrixio_hal_esp32.git
https://github.com/marvinroger/async-mqtt-client.git
https://github.com/me-no-dev/AsyncTCP.git
install 'ArduinoJson' library from https://github.com/bblanchon/ArduinoJson.git
ESP Async WebServer
m5stack/M5Atom
fastled/FastLED
yveaux/AC101 @ ^0.0.1
Changelog:
==========
v1:
- first code release. It needs a lot of improvement, no hardcoding stuff
v2:
- Change to Arduino IDE
v2.1:
- Changed to pubsubclient and fixed other stability issues
v3:
- Add OTA
v3.1:
- Only listen to SITEID to toggle hotword
- Got rid of String, leads to Heap Fragmentation
- Add dynamic brightness, post {"brightness": 50 } to SITEID/everloop
- Fix stability, using semaphores
v3.2:
- Add dynamic colors, see readme for documentation
- Restart the device by publishing hashed password to SITEID/restart
- Adjustable framerate, more info at
https://snips.gitbook.io/documentation/advanced-configuration/platform-configuration
- Rotating animation possible, not finished or used yet
v3.3:
- Added support for Rhasspy https://github.com/synesthesiam/rhasspy
- Started implementing playBytes, not finished
v3.4:
- Implemented playBytes, basics done but sometimes audio garbage out
v4.0:
- playBytes working, only plays 44100 samplerate (mono/stereo) correctly. Work in progress
- Upgrade to ArduinoJSON 6
- Add mute/unmute via MQTT
- Fixed OTA issues, remove webserver
v4.1:
- Configurable mic gain
- Fix on only listening to Dutch Rhasspy
v4.2:
- Support platformIO
v4.3:
- Force platform 1.9.0. Higher raises issues with the mic array
- Add muting of output and switching of output port
v4.4:
- Fix distortion issues, caused by incorrect handling of incoming audio
- Added resampling using Speex, resamples 8000 and up and converts mono
to stereo.
v4.5:
- Support streaming audio
v4.5.1:
- Fix distortion on lower samplerates
v5.0:
- Added ondevice wakeword detection using WakeNet, only Alexa available
v5.1:
- Added volume control, publish {"volume": 50} to the sitesid/audio topic
v5.12:
- Add dynamic hotword brightness, post {"hotword_brightness": 50 } to SITEID/everloop
v5.12.1:
- Fixed a couple of defects regarding input mute and disconnects
v6.0:
- Added configuration webserver
- Improved stability for MQTT stream
v7.0:
- Complete rewrite using StateMachine
- Support multiplate devices
- Removed Snips.ia support
- Removed local hotword detected (does not compile against latest espressif32)
Will hopefully be replaced by a porcupine lib soon
v7.1:
- Audio task should run on core 1
* ************************************************************************ */
#include <Arduino.h>
#include <ArduinoOTA.h>
#include <WiFi.h>
#include "device.h"
#define M5ATOMECHO 0
#define MATRIXVOICE 1
#define AUDIOKIT 2
#define TTGOCAMWHITE 3
#define DEVICE_TYPE 0 // Select from the list above.
#define WIFI_SSID ""
#define WIFI_PASS ""
#define OTA_PASS_HASH "start"
#define SITEID "atomecho"
#define HOSTNAME "atomecho"
#define MQTT_IP "192.168.1.167"
#define MQTT_PORT 1883
#define MQTT_USER ""
#define MQTT_PASS ""
#define MQTT_MAX_PACKET_SIZE 2000
#define CONFIG_ASYNC_TCP_RUNNING_CORE 1
boolean I2StaskCreated = false;
// Set these values below if you want this device to have a fixed IP address.
/*
#define HOST_IP "192.168.1.100"
#define HOST_GATEWAY "192.168.1.1"
#define HOST_SUBNET "255.255.255.0"
#define HOST_DNS1 "192.168.1.1"
#define HOST_DNS2 "192.168.1.1"
*/
// This is where you can include your device, make sure to create a *device
// The *device is used to call methods
#if DEVICE_TYPE == M5ATOMECHO
#include "devices/M5AtomEcho.hpp"
M5AtomEcho *device = new M5AtomEcho();
#elif DEVICE_TYPE == MATRIXVOICE
#include "devices/MatrixVoice.hpp"
MatrixVoice *device = new MatrixVoice();
#elif DEVICE_TYPE == AUDIOKIT
#include "devices/AudioKit.hpp"
AudioKit *device = new AudioKit();
#elif DEVICE_TYPE == TTGOCAMWHITE
#include "devices/TTGOCamWhite.hpp"
TTGOCamWhite *device = new TTGOCamWhite();
#endif
#include "General.hpp"
#include "StateMachine.hpp"
void setup() {
Serial.begin(115200);
Serial.println("Booting");
if (wbSemaphore == NULL) // Not yet been created?
{
wbSemaphore = xSemaphoreCreateMutex(); // Create a mutex semaphore
if ((wbSemaphore) != NULL) xSemaphoreGive(wbSemaphore); // Free for all
}
device->init();
if (!SPIFFS.begin(true)) {
Serial.println("Failed to mount file system");
} else {
Serial.println("Loading configuration");
loadConfiguration(configfile, config);
}
device->setGain(config.gain);
device->setVolume(config.volume);
// ---------------------------------------------------------------------------
// ArduinoOTA
// ---------------------------------------------------------------------------
ArduinoOTA.setPasswordHash(OTA_PASS_HASH);
ArduinoOTA
.onStart([]() {
Serial.println("Uploading...");
})
.onEnd([]() {
Serial.println("\nEnd");
})
.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
})
.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR)
Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR)
Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR)
Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR)
Serial.println("Receive Failed");
else if (error == OTA_END_ERROR)
Serial.println("End Failed");
});
fsm::start();
server.on("/", handleRequest);
server.begin();
Serial.print(F("end of setup"));
}
void loop() {
if (WiFi.isConnected()) {
//ArduinoOTA.handle();
}
fsm::run();
}