Tuesday, 9 November 2010

HA7net+iButton: "Internal DS2417 is not responding" and "Short Detected on 1-wire Bus"

Got these messages when I placed an iButton (DS1990R) on a simple magnetic  probe (ML9092).

The cause? Ground and Data reversed on the probe - Ground at the edge, data in the centre.

Sunday, 31 October 2010

AJAX slow? Check DNS Lookup time

Struggling with slow response times on AJAX updates, I stumbled on 1-sec+ DNS Lookup times for each operation.Why? Turned out this was a Firefox-only problem, with sparkling performance in Chrome. So why Firefox? Turns out that the default setting is for Firefox to try an IPv6 lookup first, and then drop back to IPv4. Turning that off (good note here) made the world of difference.

Thursday, 21 October 2010

jpGraph - cannot change line colour (or color)

Using jpGraph, an excellent package for plotting graphs from database data via PHP, I hit a problem: setting
$lineplot->Setcolor("blue"); 
had no result. Nor did
$lineplot->SetWeight(2);
Eventually, I sent off an enquiry to jpGraph - and back came a very prompt reply (from the Far East):


in version 3.5.0b1, methods to change designs of each plot should be used after $graph->add($plot) method.
This is really counter-intuitive. But it works.

So it goes like this

$bplot = new BarPlot($data1y);
$graph->Add($bplot);
 
// NOW change properties of the plot - these work ONLY after calling Add()
$bplot->SetWeight(0);
$bplot->SetFillGradient('#FFAAAA:0.7', '#FFAAAA:1.2', GRAD_VER);    
 


There is a note in the documentation included as part of the package, at:


jpgraph-3.5.0b1/docs/chunkhtml/ch29s02.html

Tuesday, 19 October 2010

HA7net - writing invalid HTML

The HA7net is a neat unit - a "1-wire Ethernet Bus Master" that purports to send readings from the 1-wire devices (eg temperature sensors) in an easy-to-parse HTML table.

But with the current firmware of the day (1.0.0.22) it sends INVALID HTML (as reported by the w3c checker). I am not an expert in parsing (domDocument in php is clever but not brilliantly documented for the newcomer) and it took me a couple of hours to trace this problem. Thanks HA7 net!

The problem is that the HA7net adds a hidden element like this:



but it neglects to wrap this in "TD" tags - it sits after the last closing /TD but before the /TR on each line

For now, I have written a bit of PHP to correct it:


function mendEDSbrokenHTM($content){
    $output;
    $delimInput="
    $delimCloseTR="";
    //add
tags around each Device_Exception_Code input
    $tA=explode($delimInput,$content); //will produce n+1 elements
    $output=$tA[0];
    for ($b=1; $b
        $tB=explode($delimCloseTR,$tA[$b],2);
        $output.="".$delimInput.$tB[0]."".$delimCloseTR.$tB[1];
    }
    return $output;
}


(this isn't perfect: there will be more cells in each data row than in the header row. But it worked well enough for me).

But why should I have to muck around like this? - Easy-to-parse HTML is a key selling point on this supposedly mature system.

Not a good first encounter with the HA7net.

Windows Task Scheduler - running more often than every 5 minutes

The problem - I wanted to interrogate a network of temperature sensors every two minutes. Not too difficult to do it once, and to package that into a bat file. But how could I run the bat file every two minutes when Windows Task Scheduler offers nothing more frequent than "every 5 minutes"?

The answer - stop respecting authority (in the shape of the options provided) and get assertive. If you want to run the program every 1 minute,  type in "1 minute" into the selection box. 

And it works! at least for me (Windows 7 Pro 64-bit).

* * *

NB - to make the BAT file run invisibly without having to install Visual Basic:

Save the following line as invisible.vbs (use Notepad Save As... All Files)

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

Confirm you have Scripting installed (By typing wscript in the Start Run dialog) 

Use the following as the script to call from Task Scheduler (Replace the "MySubFolder" with your file paths)

wscript "C:\MySubfolder\invisible.vbs" "C:\MySubfolder\MyBatchFile.bat"

Thanks to kimsland at http://forums.techguy.org

Wednesday, 6 October 2010

Configuring MySQL ODBC connection

Along with obvious things like username and password, the form demands a Data Source Name. The documentation isn't explicit, and I spent a while worrying what this should be.

In fact it can be anything you like: it is just a make-it-up "name for this data source" rather than a work-out-what-it-should-be "Data Source Name"

Wednesday, 11 August 2010

Review - mySQL Ajax Table Editor

This is much more like what I need to create a user-friendly data entry/editing system for lay users.

Documentation is on the terse side (I could have used some examples) but it does look like I will be able to get it to do odd bits of post-entry/edit data manipulation.

On user-friendliness, it scores modestly well. It is very easy to specify a user-friendly title for a data item.

BUT - it doesn't cope at all with data that includes an apostrophe.

PHPmyEdit: doesn't work with WAMP?

Looks like a very comprehensive offering, but ...

Installed it under WAMP and got:

Notice: Undefined index: db in C:\webserver\Billing\phpMyEdit\phpMyEditSetup.php on line 65

Notice: Undefined index: tb in C:\webserver\Billing\phpMyEdit\phpMyEditSetup.php on line 66

Notice: Undefined variable: db in C:\webserver\Billing\phpMyEdit\phpMyEditSetup.php on line 189

Notice: Undefined variable: tb in C:\webserver\Billing\phpMyEdit\phpMyEditSetup.php on line 192

Searching suggests that others have hit this with WAMP. There also seem to be some current issues (Aug 2010) with compatability with PHP 5.

The search goes on

PHPmySQL - review of demo




Simple enough to use, but documentation is very poor: a description of each screen in the sequence. At a first look, it appeared as only the connection data can be saved: if you want to modify an existing set of pages, you have to specify your requirements from scratch again.

When you are finished, the "Generate" action copies a bunch of files to your chosen folder. Only "database.php" and "config.php" have the current date - all the others are much older, which confused me: I eventually twigged that I needed to open "index.php" to see the resulting application.

The result is competent enough, I am sure (demo does not allow use of foreign-key lookup), but very much the IT-person's data entry experience: not suitable for lay users, in my view: there didn't seem to be any option to give data fields user-friendly display names, for example.

Monday, 9 August 2010

Working with Multiple Databases under MySQL, PHP and phpMyAdmin

I couldn't find clear and concise guidance, so here is my offering (after much miserable experimentation):

Establish a Connection, eg

$glob_dbConnection = mysql_connect($db_host, $db_user , $db_pass) or die ('D5518 Error connecting to mysql');


Unless you are doing anything fancy, you don't actually need to refer to $glob_dbConnection again, as this becomes the default.

This connection then allows access to as many databases as $db_user has privileges for, so you can specify queries like this:

$sql="SELECT databaseCommon.products.*, databaseCustomer.purchases.* from databaseCommon.products INNER JOIN databaseCustomer.purchases ON ...

But setting the Privileges is a bit of a pain, and (to me) far from obvious.

In phpMyAmin, click on the link to "Server: localhost" to get at all the top-level settings.

Clicking on the Privileges link will take you to the User Overview. This allows you to Add an extra user, and lists existing users, and tells what Global Privileges each has, but it says nothing about which databases the user can access.  To fix that, click on Edit Privileges, and find the second section, which is marked "Database-specific privileges". There is a select box marked "Add privileges on the following database" - with a default of "Use text field".
Using the default, you can type in the database name, but it is safer to open the Select Box and choose the database name from there.

Having done this, press Go. The page reloads and you can now specify which actions are allowed for this user for this database (eg Select+Insert+Update but not Delete, perhaps). Tick the boxes and press Go. You may well get an error message, eg
#1141 - There is no such grant defined for user 'billinguser' on host 'localhost'
which appears to be spurious. Click on the link (eg 'billinguser'@'localhost') and it will now offer you the chance to edit Global privileges at the top of the page; further down, it lists the Database-specific privileges and you will see the specific permissions that you have added.



Good Luck

Sunday, 8 August 2010

Chrome may fire OnKeyUp event when you give focus to a SELECT box

Trying to create an select-as-you-type text box using Javascript, I wanted to open a SELECT box listing matches for text typed so far: no problem.

The challenge came when I wanted use of down-arrow from the text box to result in the first item in the select box being displayed and selected. In Chrome, setting the focus to the SELECT box was fine for an instant, but also resulted in the "onkeyup" event being fired and the focus moving away from the SELECT box. That isn't correct: onkeyup should only fire if the user has clicked on the SELECT box, and I had moved there programatically.

The solution was to use the onkeyup event to call a function that would specify thisObj.selectedIndex=0; - this brought focus back to the SELECT box. Of course, that then needed a boolean value setting in the onKeyDown so that Icould distinguish between normal and "phantom" keyup events.


... select id='monikerSelect' onkeyup='handleSelectKeyUp();'  ...


function handleSelectKeyUp(){
//CHROME triggers this immediately after passing focus.
    //We cannot stop it firing, so we need to try and make it put right what it mucks up

if (glob_selectDownHasBeenRun){
    //this is a keyup which follows a keydown: normal use
} else {
    //this is an orphan keyup that Chrome has invented for itself: THE PROBLEM CASE
    document.getElementById("monikerSelect").selectedIndex=0;
}
glob_selectDownHasBeenRun=false;
}

Wednesday, 7 July 2010

PHP and buttons

PHP correctly reports the value of a "type=submit" button in the $_POST array. But if you use a type=button button (eg because you want to validate data before deciding whether to submit) then the value of the button pressed is NOT present in the $_POST array - the button name isn't in the array at all.

Not a big deal (easy enough to set a hidden value, assuming that you use Javascript) but that didn't stop me wasting a lot of time trying to work out what I was doing wrong.

Wednesday, 12 May 2010

PHP rendering differently from View-Source HTM

One of the obvious things to do when tackling appearance problems on a PHP page is (on Firefox) to use the "Web Developer" addin's "View Generated Source" function, copy the HTM and then save it in a separate HTM file. Then remove chunks of the page to isolate the problem.

But it isn't always that simple. Today I did this, and found that IE6 rendered the PHP version badly, but the HTM version perfectly. The error turned out to be a missing close-span tag - and I suspect that the inconsistency between PHP and HTM was because Firefox had not only forgiven the missing tag, but corrected it too.

Tuesday, 13 April 2010

Smarty variables in CMSMadeSimple

Smarty (template system) within CMSMadeSimple lets you set and retrieve variables WITHIN THE HEAD of a document. But try reading that variable after the /head tag and the value has gone!

Re-assign them after the body tag,  and then you can read them elsewhere in body - but there doesn't seem to be a ready way to transmit values from head to body

Even assigning a php variable doesn't get over the problem.

Friday, 19 March 2010

When Firefox shows SELECTED values that are different from those shown in the Source

Another quirk that cost me hours:

Firefox can be "two-faced" in the way it handles SELECT (or Combo) boxes if you have errors on your page.

Try View Selection Source (or use Web Developers' View Source or Inspect Element) and the code looks perfect. And the boxes lay out nicely and show the right list of options. BUT look at which items are ACTUALLY selected, and they aren't the same ones that show with selected="selected" in the source.

Fix the errors elsewhere on the page and all works as you would expect!

Monday, 25 January 2010

Sortable.create - Sortable is Not Defined

The DragDrop capability offered by Scriptaculous is tremendous, but is not good on error messages. What does one do with the error "Sortable is Not Defined" on a "Sortable.create" statement?

The answer, from my experience, is to look hard at the coding of the page. When I have hit this problem it has normally (perhaps always) been because "echo" statements for debugging had resulted in a page source which showed the "body" tag appearing far sooner than I had intended, and that seemed to be what was spooking the Sortable.

Thursday, 21 January 2010

vertical-align - ok on td but not table (or tr or tbody)

The vertical-align css property appears to be valid only at a td level. There is a hint of this (but not explicit statment) in the w3.org documentation

Friday, 15 January 2010

Styling select options using span or strong?

Searching around, it looks as if this cannot be done in HTML with or without CSS.

To quote :
option tags do not allow other tags within them (it's not valid html).
firefox, for example, simply removes them from the DOM when it renders it. 


It's easy to style the whole option tag. What you don't seem to be able to do is to style just part of an option.


The application was a list of users within our village. Name formats will vary, and it won't always be obvious which is the right one to sort on. Eg "Newtown Tennis Club" might be known just as the "Tennis Club". The solution was to specify a separate sort name for each user, and to sort the options in that order. I wanted to highlight the sorted term in bold: cannot do. Capitalising is the best I have been able to do.


Isn't HTML a pain?