Browse Source

Merge remote-tracking branch 'upstream/master'

master
kkloesener 5 years ago
parent
commit
aff5365f87
  1. 6
      README.md
  2. 2
      openHAB/items/Home.items
  3. 3
      openHAB/sitemaps/Home.sitemap
  4. 2
      openHAB/things/mqttConntections.things
  5. 27
      platformio.ini
  6. 2
      src/logmessages.h
  7. 46
      src/main.cpp
  8. 3
      src/settings.h

6
README.md

@ -390,9 +390,9 @@ Feel free to use your own smarthome-environments (instead of openHAB). The MQTT-
| ----------------------- | --------------- | ------------------------------------------------------------------------------ |
| topicSleepCmnd | 0 or OFF | Power off Tonuino immediately |
| topicSleepState | ON or OFF | Sends Tonuino's current/last state |
| topicTrackCmnd | 12 digits | Set number of RFID-tag which 'emulates' an RFID-tag (e.g. `123789456089`) |
| topicTrackState | String | Sends current track number, total number of tracks and full path of current |
| | | track. E.g. "(2/10) /mp3/kinderlieder/Ri ra rutsch.mp3"
| topicRfidCmnd | 12 digits | Set number of RFID-tag which 'emulates' an RFID-tag (e.g. `123789456089`) |
| topicRfidState | 12 digits | ID of current RFID-tag (if not a modification-card) |
| topicTrackState | String | Sends current track number, total number of tracks and full path of curren track. E.g. "(2/10) /mp3/kinderlieder/Ri ra rutsch.mp3" |
| topicTrackControlCmnd | 1 -> 7 | `1`=stop; `2`=unused!; `3`=play/pause; `4`=next; `5`=prev; `6`=first; `7`=last |
| topicLoudnessCmnd | 0 -> 21 | Set loudness (depends on minVolume / maxVolume) |
| topicLoudnessState | 0 -> 21 | Sends loudness (depends on minVolume / maxVolume |

2
openHAB/items/Home.items

@ -7,7 +7,7 @@ Group ZimmerTim "Kinderzimmer Tim"
// Zimmer Kind
Switch Tonuino_Sleep { channel="mqtt:topic:MQTT:tonuino:tonuino_sleep_mqtt", autoupdate="true" }
String Tonuino_Track { channel="mqtt:topic:MQTT:tonuino:tonuino_track_mqtt", autoupdate="true" }
String Tonuino_Rfid { channel="mqtt:topic:MQTT:tonuino:rfid", autoupdate="true" }
Number Tonuino_Loudness "Lautstärke [%d]" { channel="mqtt:topic:MQTT:tonuino:tonuino_loudness_mqtt", autoupdate="true" }
String Tonuino_SleepTimer { channel="mqtt:topic:MQTT:tonuino:tonuino_sleeptimer_mqtt", autoupdate="true" }
String Tonuino_Status { channel="mqtt:topic:MQTT:tonuino:tonuino_status_mqtt", autoupdate="true", expire="2m, command=Offline" }

3
openHAB/sitemaps/Home.sitemap

@ -6,7 +6,7 @@ sitemap Home label="Home" {
Text item=Tonuino_Status label="Status" valuecolor=[Tonuino_Status==Online="green", ==Offline="red"] icon="network"
Switch item=Tonuino_Sleep label="Ausschalten" icon="wallswitch" mappings=[OFF="AUS"] visibility=[Tonuino_Status=="Online"]
Switch item=Tonuino_LockControls label="Sperren" icon="wallswitch" mappings=[OFF="AUS", ON="AN"] visibility=[Tonuino_Status=="Online"]
Selection item=Tonuino_Track label="Titelauswahl" icon="text" visibility=[Tonuino_Status=="Online"] mappings=[
Selection item=Tonuino_Rfid label="Titelauswahl" icon="text" visibility=[Tonuino_Status=="Online"] mappings=[
"244189084042"="Yakari und die Pferdediebe",
"244042007042"="Yakari - Der Gesang des Raben",
"004134024043"="Yakari - Schneeball in Gefahr",
@ -29,6 +29,7 @@ sitemap Home label="Home" {
Setpoint item=Tonuino_LedBrightness icon="lightbulb" label="LED-Helligkeit" visibility=[Tonuino_Status=="Online"] maxValue=64 step=2
Text item=Tonuino_IPv4 label="IP-Adresse" icon="network" visibility=[Tonuino_Status=="Online"]
Text item=Tonuino_CurrentTrack label="Aktuell:" icon="mediacontrol" visibility=[Tonuino_Status=="Online"]
Text item=Tonuino_Voltage label="Akkuspannung:" icon="batterylevel" visibility=[Tonuino_Status=="Online"]
}
}
}

2
openHAB/things/mqttConntections.things

@ -3,7 +3,7 @@ Bridge mqtt:broker:MQTT [ host="<mqttServerIP>", secure=false, username="<userna
Thing topic tonuino "Tonuino" {
Channels:
Type switch: tonuino_sleep_mqtt "Ausschalten" [ stateTopic="State/Tonuino/Sleep", commandTopic="Cmnd/Tonuino/Sleep", on="ON", off="OFF" ]
Type string: tonuino_track_mqtt "Track" [ stateTopic="State/Tonuino/Track", commandTopic="Cmnd/Tonuino/Track" ]
Type string: tonuino_rfid_mqtt "Track" [ stateTopic="State/Tonuino/Rfid", commandTopic="Cmnd/Tonuino/Rfid" ]
Type number: tonuino_loudness_mqtt "Lautstaerke" [ stateTopic="State/Tonuino/Loudness", commandTopic="Cmnd/Tonuino/Loudness" ]
Type string: tonuino_sleeptimer_mqtt "Sleep-Timer" [ stateTopic="State/Tonuino/SleepTimer", commandTopic="Cmnd/Tonuino/SleepTimer" ]
Type string: tonuino_status_mqtt "Status" [ stateTopic="State/Tonuino/State" ]

27
platformio.ini

@ -17,12 +17,19 @@ lib_deps_external =
https://github.com/madhephaestus/ESP32Encoder.git
https://github.com/knolleary/pubsubclient.git
https://github.com/biologist79/ESP32FTPServer
https://github.com/FastLED/FastLED.git
https://github.com/FastLED/FastLED.git#3.3.3
ESP Async WebServer
https://github.com/me-no-dev/AsyncTCP
https://github.com/bblanchon/ArduinoJson.git
; https://github.com/pschatzmann/ESP32-A2DP.git
[env:common]
build_flags = -DHAL=1
; Don't forget to run this script if you changed the html-files provided in any way
extra_scripts =
pre:processHtml.py
[env:esp32-a12]
platform = espressif32
board = esp-wrover-kit
@ -42,7 +49,6 @@ board = lolin32
framework = arduino
monitor_speed = 115200
board_build.partitions = no_ota.csv
build_flags = -DHAL=1
lib_deps =
${common.lib_deps_builtin}
${common.lib_deps_external}
@ -57,6 +63,8 @@ board = lolin_d32
framework = arduino
monitor_speed = 115200
board_build.partitions = no_ota.csv
lib_deps = ${env:common.lib_deps}
extra_scripts = ${env:common.extra_scripts}
upload_port = /dev/cu.SLAB_USBtoUART
monitor_port = /dev/cu.SLAB_USBtoUART
@ -66,8 +74,10 @@ board = lolin_d32_pro
framework = arduino
monitor_speed = 115200
board_build.partitions = no_ota.csv
upload_port = /dev/cu.SLAB_USBtoUART
monitor_port = /dev/cu.SLAB_USBtoUART
lib_deps = ${env:common.lib_deps}
extra_scripts = ${env:common.extra_scripts}
upload_port = COM6
monitor_port = COM6
[env:nodemcu-32s]
platform = espressif32
@ -75,6 +85,8 @@ board = nodemcu-32s
framework = arduino
monitor_speed = 115200
board_build.partitions = no_ota.csv
lib_deps = ${env:common.lib_deps}
extra_scripts = ${env:common.extra_scripts}
upload_port = /dev/cu.SLAB_USBtoUART
monitor_port = /dev/cu.SLAB_USBtoUART
@ -84,6 +96,8 @@ board = az-delivery-devkit-v4
framework = arduino
monitor_speed = 115200
board_build.partitions = no_ota.csv
lib_deps = ${env:common.lib_deps}
extra_scripts = ${env:common.extra_scripts}
upload_port = /dev/cu.SLAB_USBtoUART
monitor_port = /dev/cu.SLAB_USBtoUART
@ -93,7 +107,4 @@ monitor_port = /dev/cu.SLAB_USBtoUART
;WINDOWS: COM3
;LINUX: /dev/ttyUSB0 (if it's the first USB-device attached, otherwise increase number)
; Don't forget to run this script if you changed the html-files provided in any way
extra_scripts =
pre:processHtml.py
[env:]

2
src/logmessages.h

@ -153,7 +153,7 @@ static const char warningLowVoltageFromNVS[] PROGMEM = "Spannungslevel (Batterie
static const char unableToRestoreLastRfidFromNVS[] PROGMEM = "Letzte RFID konnte nicht aus NVS geladen werden";
static const char restoredLastRfidFromNVS[] PROGMEM = "Letzte RFID wurde aus NVS geladen";
static const char failedOpenFileForWrite[] PROGMEM = "Öffnen der Datei für den Schreibvorgang fehlgeschlagen";
static const char fileWritten[] PROGMEM = "Schreibe Datei";
static const char fileWritten[] PROGMEM = "Datei geschrieben";
static const char writeFailed[] PROGMEM = "Schreibvorgang fehlgeschlagen";
static const char writingFile[] PROGMEM = "Schreibe Datei";
static const char failedToOpenFileForAppending[] PROGMEM = "Öffnen der Datei zum Schreiben der JSON-Datei fehlgeschlagen";

46
src/main.cpp

@ -615,10 +615,17 @@ void fileHandlingTask(void *arguments) {
}
// Measures voltage of a battery as per interval or after bootup (after allowing a few seconds to settle down)
// The average of several analog reads will be taken to reduce the noise (Note: One analog read takes ~10µs)
#ifdef MEASURE_BATTERY_VOLTAGE
float measureBatteryVoltage(void) {
float factor = 1 / ((float) rdiv2/(rdiv2+rdiv1));
return ((float) analogRead(VOLTAGE_READ_PIN) / maxAnalogValue) * refVoltage * factor;
float averagedAnalogValue = 0;
int i;
for(i=0; i<=19; i++){
averagedAnalogValue += (float)analogRead(VOLTAGE_READ_PIN);
}
averagedAnalogValue /= 20.0;
return (averagedAnalogValue / maxAnalogValue) * refVoltage * factor;
}
void batteryVoltageTester(void) {
@ -860,8 +867,8 @@ bool reconnect() {
// Deepsleep-subscription
MQTTclient.subscribe((char *) FPSTR(topicSleepCmnd));
// Trackname-subscription
MQTTclient.subscribe((char *) FPSTR(topicTrackCmnd));
// RFID-Tag-ID-subscription
MQTTclient.subscribe((char *) FPSTR(topicRfidCmnd));
// Loudness-subscription
MQTTclient.subscribe((char *) FPSTR(topicLoudnessCmnd));
@ -921,7 +928,7 @@ void callback(const char *topic, const byte *payload, uint32_t length) {
}
// New track to play? Take RFID-ID as input
else if (strcmp_P(topic, topicTrackCmnd) == 0) {
else if (strcmp_P(topic, topicRfidCmnd) == 0) {
char *_rfidId = strdup(receivedString);
xQueueSend(rfidCardQueue, &_rfidId, 0);
//free(_rfidId);
@ -1402,6 +1409,7 @@ void playAudio(void *parameter) {
uint8_t currentVolume;
static BaseType_t trackQStatus;
static uint8_t trackCommand = 0;
bool audioReturnCode;
for (;;) {
if (xQueueReceive(volumeQueue, &currentVolume, 0) == pdPASS ) {
@ -1544,7 +1552,10 @@ void playAudio(void *parameter) {
#endif
}
if (playProperties.currentTrackNumber > 0) {
// play previous track when current track time is small, else play current track again
if(audio.getAudioCurrentTime() < 2) {
playProperties.currentTrackNumber--;
}
if (playProperties.saveLastPlayPosition) {
nvsRfidWriteWrapper(playProperties.playRfidTag, *(playProperties.playlist + playProperties.currentTrackNumber), 0, playProperties.playMode, playProperties.currentTrackNumber, playProperties.numberOfTracks);
loggerNl((char *) FPSTR(trackStartAudiobook), LOGLEVEL_INFO);
@ -1570,7 +1581,15 @@ void playAudio(void *parameter) {
#ifdef NEOPIXEL_ENABLE
showRewind = true;
#endif
audio.connecttoFS(FSystem, *(playProperties.playlist + playProperties.currentTrackNumber));
audioReturnCode = audio.connecttoFS(FSystem, *(playProperties.playlist + playProperties.currentTrackNumber));
// consider track as finished, when audio lib call was not successful
if (!audioReturnCode) {
#ifdef NEOPIXEL_ENABLE
showLedError = true;
#endif
playProperties.trackFinished = true;
continue;
}
loggerNl((char *) FPSTR(trackStart), LOGLEVEL_INFO);
trackCommand = 0;
continue;
@ -1703,7 +1722,15 @@ void playAudio(void *parameter) {
playProperties.trackFinished = true;
continue;
} else {
audio.connecttoFS(FSystem, *(playProperties.playlist + playProperties.currentTrackNumber));
audioReturnCode = audio.connecttoFS(FSystem, *(playProperties.playlist + playProperties.currentTrackNumber));
// consider track as finished, when audio lib call was not successful
if(!audioReturnCode) {
#ifdef NEOPIXEL_ENABLE
showLedError = true;
#endif
playProperties.trackFinished = true;
continue;
}
#ifdef NEOPIXEL_ENABLE
showPlaylistProgress = true;
#endif
@ -3004,6 +3031,9 @@ void rfidPreferenceLookupHandler (void) {
if (_playMode >= 100) {
doRfidCardModifications(_playMode);
} else {
#ifdef MQTT_ENABLE
publishMqtt((char *) FPSTR(topicRfidState), currentRfidTagId, false);
#endif
trackQueueDispatcher(_file, _lastPlayPos, _playMode, _trackLastPlayed);
}
}
@ -4190,10 +4220,6 @@ void audio_showstation(const char *info) {
publishMqtt((char *) FPSTR(topicTrackState), buf, false);
#endif
}
void audio_showstreaminfo(const char *info) {
snprintf(logBuf, serialLoglength, "streaminfo : %s", info);
loggerNl(logBuf, LOGLEVEL_INFO);
}
void audio_showstreamtitle(const char *info) {
snprintf(logBuf, serialLoglength, "streamtitle : %s", info);
loggerNl(logBuf, LOGLEVEL_INFO);

3
src/settings.h

@ -95,7 +95,8 @@ float voltageIndicatorHigh = 4.2; // Upper range for Neopixel-
#define DEVICE_HOSTNAME "ESP32-Tonuino" // Name that that is used for MQTT
static const char topicSleepCmnd[] PROGMEM = "Cmnd/Tonuino/Sleep";
static const char topicSleepState[] PROGMEM = "State/Tonuino/Sleep";
static const char topicTrackCmnd[] PROGMEM = "Cmnd/Tonuino/Track";
static const char topicRfidCmnd[] PROGMEM = "Cmnd/Tonuino/Rfid";
static const char topicRfidState[] PROGMEM = "State/Tonuino/Rfid";
static const char topicTrackState[] PROGMEM = "State/Tonuino/Track";
static const char topicTrackControlCmnd[] PROGMEM = "Cmnd/Tonuino/TrackControl";
static const char topicLoudnessCmnd[] PROGMEM = "Cmnd/Tonuino/Loudness";

Loading…
Cancel
Save