drifterf
Posts: 140
Joined: Sat Dec 08, 2018 9:09 am
Location: Northants, England

when someone connects wifi turn on a gpio

Thu Dec 05, 2019 6:02 pm

hi everyone, can anyone help with a code or where to look for the following:

when someone connects to the same wifi network as the pi it triggers a gpio pin ?

simple as that but i dont know how to lol.

thanks

hippy
Posts: 7439
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: when someone connects wifi turn on a gpio

Thu Dec 05, 2019 7:13 pm

If this relates to your 'how to tell when a delivery driver has arrived' question elsewhere; the easiest way might be to have the Pi as an Access Point, providing the WiFi network for them to connect to.

That likely makes it easier to tell when someone has connected. I have no code for doing that though.

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

Re: when someone connects wifi turn on a gpio

Thu Dec 05, 2019 10:10 pm

There used to be code on the net for a Pi to detect when an Amazon Dash button powered up and connected to a network - might be worth trying stuff like that out

User avatar
procount
Posts: 2209
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: when someone connects wifi turn on a gpio

Thu Dec 05, 2019 11:02 pm

It would help if you explained the purpose.

For example: When my wife was out with our kids, she often turned her mobile into a hotspot so they could have some internet. But she often forgot to turn it off when she got home. You can imagine what happened when the kids started watching YouTube thinking they were on the home wifi!

So I used a PiZero that constantly tries to connect to her hotspot. When it succeeds it lights some LEDs and sounds a piezo buzzer every 10 secs to remind her to turn it off. I then adapted it to monitor my hotspot as well.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

drifterf
Posts: 140
Joined: Sat Dec 08, 2018 9:09 am
Location: Northants, England

Re: when someone connects wifi turn on a gpio

Fri Dec 06, 2019 6:49 am

hi not to sure on the "when the amazon man arrives" i didnt ask a question about this ?

the idea is for a premises of ours, delivery drivers turn up in the night and we want them to be able to access the automatic gates to park inside over night.

i thought if the pi provided a wifi network the driver could connect to it. the password for the network prompt would come up on there phone (they will be told the password) and then when they connect it automatically opens the gate.

hippy
Posts: 7439
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: when someone connects wifi turn on a gpio

Fri Dec 06, 2019 8:36 am

drifterf wrote:
Fri Dec 06, 2019 6:49 am
hi not to sure on the "when the amazon man arrives" i didnt ask a question about this ?
You didn't say "amazan man" no, but you did seem to be suggesting that kind of scenario -
drifterf wrote:
Thu Dec 05, 2019 5:57 pm
i have customers turn up in the middle of the night to deliver and need to park in our yard. it would be great if the delivery driver could drive up to our gates and then goto bluetooth settings on there phone. find our bluetooth network then connect to it. this would ask for a password which we would give the drivers earlier in the day. once connected it would trigger a gpio to open the gate.
In fact you have five threads running now which all appear to be a variation on the same theme, controlling GPIO depending on presence -

https://www.raspberrypi.org/forums/view ... 2&t=258574 using WiFi
https://www.raspberrypi.org/forums/view ... 1&t=258573 using Bluetooth
https://www.raspberrypi.org/forums/view ... 2&t=258567 using Phone Call
https://www.raspberrypi.org/forums/view ... 2&t=243164 using WiFi / Bluetooth
https://www.raspberrypi.org/forums/view ... 2&t=249562 using Bluetooth

User avatar
DougieLawson
Posts: 38854
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: when someone connects wifi turn on a gpio

Fri Dec 06, 2019 8:47 am

What you need is a captive portal. When the phone/laptop connects to the captive portal then the OS will attempt to get to the connectivity test URL, when that fails your captive portal presents the "You must login here" page.

Start here: https://pimylifeup.com/raspberry-pi-captive-portal/ as that should get it running.
Which will get you to here: https://github.com/nodogsplash/nodogsplash (the code behind the portal)

The bit you want from NoDogSplash is https://github.com/nodogsplash/nodogspl ... inauth.rst
which allows your captive portal web server to run a script. The post auth script can wiggle the GPIOs needed to open doors or activate cameras, etc.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

hippy
Posts: 7439
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: when someone connects wifi turn on a gpio

Fri Dec 06, 2019 9:25 am

As long as a Pi is configured as an access point, the relevant configuration is set to direct traffic to it's local HTTP server, while iptables junks the rest, it can all be done with a few lines of Python with no need to install third-party software, software which is often intended to deliver different functionality, far more than one needs

One really wants a 'honeypot' configuration which keeps all traffic confined to the Pi, rather than a captive portal which is acting as a 'sign-in gateway' to the internet and expects to be configured for that.

drifterf
Posts: 140
Joined: Sat Dec 08, 2018 9:09 am
Location: Northants, England

Re: when someone connects wifi turn on a gpio

Tue Dec 17, 2019 6:38 pm

hippy wrote:
Fri Dec 06, 2019 9:25 am
As long as a Pi is configured as an access point, the relevant configuration is set to direct traffic to it's local HTTP server, while iptables junks the rest, it can all be done with a few lines of Python with no need to install third-party software, software which is often intended to deliver different functionality, far more than one needs

One really wants a 'honeypot' configuration which keeps all traffic confined to the Pi, rather than a captive portal which is acting as a 'sign-in gateway' to the internet and expects to be configured for that.
thanks this sounds just what we need, i shall research, thank you

epoch1970
Posts: 5018
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: when someone connects wifi turn on a gpio

Tue Dec 17, 2019 7:16 pm

If using hostapd, see hostapd_cli and its action script capability.
https://superuser.com/questions/1071354 ... stablished
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Return to “Python”