The mqtt community is pretty helpful and there's a stack of blogs and code out there that you can get your hands on, like this bit of Perl:
#!/usr/bin/perl -wThose few lines take the data from my Current Cost and publishes it with mosquitto. But, if it doesn't work, you have to know Perl to be able to work out why it doesn't work. As I mentioned in the previous post, for anyone without coding knowledge this can be a major stumbling block.
# Reads data from a Current Cost device via serial port.
# Publishes unprocessed data to mqtt
use strict;
use Device::SerialPort qw( :PARAM :STAT 0.07 );
my $pubclient = "mosquitto_pub -t sensors/cc128/raw -q 2 -s";
my $PORT = "/dev/ttyUSB0";
local $| = 1;
my $ob = Device::SerialPort->new($PORT);
$ob->baudrate(57600);
$ob->write_settings;
open(SERIAL, "+<$PORT");
while (my $line =) {
chomp $line;
open(MQTT, "|$pubclient");
print(MQTT "$line");
close(MQTT);
}
So it's important to have a goal, be it making graphs for your website, pushing weather data to your phone or having your house tell you what's going on. Have a go at some sort of plan as to how things might work before seeing if someone's done it before. Then hopefully someone will help explaining what lines like use Device::SerialPort qw( :PARAM :STAT 0.07 ); actually mean.
No comments:
Post a Comment