New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request: New MQTT option #31
Comments
@Duzeper this is something that's cropped up a few times. Wolfgang asked about a couple of things that could be switched using MQTT (possibly with voice activation) and I need to sort out all the other good ideas and put something in the docs if I don't add the actual code. |
Thanks Paddy.
I have another issue Re. MQTT. When I first started experimenting, I tried to set up a ‘pause’ command but it seemed that it made the picture frame pause permanently. At this point I gave up with MQTT and uninstalled and reinstalled the picture frame. This appeared to fix the issue, so I carried on with setting up timer/services and all was working fine.
I have just gone back to trying MQTT but I have found where the ‘permanent pause’ is occurring. When I set parameter -m “use_mqtt” to True and run the picture frame, then it displays the first photo, but it never changes. A soon as I revert to “use_mqtt” – False it all works fine again.
I have set “mqtt_server” to my Raspberry Pi’s IP address and not changed the other mqtt parameters.
Is there a glitch in the code or (much more likely) am I doing something wrong ?
Martin
From: paddywwoof <notifications@github.com>
Sent: 09 November 2020 16:44
To: pi3d/pi3d_demos <pi3d_demos@noreply.github.com>
Cc: Duzeper <mhdashper@virginmedia.com>; Mention <mention@noreply.github.com>
Subject: Re: [pi3d/pi3d_demos] Request: New MQTT option (#31)
@Duzeper <https://github.com/Duzeper> this is something that's cropped up a few times. Wolfgang asked about a couple of things that could be switched using MQTT (possibly with voice activation) and I need to sort out all the other good ideas and put something in the docs if I don't add the actual code.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#31 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AKJICPH62KZNODYVK3YONH3SPAL6DANCNFSM4TPNZROA> . <https://github.com/notifications/beacon/AKJICPATOQFANV372J53ST3SPAL6DA5CNFSM4TPNZROKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFMUWDAA.gif>
|
Martin, I haven't use MQTT on my setup for a while (the 'free' testing servers keep deciding they can't afford to keep being free) I will install an MQTT server on my RPi and check it out and see if I can reproduce you issue. Thanks for reporting the problem. |
Thanks.
A development. I have set up the ‘Quit’ MQTT command and it works fine.
I have also set up the ‘Pause’ command and that seems to work randomly. Sometimes the display un-pauses and displays the next photo but then that one will ‘freeze’. If I tap the pause button a random number of times then it will happen again.
Also, not sure if it is related but, sometimes, when I hit ‘quit’ or Ctrl+C I get a Terminal message ‘glGetError 0x500’
Martin
From: paddywwoof <notifications@github.com>
Sent: 14 November 2020 13:59
To: pi3d/pi3d_demos <pi3d_demos@noreply.github.com>
Cc: Duzeper <mhdashper@virginmedia.com>; Mention <mention@noreply.github.com>
Subject: Re: [pi3d/pi3d_demos] Request: New MQTT option (#31)
Martin, I haven't use MQTT on my setup for a while (the 'free' testing servers keep deciding they can't afford to keep being free) I will install an MQTT server on my RPi and check it out and see if I can reproduce you issue. Thanks for reporting the problem.
Paddy
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#31 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AKJICPGAKCDV4P6GFJWUC7DSP2ELPANCNFSM4TPNZROA> . <https://github.com/notifications/beacon/AKJICPA27BG2DAXFKD2YJ4TSP2ELPA5CNFSM4TPNZROKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFNMFYEA.gif>
|
Paddy, another observation (probably not connected at all). While running pictureFrame2020 successfully (ie. With use_mqtt set to ‘False’) from a timer/service, Ctrl+C appears to have no effect, except I have noticed that it actually does stop the program, but several hours later.
Martin
From: paddywwoof <notifications@github.com>
Sent: 14 November 2020 13:59
To: pi3d/pi3d_demos <pi3d_demos@noreply.github.com>
Cc: Duzeper <mhdashper@virginmedia.com>; Mention <mention@noreply.github.com>
Subject: Re: [pi3d/pi3d_demos] Request: New MQTT option (#31)
Martin, I haven't use MQTT on my setup for a while (the 'free' testing servers keep deciding they can't afford to keep being free) I will install an MQTT server on my RPi and check it out and see if I can reproduce you issue. Thanks for reporting the problem.
Paddy
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#31 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AKJICPGAKCDV4P6GFJWUC7DSP2ELPANCNFSM4TPNZROA> .
|
Martin, I'm working my way through the MQTT stuff now. What I did was (all via ssh to the RPi which is running at command prompt with no desktop):
parse.add_argument("-m", "--use_mqtt", default=True)
parse.add_argument( "--mqtt_server", default="localhost")
parse.add_argument( "--mqtt_port", default=1883, type=int)
parse.add_argument( "--mqtt_login", default="")
parse.add_argument( "--mqtt_password", default="")
|
OK, to recap, I had done 1 & 2, and with parameter -m set to default=False, then the Picture Frame would run normally and display photos one after the other. Command 6 (quit) works fine as well However, when it comes to putting this into Android MQTT Dash, it gets a bit more complicated:- PS I could not use command 4 (xinit.....) as it gave an error:- pi@raspberrypi:~ $ sudo xinit /usr/bin/python3 /home/pi/pi3d_demos/PictureFrame2020.py (EE) I can start the frame with 'python3 /home/pi/pi3d_demos/PictureFrame2020.py' so I assume that is not an issue. |
Hi OK I will check the paused at start issue (I didn't notice that but it might have been - the raspberry pi is in a different room from where my laptop is (nice warm kitchen!)) and set up MQTT dash and play with that. The fact that your last line works means that you must have the desktop running which will stop xinit working. i.e. you need to change your boot so you go to the command line. Even if you are logging in as a different session, the fact that there is already an X session using the display will give you that error. |
OK. the MQTT dash seems to work pretty well. I set the One thing I have found with MQTT is that it will 'remember' the status from the last time it was run, so if it closed down with paused True maybe it starts off paused. But actually, your problems sound more involved than that so probably not the culpret. I did, however notice that the, frame/delete option in PictureFrame2020.py has a bug. It checks for and copies to |
I have downloaded an Android app called MQTT Dashboard and set up all three commands (Quit, Pause, Back) and all of them work perfectly, although the pause at start issue is still there. |
I suppose the PictureFrame program could send an MQTT message to switch paused off when it starts, it does seem a bit odd though. It's probably a good idea to make the code read the message payload as well as the topic. At the moment it just toggles the paused status but it would be easy to allow a payload "off", "on" or "" where the last toggles but the other two set it to a value. Or you could have two buttons: a pause on and a pause off. Now I've done a few tries I can't get it to start with the pictureframe paused. So it's the opposite way round from you! |
I have assumed that the meat of PictureFrame2020.py, where the images are displayed and changed, is from line 349, So to confirm the 'paused' status, I inserted 'print(paused) immediately before that line. When I run the program it does display 'True' Can you think of any unintended consequences of this solution? Re. displaying the paused status, would it be possible to display the word Paused on screen in a similar way to the filename display (but only while 'paused = True') |
Hi, I can't see any where the variable paused can be set to True apart from by the MQTT server which must remember its status from a previous run. Setting paused to False just before the loop starts might not work all the time because it will depend on how quickly the MQTT server sends the message (i.e. it operates asynchronously, possibly over the internet). Maybe it would be a good idea to send MQTT messages from program at startup as mentioned before. Showing the paused status with the text/date message is a good idea. I will add that and push the modified code to the develop branch as soon as I can. |
You were half right. It wasn't the MQTT Dash that was remembering the status, It was Mosquitto. I uninstalled then reinstalled it and the paused issue is resolved. Clearly though, it was MQTT Dash that somehow caused the issue in the first place. |
I've put a modified version of PictureFrame2020 on the develop branch. It has a few changes:
In defense of MQTT Dash I think their toggle system works on the basis that payload is set to a value and held on the server. So rather than PictureFrame toggling the python value of paused it should have been looking at the payload sent by MQTT and setting it to that. There are options when setting up the behavior of the dashboard buttons that indicate that's the way they expect it to be used. |
Not strictly relevant to this thread but, can you explain why, if I start the Picture Frame from the terminal with |
Sorry, but I'm not fully au fait with github. I have found the files in the develop branch. To use these new files, is there a download option, or do I just copy and paste the code? |
It's frustrating not being able to find where that glGetError message comes from but I don't think it does any harm. I will have yet another search for it. For just a one-off use such as this it's probably easier to just copy and paste. If you want to swap from master to develop and submit pull requests etc then you need to clone the repository. The advantage of the latter is that you can go back to a working version very easily if the new changes break something on your setup... but you can achieve the same thing by saving the old version as PictureFrame2020backup.py. |
Just had a chance to try the new version. However, I get this error at start up:- |
Hi, just checking that you did use the revised PictureFrame2020config.py file as well? |
Yes |
That's odd as, presumably, your RPi is essentially set up the same way as mine. Could you open a python3 terminal and enter >>> import locale
>>> locale.LC_TIME
>>> locale.setlocale(locale.LC_TIME, "en_US.utf8") and see what you get. If that runs without an error maybe put line24 >>> locale.locale_alias and see if en_US is in there. |
OK
Re. locale.locale_alias, is there a way to present the output in columns? |
>>> for k,v in locale.locale_alias.items():
... print(k, v) |
I couldn't get that to work, however I have searched the text of ' locale.locale_alias' output, and, although there are various 'en_US.ISO*****' entries, there is no 'en_US.UTF8'. However there is 'en_US.UTF-8'. Can I assume that 'UTF8' should read 'UTF-8? |
OK, didn't realise I needed to hit return twice to get the column display. Also several variations of 'en' (eng, english), but none are UTF-8 |
OK after a quick google! I think the locales must be something set up when you first got raspbian going - they're tied up with how things are displayed on the desktop and what keys on the keyboard are where. At the command prompt I typed I will have to add something to the docs and, at the very least, put this command inside a try/except block. Thanks again for your help |
That seemed to work. I say 'seemed' only because, although the frame did, this time, start up OK it couldn't find any images. It turned out that the external drive was corrupted and then, coincidentally, there was a catastrophic crash, because the OS card was also corrupted and refused to reboot. |
OK, back working. Now, I apologize in advance if I am missing something obvious.
I had hoped that, to display the fact that the frame was actually paused, the word 'PAUSED' would appear on screen regardless of the show_text setting, and then disappear when restarted.
Firstly, what are the approprite payloads for these? If they are 'true' or 'false' (or equivalents), then isn't /date_text_on superfluous? Couldn't you just set the other 2 to 'true'? Secondly, wouldn't it be easier to have just 1 /display_text topic with 4 possible options and then use a radio button control like the /paused command? |
Hi, sorry not to keep you in t he loop. I've had other discussions with Wolfgang about options and several things have changed. Most importantly I've been persuaded that having an optional location lookup would be a nice feature. i.e. if your photos are location tagged then there is a config option to enable the lookup of info from an online service to find the text description matching the lat and lon. (the text is saved so the lookup only happens the first time). This means the --show_text config option can include 'name', 'date' and 'location' i.e. name_date or 'date location' and the MQTT messages have become /text_on /date_on /location_on and /text_off the first three toggling name, date and location the last turning them all off. However (re your last point) in order to control the length of time the text is shown for the above three options the payload is used as time in seconds. If it's empty then the time of the text is set to 1/3 of the total slide time. Also, just to make you even more bamboozled, I have made the MQTT option for frame/paused take a payload so you can specify a state by passing a payload (on, true, yes)->paused (off, false, no)->un-paused (case insensitive) This means you can have two buttons on your mqtt dashboard one to always pause and one to always start it running. I will look at the logic to make PAUSED show even when there isn't any other text - I think I did look before but can't remember what the issue was. Sorry to mess you around. Wolfgang is testing the location feature and will find any other bugs in all this stuff hopefully, then I will write something up and get it into the master branch. Thanks for your help testing as well Paddy |
Hi, I have just pushed v2.40 of pi3d and pi3d_demos to github and pypi.python.org so you should be able to use the pip3 installed version. Those uncaught characters (returned by the geo location but not in the CODEPOINTS given to the Font) are now skipped as well as fixing the fact that a shorter description sometimes left a previous longer description showing and it now searches through for printable text rather than just using parts 2,3 and last from the address. I'm not sure why PAUSED doesn't show. It's supposed to so probably not a major fix. It's certainly possible to publish MQTT topics (it already publishes |
Sorry, but I have just downloaded the latest PictureFrame2020.py and PictureFrame2020geo.py, and I still get the KeyError: 'ð' with those Iceland photos. |
Hi, the fix for the KeyError is in the code for pi3d/pi3d/util/TextBlock.py so you need to move to the latest version of pi3d for that:
In the mean time thanks for the feedback Paddy |
Thanks for all your development work, Paddy. I have just published an article explaining this new geo feature based on Pi3D: https://www.thedigitalpictureframe.com/how-to-display-the-place-where-your-photo-was-taken-with-the-raspberry-pi-digital-picture-frame-geolocation-feature/ and will update it should the code change in the coming days. |
Just tried the latest files: and I get this error: pi@raspberrypi:~ $ python3 /home/pi/pi3d_demos/PictureFrame2020.py File name is different every time (because shuffle is set to True?) |
Ah sorry about that. Still in a state of flux on the develop branch. If you use develop pi3d_demos you need to have develop branch pi3d too. Basically if you: $ cd ~/pi3d_demos
$ git checkout master All the changes apart from long line wrapping are in the master branch of pi3d_demos so that's your easiest option. On the other hand if you want to use the latest changes in the pi3d_demos develop branch (I've implemented line wrapping in the pi3d.TextBlock class so long descriptions go onto two lines) Then you will need to have the pi3d repo cloned and $ cd ~/pi3d
$ git checkout master But in order to stop this cloned repository being picked up in future I would advise you to rename it after you've stopped experimenting i.e. |
OK, thanks. The reason I went to the develop branch was that they were the most recently updated. Has, not showing PAUSED show_text is turned off been fixed in the master branch? |
I have just reverted to the (current) master branch files, but I still don't see 'PAUSED' when name,date,location off. Also, can you explain the reason for sometimes seeing 'NO IMAGES SELECTED'? It does appear to happen if I try testing MQTT commands shortly after the frame has started, but it has happened at other times when sending, I think, a subdirectory change. Sorry I can't be more specific, but it does seem to be intermittent (I know, the worst problem to diagnose!), but does appear to be MQTT related. If I just leave the frame to get on with just displaying photos (which, of course, is what it's there for) it is working OK |
Hi there are a couple of issues (I've subsequently patched and now in the develop branch, unfortunately) that Wolfgang pointed out. The 'no images' issue is due to the MQTT happening synchronously with the display loop i.e. if the current picture number changed while a picture was being loaded. The PAUSED seems to work reliably even when no other text is on, but it only remains visible for the standard show_text_tm. I have added an MQTT frame/text_refresh that will just restart the current slide and make the text re-show. There might be some additional issue with the subdirectory command. I've had a couple of 'no images' message when I wouldn't have expected them, but not reproducible and hasn't happened for the last day. So maybe it's fixed itself (hmm!) I will test the code on different computers and raspberry pis today and, hopefully, push out the new master version of pi3d_demos and pi3d (v2.41) tonight. Anyway, thanks for carrying on testing. Paddy |
Thanks. So if it's a 'timing' issue, that would certainly explain why I couldn't guarantee to reproduce the error. |
Yes, computer systems generally have moved on from the idea of a single process jogging along on its own. MQTT can change variables used in the rest of the program at any time so really there should be a comprehensive mutex system... However the whole program has evolved from a rather simple demo so is rather is much more complicated than it should be! This is why I really enjoy using Rust. I'm not sure what the best approach is for the PAUSED message. The NO IMAGES SELECTED system has it's own section (look around line 520) that doesn't reduce the alpha value of the text and logically pausing might do something similar. However I think a lot of people will want to pause the slideshow at a picture they particularly like - and not want any message showing at the bottom. The current system (I've just pushed it to pi3d_demos, pi3d master and pypi.python.org as I type this) might be a reasonable compromise (without adding a series of additional config and MQTT variables) i.e. the paused message shows when you pause it then fades but you can have an MQTT topic to refresh the status if you want to check it out. |
Sorry, but I've just tried the current files from the master branch and whenever I hit any of the MQTT text display commands, the frame stops with this error: pi@raspberrypi:~ $ python3 /home/pi/pi3d_demos/PictureFrame2020.py Also sometimes when I hit pause (strangely not always) Re. your comments on the timing of MQTT cammands I have made sure that the time_delay is sufficiently long to be sure of not sending the command at the same time as a frame change. |
Looks like you're still running with the old version of pi3d. I would try:
|
I did a fresh install to test the new Pi3D version as well as an upgrade on another Pi and my frame has been running without a glitch for 12h now. |
Sorry. I should read things more carefully. Didn't see pi3d (v2.41) in your earlier post I've now done the upgrade. However: |
That renaming was just belt and braces. If you had cloned pi3d locally it would have been picked up and caused problems. If you hadn't the the worst that could happen was a no such directory message. Is it working OK now? |
Has been working OK since my last post. |
Sorry, me again. The 'frameOff' service powers off the display and stops the frame with: This all works perfectly well. I have set the default subdirectory as "" and I then choose the subdirectory I wish to play over a period of days with an MQTT command. |
Yes, you can pass any of the config values on start i.e. sudo xinit /usr/bin/python3 /home/pi/pi3d_demos/PictureFrame2020.py --subdirectory=holiday_in_cambodia But I'm not sure how you could automate that. It would be nice if the position in the sequence was remembered and the shuffle delayed until all had been shown but if the program is stopped the whole of the file list would have to be written to disk (one of the examples on Wolfgang's blog shows how somebody did exactly that I think) It would be easy enough to save the subdirectory value to a tiny txt, json or pickle file whenever an MQTT message arrived to change it. Then the program could check that when it started, but you might need some complicated code to cope with going back to no subdirectory selected... |
OK, I have inserted these lines (in PictureFrame2020.py) after line 316, to create a text file containing the latest subdirectory MQTT message. subdirfile = open("usbdrive/subdir.txt", "w") Also, I have added a subdirectory MQTT command with no payload. this, effectively, sends an empty string, thus resetting the subdirectory parameter to "". Then, before I next start PictureFrame2020.py, I redirect the contents of subdir.txt, if it exists, or an empty string if it doesn't yet exist or has been deleted, to a variable which is then passed to PictureFrame2020.py: With some assistance from the Raspberrypi.org forum I have created a file: vcgencmd display_power 1 which is then called from my frameOn.service This all does what I wanted. One more question though. The line: ExecStart=sudo systemctl stop frameOn.service no longer works in frameOff.service. I know that I could use 'pkill' to terminate PictureFrame2020.py, but is that the best way to do it? Sorry if this is a bit rambling but it' getting late! |
Well done for getting it working, however the mechanisms of running and stopping sytemd services is pretty confusing. import subprocess
try:
with open("usbdrive/subdir.txt", "r") as f:
subdir = "--subdirectory={}".format(f.read())
except:
subdir = ""
subprocess.run(["/usr/bin/python3", "/home/pi/pi3d_demos/PictureFrame2020.py", subdir]) and make the FrameOn service start this instead or (my favourite option I think) effectively add the code to read usbdrive/subdir.txt at the bottom of PictureFrame2020config.py and just change the SUBDIRECTORY 'constant' if a) nothing has been put on the command line and b) there is something in usbdrive/subdir.txt Paddy PS I think it's good practice to always use the |
Thanks, I'll give that a go. |
Did it work OK prior to making frameOn.service start the picture frame via a bash script? (i.e. did frameOff stop python when it stopped the frameOn.service) My thinking is that you can revert to the setup that worked by altering PictureFrame2020config a little bit. You could put the snippet of code into its own file and include it to simplify the process when there are new releases of pi3d_demos. if SUBDIRECTORY == "":
try:
with open("usbdrive/subdir.txt", "r") as f:
SUBDIRECTORY = f.read()
except:
pass The only issue then is differentiating between "" as the default for no command line argument entered and "" entered to set the subdirectory to nothing. I suppose that would happen with your MQTT command. |
Sorry, but I'm not entirely sure I understand the last post. import subprocess as piccy.py, and then calling it from frameOn.service: Instead of running pictureFrame2020.py Yes, stop frameOn.service did work until I tried to make it call the external file |
Hi, Oh well, maybe there are some extra settings in systemd to allow spawned process to run other processes (though what the difference is between bash and python I don't know). What I meant by my preferred solution was to reduce the number of variations from the working system: keep frameOn.service and frameOff.service exactly as they were previous to any changes. ...
DISPLAY_Y = args.display_y
DISPLAY_W = args.display_w
DISPLAY_H = args.display_h
CODEPOINTS = '1234567890AÄÀBCÇDÈÉÊEFGHIÍJKLMNÑOÓÖPQRSTUÚÙÜVWXYZ., _-/abcdefghijklmnñopqrstuvwxyzáéèêàçíóúäöüß' # limit to 49 ie 7x7 grid_size
if SUBDIRECTORY == "":
try:
with open("usbdrive/subdir.txt", "r") as f:
SUBDIRECTORY = f.read()
except:
pass |
Now I am really confused. elif message.topic == "frame/subdirectory":
subdirectory = msg
subdirvar = open("usbdrive/subdir.txt", "w") #Write subdirectory file
subdirvar.write(subdirectory)
subdirvar.close()
reselect = True and these at the end of PictureFrame2020config.py: CODEPOINTS = '1234567890AÄÀBCÇDÈÉÊEFGHIÍJKLMNÑOÓÖPQRSTUÚÙÜVWXYZ., _-/abcdefghijklmnñopqrstuvwxyzáéèêàçíóúäöüß' # limit to 49 ie 7x7 grid_size
if SUBDIRECTORY == "": #Check subdirectory
try:
with open("usbdrive/subdir.txt", "r") as f:
SUBDIRECTORY = f.read()
except:
pass When I run the ammended frame, the MQTT commands are working - except /subdirectory. When I send a /subdirectory command, all the other commands stop working. When I stop and check subdir.txt, it has not been changed. OK, it is the 3 file writing lines that are causing the MQTT issue. If I take them out then MQTT works properly, including /subdirectory. The additional code at the end of the config file is not working however. |
I can't see anything obviously wrong with your writing to file (apart from not using the Are you running the code on boot, in which case it might be hard to get the error output - but you could do it by putting your code inside a try block like this try:
with open("usbdrive/subdir.txt", "w") as subdirvar:#Write subdirectory file
subdirvar.write(subdirectory)
except Exception as e:
with open("error_msg.txt", "w") as f:
f.write(e) PS you can define code using backticks (more explicit than just indenting) - I've edited your post so you can see how |
Many thanks. You were right again. It was the path. When I changed it to the absolute path (in both files) it worked fine. Once again thanks a million for all your help. |
Sounds good and hopefully there's info in this thread that might help future bug/solution searchers. The advantage of using the 'new' style: with open("file.txt", "w") as f:
f.read() # etc etc is that it 'automatically' has a try/catch built in (so not only does it close the file automatically but it catches errors and still closes the file. So you only need the try/catch as in my example in order to get the error message and write it to a debug log file. |
I am using PictureFrame2020. Is there any chance of adding an MQTT option to toggle display/remove filenames interactively.
Generally the photos I am displaying are travel photos and there are times when I think, 'I can't remember exactly where that is', but if I could briefly bring up the filename then I could look it up.
Normally I don't want to display filenames so I have parameter -s set to '0.0'
The text was updated successfully, but these errors were encountered: