Using PHP or something else to display generated images?

Posted on
Tue Dec 31, 2013 4:52 am
MacDefender offline
Posts: 33
Joined: Oct 02, 2013
Location: Germany

Using PHP or something else to display generated images?

Is there a way to use a script that generates an image to display a device state in Indigos webserver? For example I would like to see how long ago a room was occupied using a colored background (red -> green). If motion is detected a variable is set to the timestamp. Now I would like to use this timestamp in a script to calculate how long ago the motion was detected and generate an image colored from red->yellow->green fainting away the longer ago the motion was.

Can I pass device values or variables to a script to generate an image for the web server? If not this may be a great idea to enable a lot of great control pages. If the Indigo web server don’t support php maybe it is possible to include ‚external‘ images from Apples apache installation with php enabled?

Posted on
Tue Dec 31, 2013 8:37 am
RogueProeliator offline
User avatar
Posts: 2506
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Using PHP or something else to display generated images?

If you could define a discrete set of steps for your occupancy levels you will make your life a lot easier... in that case you can build the images ahead of time and use the image heuristics to select the proper level/image based upon a variable value. Your script would simply then need to calculate and populate that value.

For instance, you could define a variable that your script will set from 0 to 100 with, say, 0 being occupied and 100 being the fully opaque time frame. You will then create a series of images corresponding to those values (would not have to create for all 100, just however many steps you want). On the control page chose to display the variable value as this image. Then your script only has to define the maximum time until "opaque" and calculate the percentage.

Should you really want to go the dynamic route, you could always setup a refreshing image on the control page and load from any accessible web server, including local apache. Your script would have to kick off the update to that image (directly or via curl or similar).

Hope that helps some...
Adam

Posted on
Thu Jan 02, 2014 10:35 am
MacDefender offline
Posts: 33
Joined: Oct 02, 2013
Location: Germany

Re: Using PHP or something else to display generated images?

I don’t see how to pass the variable values to an image(script) or images named myimgvalue_5.png

I created a variable _test and added a new element to my controlpage with show variable value as image.

But when I set this variable to several values (timestamps, integers…) it always try to find an image with +true added to the name and not my integer value or other values contained in this variable. Of cause I could create 10 images with 10 corresponding variables that are set to true for the required level but this would be a really bad option.

If my variable _test is set to 2 the control page includes this:
Code: Select all
<img src="/images/controls/variables/dot_large%2Btrue.png" alt="_test" />


Is there a way to pass the real variable value to an image/script? If not this would be my number 1 wish :idea:

Posted on
Thu Jan 02, 2014 10:53 am
RogueProeliator offline
User avatar
Posts: 2506
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Using PHP or something else to display generated images?

Yup, what you are looking for is the Image Heuristics instructions... The short of it is that you create a variable that is basically a placeholder/fallback with MyImageName+.png. Then any value that you want to have a custom image you have MyImageName+[variable value].png. For instance, I have a house mode variable that can be home, away, vacation, work. I have custom images:

HouseMode+.png
HouseMode+away.png
HouseMode+home.png
HouseMode+work.png
HouseMode+vacation.png

In the control page you select the variable (you will see the HouseMode+.png as the name/placeholder) and when displayed the proper variable will be selected. If you are using integers you don't have to have one for every possibility - it will select the closest. Take a look at that link and it explains it in more detail.

Adam

Posted on
Thu Jan 02, 2014 11:04 am
MacDefender offline
Posts: 33
Joined: Oct 02, 2013
Location: Germany

Re: Using PHP or something else to display generated images?

Thanks a lot for your help 8)
The + was missing in my base image so now I have to play around to see how to convert my timestamps into a level variable.

Maybe a future version of Indigo will be able to call a script like my image.php?value=variablevalue :roll:

Posted on
Thu Jan 02, 2014 11:47 am
RogueProeliator offline
User avatar
Posts: 2506
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Using PHP or something else to display generated images?

You can still do that... just call your script to generate the image to a web server (Apache or even Indigo's) and then on the control page put a refreshing image w/ the URL to that image. You set the refresh time and if your script has changed the image the new image will be pulled. I do something similar for iTunes art. Overall this method is a bit less responsive, though, I feel. Depending upon the usage it may not matter if it is delayed by a few seconds or whatever.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests