Posts: 1
Joined: Tue Mar 05, 2019 2:41 pm

Controlling Raspberry Pi wirelessly

Tue Mar 05, 2019 2:47 pm

Hi, I am new to this side of technology so looking for some guidance. So I decided to make a Home Automation System with the help of Raspberry Pi. My plan is to control the GPIO pins through a webpage and also with a mobile application but I'm not sure how to make all 3 (Website, mobile app and raspberry pi) communicate wirelessly. Im sorry if I'm unable to describe my problem correctly, let me know and i'll clear it out. Thank You

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

Re: Controlling Raspberry Pi wirelessly

Tue Mar 05, 2019 6:14 pm

We know the GPIOs are on the Pi.
Where will be the HTTP server delivering the web page, where will be the wifi Access Point?

You can have everything on the Pi, but it is not mandatory.
(I'm not sure but I suspect gpiozero is a good way to make your GPIO pins available through the network if you need to.)
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Posts: 13
Joined: Tue Mar 14, 2017 3:43 am

Re: Controlling Raspberry Pi wirelessly

Wed Mar 06, 2019 1:46 am

Run a Django website on your pi using nginx and connect to your pi from your network. I would assign an ip address from your router to your pi's mac address. If you want to connect to it from your ip, create your port forwarding rules to assign port 80 or 23 to your pi.

Now you have a fully functioning web server and you just need to build out the api. Your api will access the gpio pins but remember that this system is stateless as websites are stateless. You might want to hook up a sqlite database to keep track of what pin is high and low and have a monitor running on the pi to make sure that you don't get into a bad place (like a sensor to make sure that a door doesn't close and continue to try and close). The sqlite database will be there to remember that if you tell the door to close that it is already closed and it won't try to do anything.

The reason for the database is that it can take multiple threads (unlike a file) but websites are fairly terrible solutions if you expect something to run for a period of time as the page will time out or you will hit stop. This can also easily create race conditions. Basically, log your events to your database as the first thing in a website, monitor anything that moves outside of the website, and dont change state on your pi until you hit an acceptable point.

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

Re: Controlling Raspberry Pi wirelessly

Wed Mar 06, 2019 4:23 am

Check out Mqtt for a fairly simple and powerful method to issue commands from/to any network device, you could use a cloud broker but its probably easier to just host mosquitto on a pi ;)

Return to “Beginners”