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

Feature: Add Rest API #3

Open
koshisan opened this issue May 29, 2021 · 2 comments
Open

Feature: Add Rest API #3

koshisan opened this issue May 29, 2021 · 2 comments

Comments

@koshisan
Copy link

I already have a rudimentary API running in my fork - however, without rest (since it is a simple display/backlight on/off through URL requests) - however, it is a start and a good test for a pull request :)

@frankcohen
Copy link
Owner

Hi Koshisan, I need some help understanding this. Do you need a REST API implemented? -Frank

@koshisan
Copy link
Author

Hi Frank,

This was originally something I intended to do. That's why I started looking into firmware alternatives for the device. The idea is to provide a better smarthome integration. In my specific case I keep my clock in the bedroom. The displays are to bright to sleep, so I want to turn them off when I start the "nightmode" for my smarthome. I also want the LED backlight to work together with other bedroom lights.

So far I added it to SmittyHalibut's version of the code, since it was quick and easy - I just had to register a webserver with some URL handlers:

API_serv.on("/display_off", api_displayOff);
API_serv.on("/display_on", api_displayOn);
API_serv.on("/backlight_off", api_backlightOff);
API_serv.on("/backlight_const", api_backlightConst);

And as for the implementation I could use his existing functions:


void api_displayOff() {
 tfts.disableAllDisplays(); 
 API_serv.send(200, "application/json", "{}");
 Serial.println("Displays off");
}
void api_displayOn() {
 tfts.enableAllDisplays(); 
 API_serv.send(200, "application/json", "{}");
}

void api_backlightOff() {
 backlights.setPattern(backlights.patterns::dark); 
 API_serv.send(200, "application/json", "{}");
}
void api_backlightConst() {
 backlights.setPattern(backlights.patterns::constant); 
 API_serv.send(200, "application/json", "{}");
}

Note that I managed to avoid actually using a JSON object until now ;) However, I will need one for the color defintion of the background light. Ideally the background light would be controlled by an object providing mode, brightness, red, green, blue...

Also the display_on/display_off URLs are a bit amateurish - it should either accept an JSON object with a "display" item that can contain a mode, or at least something like /api/display?mode=off (with "clock", "images", etc. as alternatives)

However - for this to be implemented in your fork #5 would need to be adressed first - testing isn't really fun if you have to join the device to your wifi by phone every reboot ;)

(I did some work on this, too - will update that ticket next)

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

2 participants