Apex web control app with simple button UI

rxcomm

New member
I wanted a web control app for my Apex controller that would work well with my phone. The app needed to have a simple button UI, along the lines of aquanotes and Ken Argo's TankManager with the button UI. It also needed to display well on my phone. Here's a screenshot of what I came up with.

screenshot.png


The app is written in php, and you can grab a copy here.

To use the app, unzip all the files in a directory on your php-enabled web server. Edit the cred.inc.php file to add your Apex controller's login credentials and the title. Point your browser at the directory holding all the files, and you should be good to go. There is also a css file you can play with to change button, text, and background colors to your liking.

I don't use profiles, so didn't implement the profile stuff, but it could be done. :rolleyes:

No licensing on this software - I've placed it in the public domain. Hope you enjoy it!

Dave

PS: One other note - depending on the size of your phone's display, you may want to play with the meta tag to get the sizing exactly right.
 
Last edited:
I modified the script based on some suggestions by RussM to make it behave in a more friendly manner with hosting services that do not allow the execution of shell commands. Thanks Russ!

I've updated the link above with the revised script.

Dave
 
I gave it a try and get this:

"Oops! There seems to be a problem communicating with the controller."

I gave the directory and files 755 permissions.

thanks,

Mike
 
Last edited:
rinconmike -

Download a fresh copy and try again. There may have been a password issue if you use special characters in your password. I've fixed that (mea culpa!).

There are also now two ways to get the data from your Apex. The first way uses the utility wget, and the second uses a php function called file_get_contents(). Both are in the index.php file, although the second is commented out. If the default method (wget) doesn't work with your server, comment that method out and uncomment the second method. Instructions on how to do this are included in the index.php file.

If neither of these two techniques work, let me know and I can add a third.

SPotter -

php is a scripting language most commonly used to generate dynamic html pages at the server. If your web server is php-enabled, it will execute the php scripts contained in web pages and send the resulting html to the browser for rendering. In this case, when the index.php script is executed, it will query your Apex controller, and reformat the xml data it receives from the Apex into a page that displays all your outlets with the appropriate buttons for control. When you click a button, the php script will send appropriate data to your Apex to change the Outlet or Feed as requested, and then send updated html to your browser. You execute the script by simply requesting it from the browser.

HTH,

Dave
 
thanks. I tried the new one and now get "could not retrieve setData.xml"

I tried changing it and I got the oops error with the other code.

I assume the script creates the setData.xml file and it has permissions 644. I changed to 755 and 777 and same error.

thanks,

Mike
 
Is line 30 in the index.php correct with

"//$url = 'http://' . $hostname . ':' . $port . '/cgi-bin/status.xml';"

Are there too many spaces?

Line 9 of the forms files notes:

"$url = 'http://'.$username.':'.$passencode.'@'.$hostname.':'.$port.'/status.sht';"

should they be the same?
 
Those two lines are okay. It looks to me like you are having a write permissions error with setData.xml. Is the web server user the owner of the directory where the files are stored?

Dave
 
When I first upload the files, there is no setData.xml. Using the wget code, it does write the file.

I am not sure about the owner. I created the folder with my main userid.

thanks,

Mike
 
Apex users who happen to have their own web servers running is a very small target audience indeed!

:)
 
Mike - no worries. If the app writes the setData.xml file, then it is not a permission issue. I added getting the data via curl, and made it a bit easier to select which of the three methods to choose. Grab a new copy and see if the curl approach will work. Unfortunately, curl is slower than the other two.

Aquamanic and HeneryH - thanks for the notes. I wrote this with a user base of one in mind (me). I did achieve my objectives 1) to get a button app on my phone, and 2) to understand how my Apex worked. If somebody else finds it useful, that's gravy. But I do appreciate your sentiments:)

I used it last weekend to do a water change and some ancillary tank maintenance, and it worked great. Would be nice to figure out why it won't run on Mike's system though...

Dave
 
Just tried this out. Very cool. Thanks for the contribution. I've been meaning to throw together a little app and throw it on a touch screen for quick access control of my apex. This pretty much covers it.


For those of you that dont have a web server on your machines. It's only as hard as you make it ;)

You can download an app called EZPHP(http://www.easyphp.org/download.php) or similar. It contains an all-in-one package to install a php server in windows. After that, you just browse to the new folder that it made in program files. In my case, im x64 windows, so my program files path is: C:\Program Files (x86)\EasyPHP-5.3.6.0\www.

Make a folder in there called Apex (or whatever). Drop the files that rxcomm provided in that Apex folder. Follow his instructions for the rest, and your in business.

Note that EZPHP will install php on whatever port is available. In my case it installed and is listening on: http://127.0.0.1:8888/apex/

If you neglected to look at what port it is listening on, you can just right click the icon in the lower right corner(by your clock) and click "local web". You should see you "apex" directory there. Click on it and enjoy.

You can and should change your listening port from right click on ezphp, configuration, apache. look for Listen 127.0.0.1:8888 (or whatever port it defaulted to) and change it to your machines ip. Mine was Listen 127.0.0.1:8888. I changed it to Listen 192.168.2.22:8888. For some reason it doesnt work as 127.0.0.1 with default configs (it should). Now you can map it through your firewall, etc.

I attached the index.php file which is modified to use the second method. As the first method is not supported in my configuration. This is per rxcomm's instructions. I can just see the responses "when i open it to edit it, its all jibberish" responses.

thanks again!
 

Attachments

Last edited:
rxcomm. I get a variable erroron mine, and a bit too lazy to debug right now. At first glance, it looks like something to do with feed modes. Its one line 140: for($i==0; $i<=3; $i++) {

Notice: Undefined variable: i in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\apex\index.php on line 140

Notice: Undefined variable: i in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\apex\index.php on line 140

Notice: Undefined variable: i in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\apex\index.php on line 142

Notice: Undefined variable: i in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\apex\index.php on line 140

If you happen to know what that is already, great. Otherwise, when i get bored, i'll take a look. It works, so im not ina hurry :D
 
Still does not work.

Could it be with how server works regard its directories. I host my site at hostgator.com

the apex folder I created is at:

/public_html/mydomain.com/apex

or does this not make a difference?

The error "could not retrieve setData.xml using file_get_contents" does it mean it cannot get it from the apex or once it is written to the server and trying to read it?

thanks,

Mike
 
The error "could not retrieve setData.xml using file_get_contents" does it mean it cannot get it from the apex or once it is written to the server and trying to read it?
It's quite possible that hostgator does not permit file_get_contents from outside its network (cross-domain).
 
line 38 and down of the index file gives a die command if there is an error in authentication, ip or port. I suggest that you take a look at your cred.inc.php file again. Maybe you keyed in your info wrong.



if($usefile_get_contents) {
ini_set('allow_url_fopen', 'on');
$options = array('http' => array('method' => "GET", 'timeout' => 5, 'header' => "Authorization: Basic " . base64_encode("$username:$passencode")));
$url = 'http://' . $hostname . ':' . $port . '/cgi-bin/status.xml';
$context = stream_context_create($options);
file_put_contents($xmlFile, @file_get_contents($url, null, $context));
if (strpos($http_response_header[0], "200")) {
}
else {
die("could not retrieve setData.xml using file_get_contents");


edit: and what he said as well ^^
 
Rinconmike, find this code:

PHP:
file_put_contents($xmlFile, @file_get_contents($url, null, $context));
if (strpos($http_response_header[0], "200")) {
}
else {
die("could not retrieve setData.xml using file_get_contents");

Replace the last line with this:

PHP:
die($http_response_header[0]);


It will give a more specific error message.
 
Dave, you implemented one of my suggestions a bit too broadly; that rawurlencode suggestion applies only for the passwords being passed directly as part of the URL. ;) Sorry! I'll FedEx you a bottle of Excedrin if you'd like, 'cause I've probably given you a massive headache :D

Don't rawurlencode the password in the User Agent for the File_get_contents section.

PHP:
  $options = array('http' => array('method' => "GET",  'timeout' => 5, 'header' => "Authorization: Basic " .  base64_encode("$username:$passencode")));
should be:
PHP:
  $options = array('http' => array('method' => "GET", 'timeout' => 5, 'header' => "Authorization: Basic " . base64_encode("$username:$password")));
 
Back
Top