v0.9.141
This commit is contained in:
@@ -226,6 +226,10 @@ Work is in progress...
|
|||||||
|
|
||||||
---
|
---
|
||||||
## Version history
|
## Version history
|
||||||
|
#### v0.9.141
|
||||||
|
- fixed error reconnecting to WiFi when connection is lost
|
||||||
|
- ADDED a compilation error when choosing a board other than "ESP32 Dev Module" or "ESP32 Wrover Module"
|
||||||
|
|
||||||
#### v0.9.130
|
#### v0.9.130
|
||||||
- fixed crash in configurations with NOKIA5110 displays
|
- fixed crash in configurations with NOKIA5110 displays
|
||||||
- fixed bug with displaying buffer indicator when switching audioinfo
|
- fixed bug with displaying buffer indicator when switching audioinfo
|
||||||
|
|||||||
134
yoRadio/src/core/audiohandlers.h
Normal file
134
yoRadio/src/core/audiohandlers.h
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
#ifndef AUDIOHANDLERS_H
|
||||||
|
#define AUDIOHANDLERS_H
|
||||||
|
|
||||||
|
//=============================================//
|
||||||
|
// Audio handlers //
|
||||||
|
//=============================================//
|
||||||
|
|
||||||
|
void audio_info(const char *info) {
|
||||||
|
if(player.lockOutput) return;
|
||||||
|
if(config.store.audioinfo) telnet.printf("##AUDIO.INFO#: %s\n", info);
|
||||||
|
#ifdef USE_NEXTION
|
||||||
|
nextion.audioinfo(info);
|
||||||
|
#endif
|
||||||
|
if (strstr(info, "skip metadata") != NULL) config.setTitle(config.station.name);
|
||||||
|
if (strstr(info, "Account already in use") != NULL || strstr(info, "HTTP/1.0 401") != NULL) {
|
||||||
|
player.setError(info);
|
||||||
|
|
||||||
|
}
|
||||||
|
char* ici; char b[20]={0};
|
||||||
|
if ((ici = strstr(info, "BitRate: ")) != NULL) {
|
||||||
|
strlcpy(b, ici + 9, 50);
|
||||||
|
audio_bitrate(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void audio_bitrate(const char *info)
|
||||||
|
{
|
||||||
|
if(config.store.audioinfo) telnet.printf("%s %s\n", "##AUDIO.BITRATE#:", info);
|
||||||
|
config.station.bitrate = atoi(info) / 1000;
|
||||||
|
display.putRequest(DBITRATE);
|
||||||
|
#ifdef USE_NEXTION
|
||||||
|
nextion.bitrate(config.station.bitrate);
|
||||||
|
#endif
|
||||||
|
netserver.requestOnChange(BITRATE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool printable(const char *info) {
|
||||||
|
bool p = true;
|
||||||
|
for (int c = 0; c < strlen(info); c++)
|
||||||
|
{
|
||||||
|
if ((uint8_t)info[c] > 0x7e || (uint8_t)info[c] < 0x20) p = false;
|
||||||
|
}
|
||||||
|
if (!p) p = (uint8_t)info[0] >= 0xC2 && (uint8_t)info[1] >= 0x80 && (uint8_t)info[1] <= 0xBF;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void audio_showstation(const char *info) {
|
||||||
|
bool p = printable(info) && (strlen(info) > 0);(void)p;
|
||||||
|
//config.setTitle(p?info:config.station.name);
|
||||||
|
if(player.remoteStationName){
|
||||||
|
config.setStation(p?info:config.station.name);
|
||||||
|
display.putRequest(NEWSTATION);
|
||||||
|
netserver.requestOnChange(STATION, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void audio_showstreamtitle(const char *info) {
|
||||||
|
DBGH();
|
||||||
|
if (strstr(info, "Account already in use") != NULL || strstr(info, "HTTP/1.0 401") != NULL) player.setError(info);
|
||||||
|
bool p = printable(info) && (strlen(info) > 0);
|
||||||
|
#ifdef DEBUG_TITLES
|
||||||
|
config.setTitle(DEBUG_TITLES);
|
||||||
|
#else
|
||||||
|
config.setTitle(p?info:config.station.name);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void audio_error(const char *info) {
|
||||||
|
//config.setTitle(info);
|
||||||
|
player.setError(info);
|
||||||
|
telnet.printf("##ERROR#:\t%s\n", info);
|
||||||
|
}
|
||||||
|
|
||||||
|
void audio_id3artist(const char *info){
|
||||||
|
if(printable(info)) config.setStation(info);
|
||||||
|
display.putRequest(NEWSTATION);
|
||||||
|
netserver.requestOnChange(STATION, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void audio_id3album(const char *info){
|
||||||
|
if(player.lockOutput) return;
|
||||||
|
if(printable(info)){
|
||||||
|
if(strlen(config.station.title)==0){
|
||||||
|
config.setTitle(info);
|
||||||
|
}else{
|
||||||
|
char out[BUFLEN]= {0};
|
||||||
|
strlcat(out, config.station.title, BUFLEN);
|
||||||
|
strlcat(out, " - ", BUFLEN);
|
||||||
|
strlcat(out, info, BUFLEN);
|
||||||
|
config.setTitle(out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void audio_id3title(const char *info){
|
||||||
|
audio_id3album(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
void audio_beginSDread(){
|
||||||
|
config.setTitle("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void audio_id3data(const char *info){ //id3 metadata
|
||||||
|
if(player.lockOutput) return;
|
||||||
|
telnet.printf("##AUDIO.ID3#: %s\n", info);
|
||||||
|
}
|
||||||
|
|
||||||
|
void audio_eof_mp3(const char *info){ //end of file
|
||||||
|
config.sdResumePos = 0;
|
||||||
|
if(config.sdSnuffle){
|
||||||
|
player.sendCommand({PR_PLAY, random(1, config.store.countStation)});
|
||||||
|
}else{
|
||||||
|
player.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void audio_eof_stream(const char *info){
|
||||||
|
player.sendCommand({PR_STOP, 0});
|
||||||
|
if(!player.resumeAfterUrl) return;
|
||||||
|
if (config.store.play_mode==PM_WEB){
|
||||||
|
player.sendCommand({PR_PLAY, config.store.lastStation});
|
||||||
|
}else{
|
||||||
|
player.setResumeFilePos( config.sdResumePos==0?0:config.sdResumePos-player.sd_min);
|
||||||
|
player.sendCommand({PR_PLAY, config.store.lastStation});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void audio_progress(uint32_t startpos, uint32_t endpos){
|
||||||
|
player.sd_min = startpos;
|
||||||
|
player.sd_max = endpos;
|
||||||
|
netserver.requestOnChange(SDLEN, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -67,12 +67,14 @@ decode_results irResults;
|
|||||||
#if ENC_BTNL!=255
|
#if ENC_BTNL!=255
|
||||||
void IRAM_ATTR readEncoderISR()
|
void IRAM_ATTR readEncoderISR()
|
||||||
{
|
{
|
||||||
|
if(display.mode()==LOST || display.mode()==UPDATING) return;
|
||||||
encoder.readEncoder_ISR();
|
encoder.readEncoder_ISR();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if ENC2_BTNL!=255
|
#if ENC2_BTNL!=255
|
||||||
void IRAM_ATTR readEncoder2ISR()
|
void IRAM_ATTR readEncoder2ISR()
|
||||||
{
|
{
|
||||||
|
if(display.mode()==LOST || display.mode()==UPDATING) return;
|
||||||
encoder2.readEncoder_ISR();
|
encoder2.readEncoder_ISR();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "WiFi.h"
|
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "telnet.h"
|
#include "telnet.h"
|
||||||
#include "netserver.h"
|
#include "netserver.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include "mqtt.h"
|
||||||
|
|
||||||
Network network;
|
Network network;
|
||||||
|
|
||||||
@@ -50,6 +50,27 @@ void ticks() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Network::WiFiReconnected(WiFiEvent_t event, WiFiEventInfo_t info){
|
||||||
|
network.beginReconnect = false;
|
||||||
|
delay(100);
|
||||||
|
display.putRequest(NEWMODE, PLAYER);
|
||||||
|
if (network.lostPlaying) player.sendCommand({PR_PLAY, config.store.lastStation});
|
||||||
|
#ifdef MQTT_ROOT_TOPIC
|
||||||
|
connectToMqtt();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void Network::WiFiLostConnection(WiFiEvent_t event, WiFiEventInfo_t info){
|
||||||
|
if(!network.beginReconnect){
|
||||||
|
Serial.println("Lost connection, reconnecting...");
|
||||||
|
network.lostPlaying = player.isRunning();
|
||||||
|
if (network.lostPlaying) { player.sendCommand({PR_STOP, 0}); }
|
||||||
|
display.putRequest(NEWMODE, LOST);
|
||||||
|
}
|
||||||
|
network.beginReconnect = true;
|
||||||
|
WiFi.begin(config.ssids[config.store.lastSSID].ssid, config.ssids[config.store.lastSSID].password);
|
||||||
|
}
|
||||||
|
|
||||||
#define DBGAP false
|
#define DBGAP false
|
||||||
|
|
||||||
void Network::begin() {
|
void Network::begin() {
|
||||||
@@ -98,7 +119,8 @@ void Network::begin() {
|
|||||||
if(LED_BUILTIN!=255) digitalWrite(LED_BUILTIN, LOW);
|
if(LED_BUILTIN!=255) digitalWrite(LED_BUILTIN, LOW);
|
||||||
status = CONNECTED;
|
status = CONNECTED;
|
||||||
WiFi.setSleep(false);
|
WiFi.setSleep(false);
|
||||||
|
WiFi.onEvent(WiFiReconnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_CONNECTED);
|
||||||
|
WiFi.onEvent(WiFiLostConnection, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
|
||||||
weatherBuf=NULL;
|
weatherBuf=NULL;
|
||||||
trueWeather = false;
|
trueWeather = false;
|
||||||
#if (DSP_MODEL!=DSP_DUMMY || defined(USE_NEXTION)) && !defined(HIDE_WEATHER)
|
#if (DSP_MODEL!=DSP_DUMMY || defined(USE_NEXTION)) && !defined(HIDE_WEATHER)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define network_h
|
#define network_h
|
||||||
#include <Ticker.h>
|
#include <Ticker.h>
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
|
#include "WiFi.h"
|
||||||
|
|
||||||
#define apSsid "yoRadioAP"
|
#define apSsid "yoRadioAP"
|
||||||
#define apPassword "12345987"
|
#define apPassword "12345987"
|
||||||
@@ -16,6 +17,7 @@ class Network {
|
|||||||
n_Status_e status;
|
n_Status_e status;
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
bool firstRun, forceTimeSync, forceWeather;
|
bool firstRun, forceTimeSync, forceWeather;
|
||||||
|
bool lostPlaying = false, beginReconnect = false;
|
||||||
//uint8_t tsFailCnt, wsFailCnt;
|
//uint8_t tsFailCnt, wsFailCnt;
|
||||||
public:
|
public:
|
||||||
Network() {};
|
Network() {};
|
||||||
@@ -28,6 +30,8 @@ class Network {
|
|||||||
private:
|
private:
|
||||||
Ticker rtimer;
|
Ticker rtimer;
|
||||||
void raiseSoftAP();
|
void raiseSoftAP();
|
||||||
|
static void WiFiLostConnection(WiFiEvent_t event, WiFiEventInfo_t info);
|
||||||
|
static void WiFiReconnected(WiFiEvent_t event, WiFiEventInfo_t info);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Network network;
|
extern Network network;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef options_h
|
#ifndef options_h
|
||||||
#define options_h
|
#define options_h
|
||||||
|
|
||||||
#define YOVERSION "0.9.130"
|
#define YOVERSION "0.9.141"
|
||||||
|
|
||||||
/*******************************************************
|
/*******************************************************
|
||||||
DO NOT EDIT THIS FILE.
|
DO NOT EDIT THIS FILE.
|
||||||
|
|||||||
@@ -13,8 +13,9 @@
|
|||||||
# error YOU MUST CHOOSE BETWEEN I2S DAC AND VS1053 BY DISABLING THE SECOND MODULE IN THE myoptions.h
|
# error YOU MUST CHOOSE BETWEEN I2S DAC AND VS1053 BY DISABLING THE SECOND MODULE IN THE myoptions.h
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ARDUINO_ESP32_DEV
|
||||||
|
# error ONLY MODULES "ESP32 Dev Module" AND "ESP32 Wrover Module" ARE SUPPORTED. PLEASE SELECT ONE OF THEM IN THE MENU >> TOOLS >> BOARD
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -61,160 +61,8 @@ void loop() {
|
|||||||
if (network.status == CONNECTED) {
|
if (network.status == CONNECTED) {
|
||||||
player.loop();
|
player.loop();
|
||||||
loopControls();
|
loopControls();
|
||||||
checkConnection();
|
|
||||||
}
|
}
|
||||||
netserver.loop();
|
netserver.loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkConnection(){
|
#include "src/core/audiohandlers.h"
|
||||||
static uint32_t checkMillis = 0;
|
|
||||||
static uint32_t checkInterval = 3000;
|
|
||||||
if ((WiFi.status() != WL_CONNECTED) && (millis() - checkMillis >=checkInterval)) {
|
|
||||||
bool playing = player.isRunning();
|
|
||||||
if (playing) { player.sendCommand({PR_STOP, 0}); player.loop(); }
|
|
||||||
display.putRequest(NEWMODE, LOST);
|
|
||||||
Serial.println("Lost connection, reconnecting...");
|
|
||||||
while(true){
|
|
||||||
if (WiFi.status() == WL_CONNECTED) break;
|
|
||||||
WiFi.disconnect();
|
|
||||||
WiFi.reconnect();
|
|
||||||
delay(3000);
|
|
||||||
}
|
|
||||||
display.putRequest(NEWMODE, PLAYER);
|
|
||||||
if (playing) player.sendCommand({PR_PLAY, config.store.lastStation});
|
|
||||||
checkMillis = millis();
|
|
||||||
#ifdef MQTT_ROOT_TOPIC
|
|
||||||
connectToMqtt();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//=============================================//
|
|
||||||
// Audio handlers //
|
|
||||||
//=============================================//
|
|
||||||
|
|
||||||
void audio_info(const char *info) {
|
|
||||||
if(player.lockOutput) return;
|
|
||||||
if(config.store.audioinfo) telnet.printf("##AUDIO.INFO#: %s\n", info);
|
|
||||||
#ifdef USE_NEXTION
|
|
||||||
nextion.audioinfo(info);
|
|
||||||
#endif
|
|
||||||
if (strstr(info, "skip metadata") != NULL) config.setTitle(config.station.name);
|
|
||||||
if (strstr(info, "Account already in use") != NULL || strstr(info, "HTTP/1.0 401") != NULL) {
|
|
||||||
player.setError(info);
|
|
||||||
|
|
||||||
}
|
|
||||||
char* ici; char b[20]={0};
|
|
||||||
if ((ici = strstr(info, "BitRate: ")) != NULL) {
|
|
||||||
strlcpy(b, ici + 9, 50);
|
|
||||||
audio_bitrate(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void audio_bitrate(const char *info)
|
|
||||||
{
|
|
||||||
if(config.store.audioinfo) telnet.printf("%s %s\n", "##AUDIO.BITRATE#:", info);
|
|
||||||
config.station.bitrate = atoi(info) / 1000;
|
|
||||||
display.putRequest(DBITRATE);
|
|
||||||
#ifdef USE_NEXTION
|
|
||||||
nextion.bitrate(config.station.bitrate);
|
|
||||||
#endif
|
|
||||||
netserver.requestOnChange(BITRATE, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool printable(const char *info) {
|
|
||||||
bool p = true;
|
|
||||||
for (int c = 0; c < strlen(info); c++)
|
|
||||||
{
|
|
||||||
if ((uint8_t)info[c] > 0x7e || (uint8_t)info[c] < 0x20) p = false;
|
|
||||||
}
|
|
||||||
if (!p) p = (uint8_t)info[0] >= 0xC2 && (uint8_t)info[1] >= 0x80 && (uint8_t)info[1] <= 0xBF;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
void audio_showstation(const char *info) {
|
|
||||||
bool p = printable(info) && (strlen(info) > 0);(void)p;
|
|
||||||
//config.setTitle(p?info:config.station.name);
|
|
||||||
if(player.remoteStationName){
|
|
||||||
config.setStation(p?info:config.station.name);
|
|
||||||
display.putRequest(NEWSTATION);
|
|
||||||
netserver.requestOnChange(STATION, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void audio_showstreamtitle(const char *info) {
|
|
||||||
DBGH();
|
|
||||||
if (strstr(info, "Account already in use") != NULL || strstr(info, "HTTP/1.0 401") != NULL) player.setError(info);
|
|
||||||
bool p = printable(info) && (strlen(info) > 0);
|
|
||||||
#ifdef DEBUG_TITLES
|
|
||||||
config.setTitle(DEBUG_TITLES);
|
|
||||||
#else
|
|
||||||
config.setTitle(p?info:config.station.name);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void audio_error(const char *info) {
|
|
||||||
//config.setTitle(info);
|
|
||||||
player.setError(info);
|
|
||||||
telnet.printf("##ERROR#:\t%s\n", info);
|
|
||||||
}
|
|
||||||
|
|
||||||
void audio_id3artist(const char *info){
|
|
||||||
if(printable(info)) config.setStation(info);
|
|
||||||
display.putRequest(NEWSTATION);
|
|
||||||
netserver.requestOnChange(STATION, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void audio_id3album(const char *info){
|
|
||||||
if(player.lockOutput) return;
|
|
||||||
if(printable(info)){
|
|
||||||
if(strlen(config.station.title)==0){
|
|
||||||
config.setTitle(info);
|
|
||||||
}else{
|
|
||||||
char out[BUFLEN]= {0};
|
|
||||||
strlcat(out, config.station.title, BUFLEN);
|
|
||||||
strlcat(out, " - ", BUFLEN);
|
|
||||||
strlcat(out, info, BUFLEN);
|
|
||||||
config.setTitle(out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void audio_id3title(const char *info){
|
|
||||||
audio_id3album(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
void audio_beginSDread(){
|
|
||||||
config.setTitle("");
|
|
||||||
}
|
|
||||||
|
|
||||||
void audio_id3data(const char *info){ //id3 metadata
|
|
||||||
if(player.lockOutput) return;
|
|
||||||
telnet.printf("##AUDIO.ID3#: %s\n", info);
|
|
||||||
}
|
|
||||||
|
|
||||||
void audio_eof_mp3(const char *info){ //end of file
|
|
||||||
config.sdResumePos = 0;
|
|
||||||
if(config.sdSnuffle){
|
|
||||||
player.sendCommand({PR_PLAY, random(1, config.store.countStation)});
|
|
||||||
}else{
|
|
||||||
player.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void audio_eof_stream(const char *info){
|
|
||||||
player.sendCommand({PR_STOP, 0});
|
|
||||||
if(!player.resumeAfterUrl) return;
|
|
||||||
if (config.store.play_mode==PM_WEB){
|
|
||||||
player.sendCommand({PR_PLAY, config.store.lastStation});
|
|
||||||
}else{
|
|
||||||
player.setResumeFilePos( config.sdResumePos==0?0:config.sdResumePos-player.sd_min);
|
|
||||||
player.sendCommand({PR_PLAY, config.store.lastStation});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void audio_progress(uint32_t startpos, uint32_t endpos){
|
|
||||||
player.sd_min = startpos;
|
|
||||||
player.sd_max = endpos;
|
|
||||||
netserver.requestOnChange(SDLEN, 0);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user