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"