Tuesday, August 31, 2021

Re-publish RF433 data from a weather station to MQTT with an SDR USB dongle

Thanks to a 433MHz USB dongle and some folks on the web who wrote nice tools, it is pretty easy to collect and interpret the radio data send from my 60€ Aliexpress weather station to its base station, and re-publish them on a MQTT broker.

Oh, and it runs on a sngle-board computer like a Raspberry, a Beagle Bone or an Orange PI.

We need rtl-sdr to talk to the SDR USB radio, and rtl_433 to interpret and publish it as MQTT (it even knows already about the data format for this weather station).

Friday, August 27, 2021

NGINX configuration block to run any fastcgi bash, perl, python scripts

NGINX configuration block to run fastcgi scripts by their shebangs

This configuration will use the shebang at the start of the script to select the proper interpreter.

LOCKFILE=/var/lock/$(basename $0).lock
[ -f $LOCKFILE ] && exit 0
trap "{ rc=$?; rm -f $LOCKFILE ; exit $rc; }" EXIT

''I had to be able to run bash, perl and other kinds of CGI programs but found it difficult to gather all the bits on nginx + fastcgi.

Do not forget to install ''apt install fcgiwrap'' for the generic tool, not the one for PHP.

# Bash, perl ... CGI scripts
# Make sure to allow them in this setting of /etc/php/*/fpm/pool.d/www.conf:
#    security.limit_extensions = .sh .py .pl .cgi .exe .php
location ~ ^/cgi.*(\.cgi|\.py|\.sh|\.pl)$ {
root /home/www/cgi-bin;
# Check if CGI script exists
fastcgi_split_path_info ^(.+?\.sh)(/.*)$;
try_files $fastcgi_script_name =404;
# Remove /cgi-bin/ or /cgi/ prefix in path
rewrite ^/cgi(-bin)?/(.*) /$2 break;
# Set parameters
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/www/cgi-bin$fastcgi_script_name;
# apt install fcgiwrap
fastcgi_pass unix:/var/run/fcgiwrap.socket;

Here is a minimalist example of a CGI script made with bash. Just do not forget to return proper HTTP data else you will end up with an error that tells ''upstream prematurely closed FastCGI stdout while reading response header from upstream''):

printf "HTTP/1.0 200 OK\r\n"
printf "Content-type: text/plain\r\n\r\n"

printenv | grep ^HTTP_ 

echo "Query string is $QUERY_STRING"

Monday, August 9, 2021

Open Web Analytics for Dokuwiki

Customized PHP header for Open Web Analytics best suited to dokuwiki :

if($actionkind=='') $actionkind='page';
if($actionkind=='page' || $actionkind=='search') {
        $owa = new owa_php();
//      if(@$_GET['q']!="") $owa->setSearchTerms(@$_GET['q']);
        // Set other page properties
        //$owa->setProperty('foo', 'bar');

It helps sorts the collected data and avoids logging administrative accesses. Note that I did not investigate further to make the "search terms" work Dokuwiki ''q'' argument.

Wednesday, August 4, 2021

Profile gcc code and produce a graphical tree

Obviously compile with profile, then use ''gprof'' and ''dot'':


gprof myprog.bin | gprof2dot.py -s | dot -Tpng -o profiler.png && gwenview profiler.png