A friend of mine asked me if I can turn an Amazon dash button into a PC-Poweroff trigger. I have tried some approaches I found in internet but I didn't manage to get it to work. So I came up with my own idea. I have some old routers, compatible with OpenWRT, and I know very well how they work - so why not code myself? (or with some expert help ).
So, I'll start telling you what I've already done.
I have configured and IFTTT applet, which, already, powers off my PC when I visit a url with my browser or
curl. So the only thing left is connect the button press to the curl command in my OpenWRT.
Now, the configuration in OpenWRT is as follow:
-This router is called
-I have two interfaces:
lan is connected to my home network, subnet
192.168.1.0/24. The static IP for my
JAZZTEL_VILLEGOLAS, in the
lan side, is
192.168.1.25. The gateway is
I need connection to internet in order to do the curl command. But I need it separate from the dash button, so that it doesn't connect to amazon servers and they can disable the dash button - they don't want us to continue using these buttons.
So the other interface,
wlan, is separate from
-The local IP of the
JAZZTEL_VILLEGOLAS in the
wlan side is
192.168.2.3. The gateway is configured as
192.168.2.1 which doesn't exist, I mean, there is no host with that IP. But I imagine it is necessary to make the dash button think there's a gateway so that it tries to connect home.
lan side the DHCP server is disabled, but in the
wlan side the DHCP server is enabled.
-I think it is easier to advance if I share the
/etc/config/dhcp, so this is the content:
config dnsmasq option domainneeded '1' option boguspriv '1' option filterwin2k '0' option localise_queries '1' option rebind_protection '1' option rebind_localhost '1' option local '/lan/' option domain 'lan' option expandhosts '1' option nonegcache '0' option authoritative '1' option readethers '1' option leasefile '/tmp/dhcp.leases' option resolvfile '/tmp/resolv.conf.d/resolv.conf.auto' option nonwildcard '1' option localservice '1' option ednspacket_max '1232' config dhcp 'lan' option interface 'lan' option start '100' option limit '150' option leasetime '12h' option dhcpv4 'server' option ignore '1' config dhcp 'wan' option interface 'wan' option ignore '1' config odhcpd 'odhcpd' option maindhcp '0' option leasefile '/tmp/hosts/odhcpd' option leasetrigger '/usr/sbin/odhcpd-update' option loglevel '4' config dhcp 'wlan' option interface 'wlan' option start '100' option limit '150' option leasetime '12h' list dhcp_option '3,192.168.2.1' config host option name 'DASHBUTTON' option mac '68:37:E9:33:B5:90' option ip '192.168.2.26'
So the networking aspect is, I think, already configured and OK.
Now I'll ask you what I really don't understand.
I want to do a kind of a script, which is always executing in a loop, with the command
tcpdump, and when it detects dash button activity, it triggers the curl command. I already have the URL that curl needs to visit.
But I don't know how I can make that script. For example, I have captured the activity that happens when I press the button (connected to the
wlan). I saw the output before pressing the button, during a minute, and there's no output. But when I press the button (only once), I see some activity, and then it stops again. This is the output of the command I tried:
root@JAZZTEL_VILLEGOLAS:~# tcpdump -i wlan0 host 192.168.2.26 -U -s0 | cat tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on wlan0, link-type EN10MB (Ethernet), capture size 262144 bytes 21:17:15.962210 IP JAZZTEL_VILLEGOLAS.lan.67 > DASHBUTTON.lan.68: BOOTP/DHCP, Reply, length 300 21:17:16.207353 ARP, Request who-has JAZZTEL_VILLEGOLAS.lan tell DASHBUTTON.lan, length 28 21:17:16.207441 ARP, Request who-has JAZZTEL_VILLEGOLAS.lan tell DASHBUTTON.lan, length 28 21:17:16.207537 ARP, Reply JAZZTEL_VILLEGOLAS.lan is-at 38:72:c0:b0:f5:4d (oui Unknown), length 28 21:17:16.354042 IP DASHBUTTON.lan.57558 > JAZZTEL_VILLEGOLAS.lan.53: 57528+ A? dash-button-na.amazon.com. (43) 21:17:16.364336 IP JAZZTEL_VILLEGOLAS.lan.53 > DASHBUTTON.lan.57558: 57528 1/0/0 A 184.108.40.206 (59) 21:17:16.417819 IP DASHBUTTON.lan.57558 > JAZZTEL_VILLEGOLAS.lan.53: 57528+ A? dash-button-na.amazon.com. (43) 21:17:16.418396 IP JAZZTEL_VILLEGOLAS.lan.53 > DASHBUTTON.lan.57558: 57528 1/0/0 A 220.127.116.11 (59) 21:17:16.539424 ARP, Request who-has 192.168.2.1 tell DASHBUTTON.lan, length 28 21:17:16.539507 ARP, Request who-has 192.168.2.1 tell DASHBUTTON.lan, length 28 21:17:19.417512 ARP, Request who-has 192.168.2.1 tell DASHBUTTON.lan, length 28 21:17:19.417605 ARP, Request who-has 192.168.2.1 tell DASHBUTTON.lan, length 28 ^C18 packets captured 18 packets received by filter 0 packets dropped by kernel
So I imagine there's a way to detect any activity as the output I showed you, but I imagine too that it has to be something that only occurs once - so that it is triggered only once. But I don't have a lot of experience in shell scripting.
Can you please tell me any example I could do with this information? If you need more information, I could give you the information, please just ask. I will be reviewing this post.
Thanks in advance.