Skip to content
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

Overview of http commands available? #417

Open
sapnho opened this issue Nov 23, 2024 · 9 comments
Open

Overview of http commands available? #417

sapnho opened this issue Nov 23, 2024 · 9 comments

Comments

@sapnho
Copy link

sapnho commented Nov 23, 2024

Do we have a primer on HTTP commands for PictureFrame like Helge did for MQTT?

I am just playing around with a few ideas where I need to send HTTP commands to PictureFrame but somewhat my syntax isn't quite right yet.

@paddywwoof
Copy link
Collaborator

paddywwoof commented Nov 23, 2024 via email

@sapnho
Copy link
Author

sapnho commented Nov 23, 2024

I used the directory command here: https://www.thedigitalpictureframe.com/expand-your-digital-picture-frame-use-cases-with-pi3d-integrated-usb-media-stick-support/

Tried to figure out the full list with your HTTP frontend and Google Console but that only worked for a few commands. Things like next/back I couldn't figure out, pause or display on/off was easy.

@jgodfrey
Copy link
Collaborator

Hi Wolfgang,

Paddy's the expert here but until he chimes in you can always open Chrome dev tools, go to the network tab, and see what the existing HTML web page sends with each command. For example, here are a few for reference.

image

Just provide the IP address and port of your frame along with the command. So, something like this:

http://192.168.0.150:9000/?next={}

@paddywwoof
Copy link
Collaborator

paddywwoof commented Nov 23, 2024

Thanks Jeff, that's a really useful way of hacking all kinds of web accessible gadgets such as solar inverters etc etc. Chrome (or firefox) can basically give you the recipe for what you need to feed from your DIY app.

The HTTP interface gets a list of methods from the Controller object (see

elif key in dir(self.server._controller):
) .. and here's the file listing https://github.com/helgeerbe/picframe/blob/main/src/picframe/controller.py

You can then send the method name = method argument as GET arguments to the HTTP server. i.e. like Jeff says
http://192.168.0.150:9000/?next={}
The methods are listed below (true can be upper or lower case and many things that seem plausible such as true, on, yes, false, off, no):

@property setters - these don't need a dict of arguments as they can 'just' set the value

?paused=true
?subdirectory=holiday2019
?date_from=2020/09/01
?date_to=2024/12/01
?display_is_on=true
?clock_is_on=true
?shuffle=true
?fade_time=10
?time_delay=30
?brightness=0.5
?matting_images=0.0
?location_filter=eldwick
?tags_filter=birthday

non @property methods must be passed arguments as a json dict of {"key1":val1, "key2":val2...   etc}
non argument methods
?back={}
?next={}
?delete={}
?refresh_show_text={}
?purge_files={}
?get_number_of_files={}
?get_directory_list={}
?get_current_path={}

methods with arguments
?set_show_text={"txt_key":"title", "val":true} // text_key can be "title", "caption", "name", "date", "location", "folder"
?text_is_on={"txt_key":"title"}

PS I'm doing this from the file listing as I'm away from an actual picframe to test on. I will double check the actual syntax when I'm home!!!

@sapnho
Copy link
Author

sapnho commented Nov 24, 2024

Thanks, @paddywwoof and @jgodfrey !

The trick was to use the Chrome dev tools, right click on the value and say "copy as cURL". That gives the full command.
For example, I never got the next command working with ?next={}. But with ?next=\{\} it works.
Screenshot 2024-11-24 at 05 33 36

It's great to see that so many parameters can be remote controlled! I wasn't aware of that. Blog article coming up... :-)

@paddywwoof
Copy link
Collaborator

paddywwoof commented Nov 24, 2024

Hi @sapnho, it does look a little strange that you have to escape the curly brackets. How are you sending the instructions to the http server? It may be different when entering on the address bar of a browser. My list is what I would expect for python along the lines of:

from urllib import request

URL = "http://localhost:9000"
...
            request.urlopen(f"{URL}?display_is_on=OFF")
            request.urlopen(f"{URL}?brightness=0.0")
            request.urlopen(f"{URL}?next={{}}")
            request.urlopen(f"{URL}?set_show_text={{\"txt_key\":\"title\",\"val\":true}}")

I've escaped the quote marks in the last command but it should also work with f"{{URL}set_show_text={'txt_key':'title', 'val':true}}" as I think my code converts the \' characters to \" required by a json strings. As you can tell the issue of character encoding and quoting around strings is a complete nightmare in applications like this.

NB including variables in strings like this means that the { character has to be escaped as {{ following the python convention.

This is the HTML/js code for the simple web interface https://github.com/helgeerbe/picframe/blob/main/src/picframe/html/index.html

Also I might be wrong with some of this, I will check the details when I get home. So maybe hold off actually publishing your blog for a day or so!!

Paddy

@paddywwoof
Copy link
Collaborator

Hi, I've checked this out now I'm in contact with a picframe. Most of the commands work as I expected but if entering the string using f"{}" formatting you need to use double curly braces in order for them to be passed correctly.

@sapnho
Copy link
Author

sapnho commented Dec 7, 2024

@paddywwoof How would I send an HTTP command to show both date and location? I only manage to do one thing at a time.

@paddywwoof
Copy link
Collaborator

Hi, Although the parts of the text to show are controlled by a cunning bit-field system, the method that changes each bit only works one bit at a time... with the exception of turning them ALL off, which can be done by calling ViewerDisplay.set_show_text(txt_key=None) (which is the default so could be done with ViewerDisplay.set_show_text() this method should be called via HTTP by, for instance:

        request.urlopen(f"{URL}?set_show_text={{}}")

In order to turn on both date and location you would then need to send two requests:

        request.urlopen(f"{URL}?set_show_text={{\"txt_key\":\"date\",\"val\":true}}")
        request.urlopen(f"{URL}?set_show_text={{\"txt_key\":\"location\",\"val\":true}}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants