Home

Welcome! Log in or Join us

Arduino SEG receiver

published, Oct 28, 2010 12:25pm
views (3077)

For my SEGmeter setup I have tried to use as many bits and bobs I already had in my workshop, and as there was no device ready to be flashed with OpenWRT in the cupboard, I reached for a spare arduino.

The result? An arduino, a few lengths of hookup wire, an XBee and some pin headers (2 pin and 3 pin male headers on the arduino side, and a 10 pin [2.0mm] female for the XBee).

created on: 10/28/10

3.3V and GND from the arduino connect directly to pins 1 and 10 of the XBee respectively, and digital pins 0 and 1 of the arduino connect directly to pins 2 and 3 of the XBee (again, respectively).

A quick sketch was needed on the arduino to receive the data from the XBee and write it to the USB port:

// this is where we will put our data
int myData = 0;
void setup(){
    // Start up our serial port, XBEE devices default to 9600 bps. 
    Serial.begin(9600);
}
void loop(){
    // handle serial data, if any
    if(Serial.available() > 0){
        myData = Serial.read();
        Serial.print(myData, BYTE); 
    }
}

 

Note I'm using 9600 baud, the default for the XBee. I haven't done any configuring of the XBees (they default to 9600), so if you go down this path make sure the baud rate on your SEGmeter is set to 9600 in the SEGmeter sketch.

I then have a perl script on my web server (which could be any machine you have running 24/7) to take the data received from the arduino (on /dev/ttyUSB0) and push it to SEG:

#!/usr/bin/perl

use Device::SerialPort;

# Set up the serial port
my $port = Device::SerialPort->new("/dev/ttyUSB0");
$port->databits(8);
$port->baudrate(9600);
$port->parity("none");
$port->stopbits(1);

while (1) {
    # Poll to see if any data is coming in
    my $data = $port->lookfor();

    # If we get data, upload to SEG, and print for debugging
    if ($data) {
	my $cmd = `curl -s -d "data_post=(site your_api_key $data)" http://api.smartenergygroups.com/api_sites/stream`;
        print "data: " . $data . "";
    }
}

 

Now my SEGmeter is just about ready for the fuse box.

copyright © 2008 Smart Energy Groups pty ltd