graph temperature and humidify using gnuplot on kindle framebuffer
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 12 Mar 2017 10:28:57 +0000 (11:28 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 12 Mar 2017 10:28:57 +0000 (11:28 +0100)
pgm2fb.pl [new file with mode: 0755]
temp.gnuplot [new file with mode: 0644]
temp.sh [new file with mode: 0755]

diff --git a/pgm2fb.pl b/pgm2fb.pl
new file mode 100755 (executable)
index 0000000..561bf08
--- /dev/null
+++ b/pgm2fb.pl
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+my $path = shift @ARGV || die "usage: $0 image.pgm";
+
+my $o_x = $ENV{O_X} || 0;
+my $o_y = $ENV{O_Y} || 0;
+
+open(my $in, '<', $path) || die "$path: $!";
+
+my $magic = <$in>;
+die "wrong magic $magic" unless $magic =~ m/^P5/;
+my $size = <$in>;
+chomp $size;
+my ( $w, $h ) = split(/ /,$size);
+<$in>;
+
+my $fb;
+
+my $y = 0;
+
+seek($in, $w * $o_y, 1) if $o_y;
+
+while(my $size = read($in, my $px, $w)) {
+
+       foreach my $x ( 0 .. $w / 2 - 1 ) {
+
+               my ($a,$b);
+
+               if ( length($px) < $x * 2 + $o_x + 2 ) {
+                       print "\x00";
+               } else {        
+
+                       my ($a,$b) = unpack('CC', substr($px,$x * 2 + $o_x,2));
+                       print pack( 'C', (
+                               ( $a & 0xf0 )
+                               |
+                               ( ( $b & 0xf0 ) >> 4 )
+                       ) ^ 0xff );
+
+               }
+
+       }
+
+       $y++;
+       last if $y == $h;
+}
+
diff --git a/temp.gnuplot b/temp.gnuplot
new file mode 100644 (file)
index 0000000..a8a2006
--- /dev/null
@@ -0,0 +1,17 @@
+set terminal png size 600,250
+
+set xdata time
+set timefmt "%s"
+
+set pointsize 0.2
+
+set output '/dev/shm/1.png'
+plot "/dev/shm/temp.tsv" using 1:2 with points title "DS18B20 deg. C"
+
+set output '/dev/shm/2.png'
+plot "/dev/shm/temp.tsv" using 1:($3 > 1 ? $3 : '') with dots title "DHT22 deg. C"
+
+set output '/dev/shm/3.png'
+plot "/dev/shm/temp.tsv" using 1:($4 > 3 ? $4 : '') with dots title "DHT22 % hum"
+
+
diff --git a/temp.sh b/temp.sh
new file mode 100755 (executable)
index 0000000..ad5dcde
--- /dev/null
+++ b/temp.sh
@@ -0,0 +1,9 @@
+#!/bin/sh -x
+
+#ssh rpi 'cat `ls -t /dev/shm/vaillant.* | head -1` | sed "s/  .*| */ /"' > /dev/shm/temp.tsv
+cat `ls -t /dev/shm/vaillant.* | head -1` | sed "s/  .*| */ /" > /dev/shm/temp.tsv
+gnuplot temp.gnuplot
+montage /dev/shm/[1-3].png -tile 1x3 -geometry +0+0 /tmp/m1.png
+convert /tmp/m1.png -gravity center -extent 600x800 /tmp/m1.pgm
+#display /tmp/m1.pgm
+./pgm2fb.pl /tmp/m1.pgm | ssh root@192.168.3.100 'dd of=/dev/fb0 ; echo 2 > /proc/eink_fb/update_display'