Running Traffic Light with Pi and Sending that info to another Pi - python

I am trying to program a raspberry pi 3 to run a traffic light on a breadboard.I also have a sensor that detects color of the traffic light, which is connected to the same raspberry pi. Can anyone help me with this? How would I do that, and also HOW can I send that detected information to another raspberry pi?
Thank you!

You can use messaging protocol like RabbitMQ, MQTT tech to make an easy communication between the raspberries.
But another Simplest way is to develop HTTP REST endpoints if you don't have stron background in messaging protocols (MQTT).
Easy way is develop HTTP REST endpoints using python flask.
Suppose you have a method in python flask as turnOnLED() bind with a URL as /on on Raspberry PI X. Now you can call this REST Endpoint using the IP of this raspberry X from another Raspberry Y.
You can similarly write a method in python to interact with **GPIO** and make that method available through your URL (ip/endpoints) to another Raspberry. From other Raspberry you can call that method by calling the URL for the first one.
Make research on RESTful APIs using Python, GPIO, PGPIOD, WiringPI, Pythong flask or any other framework to write REST Endpoints rapidly.
You need knowledge in all these buddy.

Related

Raspberry Pi as a web server security

I'm currently making a small hobby project where I use a Raspberry Pi Zero to control a set of RGB LED's.
I've got a basic python app so far that is built on Flask that allows me to set up a web server so that the LED colours can be set remotely.
My main concern is that I'm self-taught as far as programming goes and I don't know squat about security.
The plan is essentially to be sending any port 80 traffic to the raspberry pi on my home network and give friends my IP. I may eventually get a domain name to simplify things.
Should I have any security concerns when I set this up live full-time? I don't know if it's possible to access my private network via the raspberry pi or if I'm just being paranoid.
You can try putting your Raspberry PI on separate vlan and put your home devices on another vlan. Please note you need a router which supports vlan and configure it in a way that the both vlans cant talk to each other
Also, try using HTTPS for your webserver and don't run the webserver process as root user. If you want to go more crazy you can put a firewall.
These are generic suggestions for hardening the security for any web app.
If your experimenting and learning... might be a great opportunity to try out something called wire-guard, if you don't have the network equipment to support vlans.
https://engineerworkshop.com/blog/how-to-set-up-wireguard-on-a-raspberry-pi/
You and your friends can directly connect to the pi, add some appropriate iptables firewall, and you can restrict them just to that machine.
If you want learn more about secure coding, there are tons of resources. Maybe even get you and your friends 'to capture the pi' .... and learn from each other!
What ever you do , keeping hacking away, and keep having fun....

Accessing IOT raspberry pi outside of network using flask with Gunicorn

I’ve looked through this forum and couldn’t find a clear answer to helping my situation.
To explain: I’m currently trying to develop an IOT device that mainly consists of a raspberry pi 3. As it’s for a start up business idea I want to reduce costs and not have a server on the cloud.
I thought it would be a good idea to have flask run with gunicorn on the pi and this would be accessed by a desktop app or mobile app that would know the IP address of the pi as well as it’s flask endpoints.
I wanted the pi to be accessible from any other network (not just its local one). I have host on “0.0.0.0” and port 5000 for development but can’t access it through my mobile network.
I have seen similar posts mentioning ngrok (which might make data less secure?). I’ve seen that I might have to forward the port of the pi to the router. But I think this might involve accessing the router set up. And I don’t want to have to do this for every new client.
I have checked other posts on the forum but can’t seem to find what I’m looking for.
Can I ask this forum if my understanding is correct? Can anyone help me out?
Any advice would be greatly appreciated!
If I understood the problem correctly,
If you want to connect to your raspberry pi remotely you should know the IP address of your raspberry pi and need port forwarding. After that, you can connect to your raspberry pi with a public ip address. For example publicraspberrypiaddress:5555 (which port are you using)
Ngrok gives a random subdomain for connection so I don't know how you recognize the ngrok url when device is not near of you.
Alternatively, you can use cotunnel. It gives static url and the device appears on the cotunnel dashboard so you can manage your raspberry pi remotely with ssh terminal too.
Or you should develop your own tunnel-like service, or change your project structure. I don't know another way.

Making a ifttt enabled home automation system with raspberry pi

Hi everyone I am trying to make a relatively simple home automation system with ifttt and my raspberry pi model b+. My goal is to create a python script which hosts a web server which can be posted to by ifttt maker channel. The pi needs to be able to detect the post by ifttt and then run an action in my case change the color/brightness/state of an RGB LED. I have already tried use email to control actions but that was very slow and whenever wifi dropped out on my pi the script crashed so I also will need a detection system that can detect when wifi is out to prevent crashes. I am currently 11 years old (Shocker) but I need some help because currently, i am struggling to get anywhere close to my goal. Any help will be greatly appreciated.
The RPi side
There are two separate scripts you need:
1) Python script which will host a web-server.
2) Python script which can manipulate RGB data.(Guess you already have this)
On IFTTT side First of all, check out this IFTTT service called Maker Web-hooks.
Basically, IFTTT is able to hit URLs(in your case, your python web-services). So you expose an API, tell IFTTT to listen to a trigger of you choice. And upon trigger, invoke your web API. This should be very fast.
A Few Notes
1) The RPi's server needs to be accessible from the internet, not just the local wi-fi. This is because IFTTT is going to try to reach out to your RPi web-server.
2) For quick message delivery, you can evaluate MQTT. This has been explained in another answer here. The only shortfall is, you need to register(for free) for an MQTT broker service. So there's essentially an additional entity between IFTTT and your RPi.
3) Like #anjsimmo has said, exception handling is a must. You'll need to do it with any sort of code.
I'm running my personal home-automation system with the same RPi model, using MQTT. Publisher is an Android app and subscriber is the RPi. All the best with your project!

Trigger python script on raspberry pi from a rails application

I have a rails application, and when there is an update to one of the rows in my database, I want to run a python script which is on a raspberry pi (example: lights up a LED when a user is created). I'm using PostgreSQL and have looked into NOTIFY/LISTEN channels, but can't quite figure that out. Is there an easy way to do this? The raspberry pi will not be on the same network as the rails application.
There are many "easy" ways, depending on your skills.
Maybe: "Write triggers, which are sending the notify on insert/update" is the hint you need?

webrtc without a browser

Right now I am using this project here. It is a python script that runs a server using webrtc to send the clients/browsers webcam to the server and perform face recognition. What I want to do is do the same thing with a web cam or pi cam hooked up to the pi but without the use of the browser. Is there a way to do it with the current set up or is there a better method to accomplish this?
You can use the native library and connect it to the face recognition server. You can use either the google implementation of webrtc or a more recent implementation (by Ericsson) called openWebrtc. The developers of openWebRTC are very proud of running their implementation on various pieces of hardware like raspberry pi and iOS devices.
If you don't what to mess with a native library you can use a nodejs binding for webrtc (for example node-webrtc or easyrtc)
If you want a Python implementation of WebRTC, give aiortc a try. It features support for audio, video and data channels and builds upon Python's asyncio framework.
The server example illustrates both how to perform image processing on a video stream and how to send video back to the remote party. Aside from signaling there is no actual "server" or "client" role in WebRTC so you can also run aiortc on your raspberry pi and have it send video frames to whatever WebRTC endpoint you want.

Categories

Resources