Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. pete1450
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    pete1450

    @pete1450

    3
    Reputation
    37
    Posts
    711
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online
    Location Tennessee, US

    pete1450 Follow

    Best posts made by pete1450

    • Graphing sensor data

      This is still in very early stages but I wanted to share what I've got up and running.

      I don't even have a controller yet but I've been meaning to use the nrf24l01+ for quite some time and finding this site with everything worked out gave me the push to pull them out of the parts bin. I'm a data hog who likes to have a record of everything so I figured I'd get a logging server set up for when I actually get the other sensors going(at minimum temp/PIR for every room).
      For proof-of-concept I pulled an ultrasonic sensor out and attached it to a pro mini with the distance sketch. A nano was attached to another nrf24l01+ and sent an id to the sensor so it would quit whining. At that point I could see data coming across and moved on to what this post is really about.
      The pogoplug line of devices are meant to be an easy way to make your own cloud storage by plugging a USB drive into it and then the Pogoplug into your router. Whats great is that underneath they're just an Arm processor running stripped down linux. That means they can be reloaded with other versions of linux and run as a low power server.

      The best part? You can find them for $6 on sale.

      I'm not going to go into all the detail of getting everything set up; Google can help you get the pieces working together. I'll just give the high level overview. If you get stuck, a search for 'ArchLinux thing-im-trying-to-install' will get you to a wiki page with the exact commands you need to run.

      • I went with this guide for getting ArchLinux running. Be aware that you need to find a guide specific to your pogoplug model/processor. I happene to be using the Mobile which has only one USB port so followed the directions in that guide to run the OS off a SD card.

      • I like Perl so the libraries I used in the code were Device::SerialPort, DBD:SQLite, and GD::Graph. One or two failed on install through cpanminus if I recall because of a lack of memory(Pogoplug mobile only has 128mb). Creating a swap file took care of that.

      • CGI is a quick way to make dynamic content and using a scripting language like Perl lets you just "print" whatever you want to a page. You can use things like

        <img src="/makegraph.cgi?">
        in a html page to place the output of your script(in this case your graph) there. Multiple lines would put multiple graphs on one page.

      • Database used is sqlite

      • Web server is lighttpd

      Code to grab data off the gateway and store it. This runs continuously in the background.

      use Device::SerialPort;
      use DBI;
      my $port = Device::SerialPort->new("/dev/ttyUSB0") or die $!;
      my $dbh = DBI->connect(          
      	"dbi:SQLite:dbname=/srv/http/distancetest", 
      	"",
      	"",
      	{ RaiseError => 1}
      ) or die $DBI::errstr;
       
      # 19200, 81N on the USB ftdi driver
      $port->baudrate(115200); # you may change this value
      $port->databits(8); # but not this and the two following
      $port->parity("none");
      $port->stopbits(1);
       
      #get rid of some junk data
      my $tEnd = time()+2; # 2 seconds in future
      while (time()< $tEnd) {
        my $c = $port->lookfor();
        next if $c eq "";
        last;
      }
      while (1) {
      	# Poll to see if any data is coming in
      	my $char = $port->lookfor();
       
      	# If we get data, then print it
      	if ($char) {
      		print "$char\n";
      		if($char =~ /1;1;1;0;13/){
      			@tmparr = split(/;/, $char);
      			$tmpval = $tmparr[5];
      			print "$tmpval\n";
      			if($tmpval !~ //){ #sometimes a blank value comes in
      				$dbh->do("INSERT INTO distance(distance) VALUES(" . $tmpval . ")") or die $!;
      			}
      		}
      	}
      	# Uncomment the following lines, for slower reading,
      	# but lower CPU usage, and to avoid
      	# buffer overflow due to sleep function.
       
      	# $port->lookclear;
      	# sleep (1);
      }
      

      This is the cgi script that generates the graphs. Ideally there would be fields to fill in that are passed to the script for determining ranges... later.

      #!/usr/bin/perl -w
      use CGI ':standard';
      use DBI;
      use GD::Graph::lines;
      use strict;
      #use CGI::Carp qw(fatalsToBrowser);
      
      my $dbh = DBI->connect(          
      	"dbi:SQLite:dbname=/srv/http/distancetest", 
      	"",
      	"",
      	{ RaiseError => 1}
      ) or die $!;
      
      my $sth = $dbh->prepare("SELECT * FROM distance");
      $sth->execute() or die "Cannot execute: " . $sth->errstr(  );
      
      my $row;
      my @data;
      my @out1;
      my @out2;
      
      while ($row = $sth->fetchrow_arrayref()) {
      	push(@out1, @$row[0]);
      	push(@out2, @$row[1]);
      }
      #@out1 = (1,2,3,4,5);
      #@out2 = (1,2,3,4,5);
      
      $data[0] = \@out1;
      $data[1] = \@out2;
      
      $sth->finish();
      $dbh->disconnect();
      
      my $skip = int ((@data * 50)/(600-50) + 1);
      
      my $mygraph = GD::Graph::lines->new(600, 300);
      $mygraph->set(
      	x_label     => 'Timestamp',
      	y_label     => 'cm',
      	title       => 'Distance measuted at time',
      	line_types  => [1],
      	line_width  => 2,
      	x_labels_vertical => 1,
      	x_label_skip => 10,
      	dclrs       => ['blue'],
      ) or warn $mygraph->error;
      
      $mygraph->set_legend_font(GD::gdMediumBoldFont);
      $mygraph->set_legend('sensor1');
      my $myimage = $mygraph->plot(\@data) or die $mygraph->error;
      
      print "Content-type: image/png\n\n";
      #open(OUTPUT, ">$0.png") or die "Can't open $0.png: $!\n";
      #print OUTPUT $myimage->png();
      print $myimage->png;
      

      And below is a graph from data that the sensor has reported today. The x axis needs work because that range is just a set spacing for each event; it's not representative of time.

      graphout.png

      Once I get a controller(hinted strongly to my wife for a Christmas Veralite), the nano will attach to that and I'll update all sensors to provide data in response to a request. A separate pro mini will be attached to the Pogoplug and send requests at set times for things like temperature. It will also recieve store-data requests for any commands a Vera would send to a sensor/control or new states something like a door sensor would have, I got this up in a bout a day of on and off work(when I should be wrapping Christmas presents) so anyone more linux savy should be able to knock this out quick. Anyone less: again, Google is your friend. It was a lot of copy/paste on my part anyway.

      posted in My Project
      pete1450
      pete1450
    • RE: Help understanding addressing and log messages

      Based on this: http://www.mysensors.org/build/serial_api

      Example 1
      id Node-id 0
      Child-id 0
      internal message
      no ack
      payload is type I_LOG_MESSAGE
      and your actual payload is "read: 21-20-0 s=0,c=1,t=0,pt=7,l=5:16.7"

      EDIT: I'm not sure if there is an easier place to get this, but I looked in the code for process where it prints "read" messages and found this to describe the payload. Send is also in there.

      msg.sender
      -msg.last
      -msg.destination
      s=msg.sensor
      c=mGetCommand(msg)
      t=msg.type
      pt=mGetPayloadType(msg)
      l=mGetLength(msg)
      :msg.getString(convBuf));

      posted in Hardware
      pete1450
      pete1450

    Latest posts made by pete1450

    • RE: 💬 Infrared Sender and Receiver

      @ramoncarranza When I went and looked where the library manager installed the IRremote lib(for me C:\Users\User\Documents\Arduino\libraries), it had given it an odd name like arduino_294267. I renamed it to IRremote and the issue went away.

      posted in Announcements
      pete1450
      pete1450
    • RE: [SOLVED] Raspberry Pi Gateway to Vera UI7 Not adding sensors

      @mfalkvidd I didnt realize it was a vera specific flag. By the name it sounds like something that would be needed to include sensors on any platform. If not, fair point.

      posted in Troubleshooting
      pete1450
      pete1450
    • RE: [SOLVED] Raspberry Pi Gateway to Vera UI7 Not adding sensors

      @anvil Are you kidding me! That was it. I don't have a problem fiddling with the files but I assumed the step-by-step instructions would have laid that critical step out. Or for that matter why isn't it in the source to begin with?

      posted in Troubleshooting
      pete1450
      pete1450
    • RE: [SOLVED] Raspberry Pi Gateway to Vera UI7 Not adding sensors

      @blacey
      I was using the serial gateway over a year ago with UI5. I decided to update to the new version and have tried UI5 and UI7 with both the serial-to-vera and raspi-as-ethernet gateways. Can't get the serial gateway to show up so I'm back to UI7 Ethernet trying to figure out what's getting lost in the messages. SHAs seem to match yours. I'm a little confused though. Aren't id's handed out by the controller only during inclusion? If I reboot my vera, start the gateway, and clear eeprom/upload a motion sketch, I get the output below. It looks like an id is handed out and I never touched the start button.

      root@MiOS_35029342:~# sha1sum /etc/cmh-ludl/*_Arduino*
      f9875310ea581c6384046dfd733dc5c9e436ef20  /etc/cmh-ludl/D_Arduino1.json.lzo
      e3c4493c7dff216c152b8a4d50c169acf636b1fc  /etc/cmh-ludl/D_Arduino1.xml.lzo
      8f0186c85c9a6ef6e0e8ba0755f88cbb5d326e30  /etc/cmh-ludl/D_ArduinoNode1.json.lzo
      7d66187bb75beb01606f607ad1e82a6fa6b2a552  /etc/cmh-ludl/D_ArduinoNode1.xml.lzo
      722b702937db7aedcb03346229fcc38363b2c378  /etc/cmh-ludl/D_ArduinoRelay1.json.lzo
      05ea89a8d904f436c60bd326315724e79c5c47de  /etc/cmh-ludl/D_ArduinoRelay1.xml.lzo
      ed15bfde68e6615b7615bd6230ca8040a50f5f28  /etc/cmh-ludl/I_Arduino1.xml.lzo
      2f0603b6192006f88e3582788a13a168391ceee4  /etc/cmh-ludl/L_Arduino.lua.lzo
      dc1e8a26833890f2d1f412c9b2e915724576cbd4  /etc/cmh-ludl/S_Arduino.xml.lzo
      64f886de376e2d932cd55bdf8a6367ed7a394d55  /etc/cmh-ludl/S_ArduinoNode.xml.lzo
      root@MiOS_35029342:~#
      
      mysgw: TSF:MSG:READ,255-255-0,s=255,c=3,t=3,pt=0,l=0,sg=0:
      mysgw: Client 0: 255;255;3;0;4;1
      mysgw: TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=4,pt=0,l=1,sg=0,ft=0,st=OK:1
      mysgw: Client 0:
      mysgw: TSF:MSG:READ,1-1-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
      mysgw: TSF:MSG:PINGED,ID=1,HP=1
      mysgw: TSF:MSG:SEND,0-0-1-1,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=OK:1
      mysgw: TSF:MSG:READ,1-1-0,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
      mysgw: TSF:MSG:SEND,0-0-1-1,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
      mysgw: TSF:MSG:READ,1-1-0,s=255,c=0,t=17,pt=0,l=5,sg=0:2.1.0
      mysgw: TSF:MSG:READ,1-1-0,s=255,c=3,t=6,pt=1,l=1,sg=0:0
      mysgw: TSF:MSG:READ,1-1-0,s=2,c=0,t=1,pt=0,l=0,sg=0:
      mysgw: TSF:MSG:READ,1-1-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2
      mysgw: TSF:MSG:SEND,0-0-1-1,s=255,c=3,t=27,pt=1,l=1,sg=0,ft=0,st=OK:1
      mysgw: TSF:MSG:READ,1-1-0,s=2,c=1,t=16,pt=0,l=1,sg=0:0
      mysgw: TSF:MSG:READ,1-1-0,s=2,c=1,t=16,pt=0,l=1,sg=0:0
      mysgw: TSF:MSG:READ,1-1-0,s=2,c=1,t=16,pt=0,l=1,sg=0:0
      
      
      posted in Troubleshooting
      pete1450
      pete1450
    • RE: 💬 Building a Raspberry Pi Gateway

      @marceloaqno Well that fixed the connection issue. Now I'm just back to square one where pressing start doesn't do anything. Why do I not need to specify my controllers ip? That is the ip for my veralite. Whats the use case for that option.

      posted in Announcements
      pete1450
      pete1450
    • RE: 💬 Building a Raspberry Pi Gateway

      @marceloaqno
      Ran as root and made sure I didn't have mysgw already running:

      rm -r MySensors/
      git clone https://github.com/mysensors/MySensors.git --branch master
      cd MySensors/
      ./configure --my-controller-ip-address=192.168.1.136 --my-port=5003 --my-rf24-irq-pin=15
      make
      
      
      root@raspberrypi:~/downloads/MySensors# ./bin/mysgw -d
      mysgw: Starting gateway...
      mysgw: Protocol version - 2.1.1
      mysgw: MCO:BGN:INIT GW,CP=RNNG--Q,VER=2.1.1
      mysgw: TSF:LRT:OK
      mysgw: TSM:INIT
      mysgw: TSF:WUR:MS=0
      mysgw: TSM:INIT:TSP OK
      mysgw: TSM:INIT:GW MODE
      mysgw: TSM:READY:ID=0,PAR=0,DIS=0
      mysgw: MCO:REG:NOT NEEDED
      mysgw: connect: Connection refused
      mysgw: failed to connect
      mysgw: Eth: connect
      
      posted in Announcements
      pete1450
      pete1450
    • RE: 💬 Building a Raspberry Pi Gateway

      @marceloaqno I should have specified, I'm getting the connection errors with the ethernet gateway.

      posted in Announcements
      pete1450
      pete1450
    • RE: 💬 Building a Raspberry Pi Gateway

      @lakshmc Make sure you don't have the daemon running already

      If not, I'm getting the same problem on the 2.1.1 that was just released. 2.1.0 was working "fine"(besides my suspecting a bug that doesn't let any inclusion happen, hence I tried the new version). Time to go back to the serial gateway right into the vera.

      posted in Announcements
      pete1450
      pete1450
    • RE: [SOLVED] Raspberry Pi Gateway to Vera UI7 Not adding sensors

      I've got nowhere. Unless someone happens to pop up with somewhere to look I guess I'll be going back to see if the serial gateway will work. As the problems exists after valid data already comes through I'd think the problem will still exist but who knows.

      posted in Troubleshooting
      pete1450
      pete1450
    • RE: [SOLVED] Raspberry Pi Gateway to Vera UI7 Not adding sensors

      I've tried going back to UI5 as well but no change. I'd really like to know for starters why the start button in the UI doesnt have any visible effect but aparently starts things behind the scenes.

      posted in Troubleshooting
      pete1450
      pete1450