Community Articles

Find and share helpful community-sourced technical articles.
Labels (1)
Super Guru


Sometimes you want to trigger events with a click on a special touchpad or device mounted somewhere. This could be in a factory, on a door or at your desk.

For me it's a small device on my desk that I can use to trigger events. I have this running every 15 seconds looking for gestures. I could put it in an infinite loop, but Python and RPI could leak some memory. We are very constrained, so I am trying to keep it a little more minimal. I keep my batch duration to 15 seconds and my run schedule to 15 seconds.

Let's Build A Simple NiFi Flow to Receive The JSON Data and React To It


In my RouteOnContent, I just look for the word "center". I have thought of many options for running sql, doing a backup, etc..

Build The MiniFi Flow in NiFi


Downloaded minifi 0.2.0 and minifi 0.2.0 toolkit (you can use newer, but make sure you install the same version on the device you are going to move your config.yml to).

minifi-toolkit-0.2.0/bin/ transform minififlick.xml config.yml 

Then SCP that config.yml and the minifi-*.zip to your device.

Unzip (or tar-cvf it). Then you can run. This requires Java 8 JDK installed and running on your machine. The Oracle version runs best on RPI.

Let's Install and Run MiniFi

cd /opt/demo/minifi-0.2.0 
bin/ install 
bin/ start 

Example Message

{"flick": "center", "host": "herrflick", "ipaddress": "", "ts": "2017-08-14 21:19:21", "cputemp": 47.0}

The important data is flick which is the gesture made (click, tap, movement, double click, etc...) The other data is one's I always like to grab for devices (hostname, IP Address, timestamp and CPU temperature).

Since flick = center, we send a Slack message


We could do just about anything you want in the flow based on the trigger. Start backups, send system information, anything you want to trigger on demand.

or Source Code:

#!/usr/bin/env python
# -*- coding: <utf-8> -*-

# Based on
#Author: Callum Pritchard, Joachim Hummel
#Project Name: Flick 3D Gesture
#Project Description: Sending Flick 3D Gesture sensor data to mqtt
#Version Number: 0.1
#Date: 15/6/17
#Release State: Alpha testing
#Changes: Created

import time
import colorsys
import os
import json
import sys, socket
import subprocess
import time
import datetime
from time import sleep
from time import gmtime, strftime
import signal
import flicklib
import time
from curses import wrapper

some_value = 5000

flicktxt = ''

#### Initialization
# yyyy-mm-dd hh:mm:ss
currenttime= strftime("%Y-%m-%d %H:%M:%S",gmtime())

external_IP_and_port = ('', 53)  #
socket_family = socket.AF_INET

host = os.uname()[1]

def getCPUtemperature():
    res = os.popen('vcgencmd measure_temp').readline()

def IP_address():
            s = socket.socket(socket_family, socket.SOCK_DGRAM)
            answer = s.getsockname()
            return answer[0] if answer else None
        except socket.error:
            return None

def message(publisher, value):
    print value

def move(x, y, z):
    global xyztxt
    xyztxt = '{:5.3f} {:5.3f} {:5.3f}'.format(x,y,z)

def flick(start,finish):
    global flicktxt
    flicktxt = 'FLICK-' + start[0].upper() + finish[0].upper()

def spinny(delta):
    global some_value
    global airwheeltxt
    global flicktxt
    some_value += delta
    if some_value < 0:
        some_value = 0
    if some_value > 10000:
        some_value = 10000
    airwheeltxt = str(some_value/100)
    flicktxt = airwheeltxt

def doubletap(position):
    global doubletaptxt
    global flicktxt
    doubletaptxt = position
    flicktxt = doubletaptxt

def tap(position):
    global taptxt
    global flicktxt
    taptxt = position
    flicktxt = taptxt

def touch(position):
    global touchtxt
    global flicktxt
    touchtxt = position
    flicktxt = touchtxt

def main():
    global xyztxt
    global flicktxt
    global airwheeltxt
    global touchtxt
    global taptxt
    global doubletaptxt

    flickcount = 0
    airwheeltxt = ''
    airwheelcount = 0
    touchtxt = ''
    touchcount = 0
    taptxt = ''
    tapcount = 0
    doubletaptxt = ''
    doubletapcount = 0


    while flickcount < 100:
        if (flicktxt != "") :
          flickcount += 100
          ipaddress = IP_address()
          row =  { 'ts': currenttime, 'host': host, 'cputemp': round(cpuTemp,2), 'ipaddress': ipaddress, 'flick': flicktxt }
          json_string = json.dumps(row)

        flickcount += 1






Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.
Version history
Last update:
‎08-17-2019 11:37 AM
Updated by:
Top Kudoed Authors