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.

No comments: