Unverified Commit 8d1a79b0 authored by Wolle's avatar Wolle Committed by GitHub

Merge pull request #465 from schreibfaul1/master

update from master
parents fe1f37c9 0ef0ca35
// This arduino sketch for ESP32 announces the time every hour.
// A connection to the Internet is required
// 1) to synchronize with the internal RTC on startup
// 2) so that GoogleTTS can be reached
#include <Arduino.h>
#include "WiFiMulti.h"
#include "Audio.h"
#include "time.h"
#include "esp_sntp.h"
//------------------------USER SETTINGS / GPIOs-------------------------------------------------------------------------
String ssid = "xxxx";
String password = "xxxx";
uint8_t I2S_BCLK = 27;
uint8_t I2S_LRC = 26;
uint8_t I2S_DOUT = 25;
//------------------------OBJECTS /GLOBAL VARS--------------------------------------------------------------------------
Audio audio(false, 3, 0);
WiFiMulti wifiMulti;
uint32_t sec1 = millis();
String time_s = "";
char chbuf[200];
int timeIdx = 0;
//------------------------TIME / SNTP STUFF-----------------------------------------------------------------------------
#define TZName "CET-1CEST,M3.5.0,M10.5.0/3" // https://remotemonitoringsystems.ca/time-zone-abbreviations.php
char strftime_buf[64];
struct tm timeinfo;
time_t now;
boolean obtain_time(){
time_t now = 0;
int retry = 0;
Serial.println("Initializing SNTP");
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, "pool.ntp.org");
sntp_init();
const int retry_count = 10;
while(timeinfo.tm_year < (2016 - 1900) && ++retry < retry_count) {
Serial.printf("Waiting for system time to be set... (%d/%d)\n", retry, retry_count);
vTaskDelay(uint16_t(2000 / portTICK_PERIOD_MS));
time(&now);
localtime_r(&now, &timeinfo);
}
setenv("TZ", TZName, 1);
tzset();
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
if(retry < retry_count) return true;
else return false;
}
const char* gettime_s(){ // hh:mm:ss
time(&now);
localtime_r(&now, &timeinfo);
sprintf(strftime_buf,"%02d:%02d:%02d", timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
return strftime_buf;
}
//-----------------------SETUP------------------------------------------------------------------------------------------
void setup() {
Serial.begin(115200);
wifiMulti.addAP(ssid.c_str(), password.c_str());
wifiMulti.run();
obtain_time();
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(15);
}
//-----------------------LOOP-------------------------------------------------------------------------------------------
void loop() {
audio.loop();
if(sec1 < millis()){ // every second
sec1 = millis() + 1000;
time_s = gettime_s();
Serial.println(time_s);
if(time_s.endsWith("00:00")){ // time announcement every full hour
char am_pm[5] = "am.";
int h = time_s.substring(0,2).toInt();
if(h > 12){h -= 12; strcpy(am_pm,"pm.");}
sprintf(chbuf, "It is now %i%s and %i minutes", h, am_pm, time_s.substring(3,5).toInt());
Serial.println(chbuf);
audio.connecttospeech(chbuf, "en");
}
}
}
//------------------EVENTS----------------------------------------------------------------------------------------------
void audio_info(const char *info){
Serial.printf("info: %s\n", info);
}
\ No newline at end of file
......@@ -3,8 +3,8 @@
*
* Created on: Oct 26.2018
*
* Version 2.0.8c
* Updated on: Jan 11.2023
* Version 2.0.8d
* Updated on: Jan 13.2023
* Author: Wolle (schreibfaul1)
*
*/
......@@ -2560,6 +2560,7 @@ const char* Audio::parsePlaylist_M3U8(){
strcpy(m_lastHost, tmp);
if(tmp){free(tmp); tmp = NULL;}
if(m_f_Log) log_i("redirect %s", m_playlistContent[i]);
_client->stop();
return m_playlistContent[i]; // it's a redirection, a new m3u8 playlist
}
......@@ -4637,12 +4638,14 @@ bool Audio::ts_parsePacket(uint8_t* packet, uint8_t* packetStart, uint8_t* packe
if(m_f_Log) log_i("Adaptation Field Length: %d", AFL);
}
int PLS = PUSI ? 5 : 4; // PayLoadStart, Payload Unit Start Indicator
if(AFL > 0) PLS += AFL + 1; // skip adaption field
if(PID == 0) {
// Program Association Table (PAT) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if(m_f_Log) log_i("PAT");
pidsOfPMT.number = 0;
pidOfAAC = 0;
int startOfProgramNums = 8;
int lengthOfPATValue = 4;
int sectionLength = ((packet[PLS + 1] & 0x0F) << 8) | (packet[PLS + 2] & 0xFF);
......
......@@ -4,7 +4,7 @@
* Created on: Oct 28,2018
*
* Version 2.0.8c
* Updated on: Jan 11,2023
* Updated on: Jan 13,2023
* Author: Wolle (schreibfaul1)
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment