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

Acces via url for integration on other software #42

Open
dcjona opened this issue Feb 11, 2020 · 6 comments
Open

Acces via url for integration on other software #42

dcjona opened this issue Feb 11, 2020 · 6 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@dcjona
Copy link

dcjona commented Feb 11, 2020

Hi,
I would like to know if it's possible to intégrate to my automation system.
For that i need to access to the system by url e.g.
something like that : http://ipadress/green.xx
all balls will be in green
, changing also the color etc ...
do you think it's possible to make that ?
thank you very much for this awesome review of the ping pong clock

@lancewilhelm lancewilhelm self-assigned this Feb 11, 2020
@lancewilhelm lancewilhelm added the enhancement New feature or request label Feb 11, 2020
@lancewilhelm
Copy link
Owner

@dcjona, This capability may already exist within the current firmware. If you want, take a look at the code in flaskUtils.py and in script.js.

In order to change the board I utilize POST requests from the webpage (specically the javascript funtions) to the flask python server that is running. The code in flaskUtils interprets the incoming requests and does whatever function is requested (e.g. change the bg color, the text animation, the font, etc.)

You should be able to make a POST request to http://ipaddress/api/bgcolor to change the BG color for example. Look in those two files above to see how it is done and how to utilize this. I may write some documentation that explains how to use this as well in case more people want to integrate this.

@lancewilhelm lancewilhelm added the documentation Improvements or additions to documentation label Feb 11, 2020
@dcjona
Copy link
Author

dcjona commented Feb 12, 2020

thanks i will check that :)

@dcjona
Copy link
Author

dcjona commented Feb 12, 2020

i check the two file ( i'm not a programmer, so maybee harder for me to understand) could you tell me what parameter must i transmis on the url to change the color ? http://ipaddress/api/bgcolor doesn"t work like that

@lancewilhelm
Copy link
Owner

http://ipaddress/api/bgcolor doesn"t work like that

You are right it will not work when you type this directly into the URL bar. This is because when you type and address into a URL bar and hit Enter you are sending a GET HTML request to the flask server.

I pointed you to my javascript file because a lot of these functions feature POST requests.

https://www.diffen.com/difference/GET-vs-POST-HTTP-Requests

This is how I send data to my server. Probably the biggest benefit is that in flaskUtils.py I do not have to have a separate route for each color or function that I want to set. With a "POST" request you can send multiple pieces of data through the form data and parse it out on the server side. I urge you to look at those two files again.

All of this is to say, you need to find a way to send POST requests from your web page/application. This shouldn't be too hard to do as there are multiple examples of how to do this in script.js. Here is an example of what a post request looks like in the Chrome Inspector when I change the text color to Rainbow.

image

You can see that it is a post request and that it sends specific data to the server. When you load the web page it performs a GET request to receive data. If you want to manually try POST requests you can do this via a Chrome Plugin like RestMan

image

@lancewilhelm
Copy link
Owner

http://jsfiddle.net/ItsMcNugs/xq5rb7fm/5/

Here is an example of the green button from the website. You can see how each part of the web page works, the HTML, the CSS, and the JS together.

This code should work, btw, if you change your clock IP address. Keep in mind that the JSFiddle code must be loaded as http:// not https:// for this snippet to work.

@dcjona
Copy link
Author

dcjona commented Feb 16, 2020

Thanks a lot, i will search. With an api test i found the curl request ans everything work but i Can improve it will check your links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants