User avatar
sapnho
Posts: 207
Joined: Sun Sep 14, 2014 3:49 pm
Location: Frankfurt am Main
Contact: Website

Looking for a small hardware device to trigger a python script on my RPi

Sun Mar 24, 2019 8:57 pm

I would like to have a little button to trigger a python script on a nearby device (bluetooth range). Initially, I was thinking of the Amazon Dash Button but Amazon has stopped selling them.

Would anyone have an idea of what simple battery powered device I could use?
www.TheDigitalPictureFrame.com
Build a really great digital picture frame with the Raspberry Pi.
With lots of great tips from this forum.

User avatar
rin67630
Posts: 380
Joined: Fri Mar 04, 2016 10:15 am

Re: Looking for a small hardware device to trigger a python script on my RPi

Sun Mar 24, 2019 9:39 pm

Maybe a bluetooth remote for selfies?

https://www.ebay.de/itm/Selfie-Remote-B ... 680397966

It seems to be easy to interface, it should act as a keyboard:

https://www.childs.be/blog/post/bluetoo ... on-mapping

Viel Glück, mein Freund!
Laszlo
Last edited by rin67630 on Sun Mar 24, 2019 9:46 pm, edited 2 times in total.

mattmiller
Posts: 2083
Joined: Thu Feb 05, 2015 11:25 pm

Re: Looking for a small hardware device to trigger a python script on my RPi

Sun Mar 24, 2019 9:42 pm

The amazon dash technique is just a program running that detects a device joining a LAN- it just waits for a specific MAC address to appear.

You can use something like a WEMOS D1 mini and use its reset button to make it disconnect and reconnect to your LAN and then detect it rejoining

Alternatively, you could add a little bit of electronics so that the WEMOS is off normally and pressing a button starts it up - stays on a for a few seconds - and then switch itself off again

Code for python detector (has stuff in to send MQTT message to a broker)

Code: Select all

from scapy.all import *
import paho.mqtt.client as mqtt
import time

def arp_detect(pkt):
    if pkt[ARP].op == 1: #network request
        #if pkt[ARP].hwsrc == 'b4:7c:9c:f9:1b:8e':#dash button
        #if pkt[ARP].hwsrc == '48:5a:3f:1d:79:0d': #samsung droid phone
        if pkt[ARP].hwsrc == 'dc:4f:22:1c:90:ba':#wemos 
            publish("dash","pressed")
            print time.strftime("%b %d %Y %H:%M:%S")
            return "Button detected!"
            
def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))


def publish(topic,payload):
    client.publish(topic,payload)
    print("sending: " +topic + " " + str(payload))


client = mqtt.Client()
client.on_connect = on_connect
client.connect("192.168.0.23")
client.loop_start()


try:
    print sniff(prn=arp_detect, filter="arp", store=0)
except KeyboardInterrupt:
    print
    pass

User avatar
sapnho
Posts: 207
Joined: Sun Sep 14, 2014 3:49 pm
Location: Frankfurt am Main
Contact: Website

Re: Looking for a small hardware device to trigger a python script on my RPi

Mon Mar 25, 2019 8:42 am

Thanks, Laszlo and Matt! I am looking for an off-the-shelf hardware button so I may give the Bluetooth remote a try first, I guess. I wonder if there may be a ready-made button product for the WEMOS D1 as well?
www.TheDigitalPictureFrame.com
Build a really great digital picture frame with the Raspberry Pi.
With lots of great tips from this forum.

User avatar
rin67630
Posts: 380
Joined: Fri Mar 04, 2016 10:15 am

Re: Looking for a small hardware device to trigger a python script on my RPi

Mon Mar 25, 2019 12:49 pm

sapnho wrote:
Mon Mar 25, 2019 8:42 am
Thanks, Laszlo and Matt! I am looking for an off-the-shelf hardware button so I may give the Bluetooth remote a try first, I guess. I wonder if there may be a ready-made button product for the WEMOS D1 as well?
The Wemos is an astonishing powerful device, for your need it seems overkill, albeit they are very cheap. But you need to solder and get into the guts, especially if you want to run months on battery. I don't know about ready made cases for them.

User avatar
scruss
Posts: 2360
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Looking for a small hardware device to trigger a python script on my RPi

Mon Mar 25, 2019 1:53 pm

To be honest, this is going to be quite a bit of work — unless there's a magic "launch a command on an event" tool I don't know about.

Via GPIO, you could use something like a Simple RF receiver along with a keyfob remote. These give you four different buttons. You'll need to connect the receiver via a logic level converter: they're 5 V devices. One could write a simple systemd service that ran a program to watch GPIO pins and launch something when the pin goes high. I've used one of these for a commercial installation: cheap, reliable, but no security. Someone in the same room with the same type of fob can trigger your device.

Another option is a BT selfie button. I dug out a selfie stick I was given, turned it on, associated it through the desktop BT menu, then saw the following interesting events in xev:

Code: Select all

KeyRelease event, serial 48, synthetic NO, window 0x2000001,
    root 0x25d, subw 0x0, time 331326881, (104,95), root:(950,163),
    state 0x0, keycode 123 (keysym 0x1008ff13, XF86AudioRaiseVolume), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 48, synthetic NO, window 0x2000001,
    root 0x25d, subw 0x0, time 331334771, (104,95), root:(950,163),
    state 0x0, keycode 36 (keysym 0xff0d, Return), same_screen YES,
"   XLookupString gives 1 bytes: (0d) "
"   XmbLookupString gives 1 bytes: (0d) "
    XFilterEvent returns: False

KeyRelease event, serial 48, synthetic NO, window 0x2000001,
    root 0x25d, subw 0x0, time 331334775, (104,95), root:(950,163),
    state 0x0, keycode 36 (keysym 0xff0d, Return), same_screen YES,
"   XLookupString gives 1 bytes: (0d) "
    XFilterEvent returns: False
So it seems to be sending two (three for the pedantic) keyboard events: a Return key press and release followed by a Raise Volume key release. I'm not sure if keyboard shortcuts/launchers would work for what you need.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

User avatar
sapnho
Posts: 207
Joined: Sun Sep 14, 2014 3:49 pm
Location: Frankfurt am Main
Contact: Website

Re: Looking for a small hardware device to trigger a python script on my RPi

Mon Mar 25, 2019 2:06 pm

Thanks much! I have ordered a BT camera remote button and will report on my progress! 8-)
www.TheDigitalPictureFrame.com
Build a really great digital picture frame with the Raspberry Pi.
With lots of great tips from this forum.

PhatFil
Posts: 1309
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Looking for a small hardware device to trigger a python script on my RPi

Mon Mar 25, 2019 3:12 pm

for an off the shelf solution with minimal h/w interference and simple straight forward configuration, i use 433mhz alarm/doorbell buttons of which there are lots to choose from https://www.aliexpress.com/wholesale?ca ... mhz+button to listen for all 433mhz signals it can decode i use a sonoff rf bridge reflashed with tasmota that will echo any signals it can decode as a wifi mqtt topic/payload.

node red sits alongside mosquitto mqtt broker on my pi-0-w and subscribes to the bridge/result topic and on acts on any known codes in a very simple flow.

once set up adding new buttons etc is simple, open the bridge web interface and navigate to its console window, press/activate your 433mhz device and its code will appear in the console, I then go to node-red with the code and add a new switch condition based on that code to direct flow to a node to fire up whatever is relevant.

User avatar
sapnho
Posts: 207
Joined: Sun Sep 14, 2014 3:49 pm
Location: Frankfurt am Main
Contact: Website

Re: Looking for a small hardware device to trigger a python script on my RPi

Mon Mar 25, 2019 9:27 pm

A doorbell is certainly a nice idea hardware-wise, but I am looking for a rather simple solution which does not require any additional hardware tinkering on the RPi.
www.TheDigitalPictureFrame.com
Build a really great digital picture frame with the Raspberry Pi.
With lots of great tips from this forum.

ghp
Posts: 1395
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Looking for a small hardware device to trigger a python script on my RPi

Tue Mar 26, 2019 6:00 am

Found a nice solution using esp8266. https://community.openhab.org/t/esp8266 ... tton/40770

User avatar
sapnho
Posts: 207
Joined: Sun Sep 14, 2014 3:49 pm
Location: Frankfurt am Main
Contact: Website

Re: Looking for a small hardware device to trigger a python script on my RPi

Tue Mar 26, 2019 6:54 am

Yes, that looks nice but I don't have a 3D printer! :?
www.TheDigitalPictureFrame.com
Build a really great digital picture frame with the Raspberry Pi.
With lots of great tips from this forum.

Heater
Posts: 12974
Joined: Tue Jul 17, 2012 3:02 pm

Re: Looking for a small hardware device to trigger a python script on my RPi

Tue Mar 26, 2019 8:20 am

This might be a little bit pricey but what about an Espruino Puck.js
https://shop.espruino.com/puckjs

It's a really neat, nice feeling Smart Bluetooth button, with LEDs built, runs off a coin cell for ages. It has a ton of capability that you might like to play with. Programming it is drop dead simple:

Loads of simple getting started turorials/examples here:
http://www.espruino.com/Puck.js#tutorials

User avatar
sapnho
Posts: 207
Joined: Sun Sep 14, 2014 3:49 pm
Location: Frankfurt am Main
Contact: Website

Re: Looking for a small hardware device to trigger a python script on my RPi

Tue Mar 26, 2019 9:25 am

Yes, a little pricey indeed. I am looking for something which is widely available and costs less than €10. :roll:
www.TheDigitalPictureFrame.com
Build a really great digital picture frame with the Raspberry Pi.
With lots of great tips from this forum.

martinohanlon
Posts: 11
Joined: Thu Jul 12, 2018 2:18 pm

Re: Looking for a small hardware device to trigger a python script on my RPi

Thu Apr 04, 2019 8:34 am

Have a look at BlueDot, its a Bluetooth remote and Python library.

https://bluedot.readthedocs.io/en/latest/index.html

You can use an android phone or another Raspberry Pi as the remote.

User avatar
sapnho
Posts: 207
Joined: Sun Sep 14, 2014 3:49 pm
Location: Frankfurt am Main
Contact: Website

Re: Looking for a small hardware device to trigger a python script on my RPi

Thu Apr 04, 2019 10:55 am

Also an interesting approach, thanks!
www.TheDigitalPictureFrame.com
Build a really great digital picture frame with the Raspberry Pi.
With lots of great tips from this forum.

PhatFil
Posts: 1309
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Looking for a small hardware device to trigger a python script on my RPi

Fri Apr 05, 2019 12:46 am

i still like the 433mhz botton devices, they come in 1x button to 10x buttons and more.. and have a greater range than most bluetooth devices, and all you need for wifi/mqtt translation of the codes is a £10 usb device flashed with some free firmware.. once set up adding a new code from a button or alarm device like pir or door/window sensor takes a few minutes
https://github.com/arendst/Sonoff-Tasmo ... Bridge-433

your python script needs only sit and respond to the relevant mqtt publications..
i use node red for all that tho

Return to “Python”