Reading Exetel Usage Data With PowerShell

The de facto standard for control in house is our PLC, things mainly happen autonomously, but when things don’t happen magically the tool of choice is a smart phone running NetIO.

NetIO is a multi platform smartphone application, a generic remote controller for almost everything. It simply sends and reads strings over a network socket.

I have a NetIO server integrating with my PLC (Homevision Pro) written in TCL/TK and I write jSON code for our smart phones to leverage my PLC. This allows us to control everything the PLC has on offer. The PLC talks to everything in my house from heating and cooling, security, TCP/IP devices, power, lights, audio, and so on all in a consistent manner.

The other day I thought, wouldn’t it be great if I had a page showing all of my bills and how much I have used in real time, most places have API’s. So here goes my first example trying to read my usage data from Exetel.

 

Step 1: How Do I Talk to Exetel?
After hitting Google I am came across a page on Whirlpool that contained exactly what I needed.

https://www.exetel.com.au/members/usagemeter_xml.php?username,password’

Sounds simple enough and really it is. Putting this in your browser returns malformed XML, which isn’t great as an XML parser can’t be used but there are ways.

Step 2: Manipulating The Data
My language of choice these days is PowerShell so that is what we will write this in.

Dealing with Exetel  (and most other API’s) usually throws in a few curve-balls and here is what I found when writing my code.

  1. Malformed XML, the output is malformed and because of this I can’t use PowerShells’ built in XML parser. We will need to use regular expressions to pattern match and this is what I have done.
  2. It’s not a total, when I login to Exetel’s members page I get a total amount of data used but when I download XML I receive it split in to off-peak / peak and upload / download, we will need to combine

Step 3: My Code
My code for this solution can be found here. So after executing if you are wondering how did he get this to his PLC I have removed the function to post the results back to my PLC because unless you have exactly the same PLC I do it will be useless and cause compilation failure

ExetelData_Blog

Execution will return a variable called $TrafficTotal which will be the sum of downloads, uploads, peak and off-peak in GB that is rounded to whole integer. What you do with this is up to you

Step 4: Displaying in NetIO
The cherry on the top. My solution updates my PLC with this variable data and I use NetIO to read this and display it as a gauge. The max value on the gauge is my internet plan’s maximum consumption

NetIO_Exetel

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Shane Baldacchino

Leave a Comment