Aggregation of the data before uploading to PVOutput
Why do we need to aggregate the data?
The data collected by the meter reading Arduino will be sent to PVOutput on the addstatus service using the standard parameters. The hot water Arduino will be sending the data on the extended parameters (only available to donors), but you can only use the extended parameters if a v1, 2, 3 or 4 is also transmitted in the same request. Both of the Arduino’s transmit their readings at different times so in order to be able to use the extended parameters on PVOutput, the data needs to be aggregated.
The scripts and programs for aggregation
Both Arduino’s transmit their data initially to my server (called Pompeii in case you hadn’t noticed from the code). Pompeii then aggregates the data before calling PVOutput with the meter readings and additional data.
The first scripts in the chain are php scripts, simply because they were there first – however the new aggregation service can easily replace the php scripts. Their job is to add the date and time to the data received and re-post to Pompeii.
<?php $dte = date('Ymd'); $tme = date('H:i'); $url = 'http://localhost:22010/pvoutput-post-consumption'; $import = $_POST["iw"]; $export = $_POST["ew"]; $msBetweenCalls = $_POST["msBetweenCalls"]; $myvars = 'd=' . $dte . '&t=' . $tme . '&v4=' . $import . '&v9=' . $export . '&msBetweenCalls=' . $msBetweenCalls; //echo "Post Data: " . $myvars; $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_POST, 1); curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); curl_exec( $ch ); ?>
<?php $dte = date('Ymd'); $tme = date('H:i'); $url = 'http://localhost:21010/pvoutput-post-hotwater'; $temperature = $_POST["t"]; $immersion = $_POST["i"]; $myvars = 'd=' . $dte . '&t=' . $tme . '&v7=' . $temperature . '&v8=' . $immersion; //echo "Post Data: " . $myvars; $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_POST, 1); curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); curl_exec( $ch ); ?>
The next program is a Mule application which is listening on two ports. Each time it receives a message it converts it to an object and puts it on a vm queue with a correlation id of the date + time. If two messages are received with the same correlation id, the next phase is to combine the data and post the data to PVOutput and also write the data to file. The data is written to file in case I decide to write my own graphing app on top of the recorded data.
There’s also an exception strategy in case second message is never received. If the second message is not received and the first message is a Meter reading, we can still send the result to PVOutput
There are only 6 class files for the entire app – I’ll post them on the next part in order to not clutter this page
Part 6: Java Code