Showing posts with label awk. Show all posts
Showing posts with label awk. Show all posts

22 October, 2016

rtl_433: simple daemon and tools

Last time I wrote about simple awk script that prints the latest values collected from rtl_433 application. I was pretty much satisfied with this "quick and dirty" solution until recently, when I needed to use the data from two different projects...
Right. It is time for simple daemon solution that will collect the data in format that makes it easy to be used from different clients. And here is my code:


#!/usr/bin/awk -f
BEGIN{
  FS=","
  cmd="rtl_433 -F csv -q -p 24 2> /dev/null"

  # Get csv column labels and count
  cmd | getline; csvNF= NF;  header=$0;

  while( cmd | getline){
    if (NF==csvNF){

      if ($2=="Proove") sensor=$3+$14
      else sensor=$3$4

      fn= "/dev/shm/rtl_"sensor
      print $0 > fn; close(fn);

      if (($5!="OK") && ($5!="")) {
        fn= "/dev/shm/rtl-BAT"
        print $0 >> fn; close(fn);
      }
    }
  }
}

07 March, 2016

rtl_433: simple text monitoring panel

There is this really nice rtl_433 "application using librtlsdr to decode the temperature from a wireless temperature sensor (433.92MHz)"  https://github.com/merbanan/rtl_433 which does exactly what is says. 

I just thought that I can write a simple script that will keep showing only the latest decoded data.
As one can see in the example output, further below, some of the sensors sends the data 3 times and if you have couple of them the data starts to get a bit difficult to read. With a small awk script (tailored for my needs) I can get this simple output that contains only the interesting data and few colors to prettify it:

===================================================================================
|        Time         |               Name             |  ID  |  Temp |   %  | Bat
===================================================================================
| 2016-03-07 10:26:19 | Gym - WT450                    |   61 |   5.4 |  84% | OK
| 2016-03-07 10:26:13 | Outdoor - Nexus                |   92 |   1.5 |  90% | OK
| 2016-03-07 10:25:51 | Indoor  - WT450                |  131 |  20.1 |  27% | OK
| 2016-03-07 10:25:45 | Outdoor - WT450                |  151 |   2.0 |  94% | OK
| 2016-03-07 10:25:37 | Ventilation - Nexus            | 1281 |  17.8 |   0% | OK
===================================================================================