diff --git a/README.md b/README.md index ff6becb..49c90f7 100644 --- a/README.md +++ b/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 | diff --git a/openHAB/items/Home.items b/openHAB/items/Home.items index 35484a2..c3d5fde 100644 --- a/openHAB/items/Home.items +++ b/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" } diff --git a/openHAB/sitemaps/Home.sitemap b/openHAB/sitemaps/Home.sitemap index b261476..0735c71 100644 --- a/openHAB/sitemaps/Home.sitemap +++ b/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"] } } } diff --git a/openHAB/things/mqttConntections.things b/openHAB/things/mqttConntections.things index 57512b4..0b7a3c1 100644 --- a/openHAB/things/mqttConntections.things +++ b/openHAB/things/mqttConntections.things @@ -3,7 +3,7 @@ Bridge mqtt:broker:MQTT [ host="", secure=false, username=" 0) { - playProperties.currentTrackNumber--; + // 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); diff --git a/src/settings.h b/src/settings.h index 6f7b214..9ef88f8 100644 --- a/src/settings.h +++ b/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";