Simple one, this one…
We wanted to see exactly how much power we were using, and wanted to be able to display this information to staff.
First off, you need a monitoring device. I opted for the CurrentCost Envi with the optional data lead (and two more sensors as we’re on three phase!)
Next, you download the driver from the CurrentCost site. Then you plug the monitor into your USB port. In theory it’s now pumping data into COM3 at 56700 baud. Ace.
A quick check with HyperTerminal (you have to go hunting for this, it died with XP!) and sure as hell… we have some data coming in. The Envi pumps in the current readings at 6 second intervals. Cool.
Now, a teeny tiny bit of code in VB.Net gets the data into your app. With .NET 3.5 you get a nice SerialPort control. Drag one of those onto your form, and then add this code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.PortName = "COM3" SerialPort1.BaudRate = 57600 SerialPort1.Handshake = IO.Ports.Handshake.None SerialPort1.Open() End Sub Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived Dim datain As String = "" datain = SerialPort1.ReadLine() System.Diagnostics.Debug.Print(datain) End Sub
Tada!!!! You now have live electricity readings from within your app, coming in nice XML blobs like this:
<?xml version="1.0" encoding="utf-8" ?> <msg> <src>CC128-v0.12</src> <dsb>00001</dsb> <time>12:38:19</time> <tmpr>18.5</tmpr> <sensor>0</sensor> <id>00077</id> <type>1</type> <ch1> <watts>02330</watts> </ch1> </msg>
A bit of XML jiggery pokery and you have a reasonably accurate data feed of your power readings in your SQL server.
To see what I did with the data, have a look at the JAM Blog