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!
Related
hello I work with an Rpi 4 and an Rpi Zero W and I want to activate the internet connection by a communication network using SIM7020E. I manage to establish the contact by checking the basic commands on Minicom but the connection is not activated. I must provide at the end transfer data from my Rpi by Email but without Wifi or Ethernet Cable.
i program with python
please can someone help me?
I would recommend checking out the 1NCE Developer Hub.
In the recipes section are examples of using the SIM7000G, which works very much in the same way and can be compared. You find all the recipes here: https://help.1nce.com/dev-hub/recipes and look for SIM7000G.
The main things you need to do is to configure the SIM7020E via the serial interface and send the correct commands from your python application.
Do the overall network registration of the module as shown here: https://help.1nce.com/dev-hub/recipes/sim7000g-network-registration
From there, you can already start sending data. Unfortunately, there is not a direct example for sending mail but as I expect you are using some mail delivery service that also has an API, you can follow the following guide for that: https://help.1nce.com/dev-hub/recipes/sim7000g-http-post
It will show you what commands are required for an HTTP POST call.
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....
I am trying to get an RPi3 robot to accept commands from both the Web and from a touchscreen/keyboard interface. I have a script that handles the keyboard and I am looking for that current script I have in Python to be expanded to accept real-time input from the web. As well as trying to figure out how to send the data to the script.
More detail is below but that is the basic question.
I created the robot using a raspberry pi and 3 arduinos controlling DC motors and servos to make the bot move. The program is written in Python and is run from the command line. when run it:
queries the active serial ports on the Raspberry
opens each available port
sends an integer to the receiving arduino
the arduino responds with an identifying integer so the RPI can name the port
then the script waits for user input like "Forward"
the command is translated and sent to the correct port
the robot moves
This all works perfect. Now I want to expand it. I want to keep this functionality intact and add in a web interface so I can control it from anywhere. I've tried a couple of different things with no success. I have installed apache and I am able to serve the pages with no problem, I can get the data on the page, but I can't figure out how to get the web page to send the data to the running arduino script. My issue stems from the fact that the bot control script needs to run independent of the web page. I want to still keep the same input now from the keyboard, but I also want it to accept the data from the web page. If I invoke the bot controller from the web page each time it will need to re-establish the port connections each time which takes up to 20 seconds...
I am thinking if I create a listening script I can have the website invoke the listener which will run only to receive the data from the web and pass it to the bot controller and back. But I am not sure how to do this or if this is even the best way.
I've looked at websockets, CGI/wsgi, Flask, writing a file, and JSON and I just can't seem to string it all together.
Thanks in advance and apologies if this is not in the right place or has been answered before. Also, I have not included any code as the only solid code is the bot controller. I am hoping someone with some real expertise can help me unravel this.
thanks in advance
KenV
I would say Flask is your best option. A simple example of how you could use it:
from my_robot_stuff import move_forward
#app.route('/move_forward')
def move_forward_flask():
move_forward()
return redirect('/')
Your html would then have a button that says move forward that directs to mysite.com/move_forward. flask would process it, run the code, then redirect back to the root.
I am working on a student project involving a drone which runs on the Pixhawk platform but has a 'companion computer' in the form of a Raspberry Pi. The Pi runs its own Python software and uses DroneKit (and therefore MAVLink?) to communicate with the Pixhawk via USB - giving it commands, transferring data and so on. Additionally, we have a 'ground station' laptop running ArduPilot Mission Planner which can view and interact with the aircraft remotely and also view it's telemetry. I noticed a 'Messages' tab which essentially acts like a remote console, showing 'logged' messages from the Pixhawk - this is what the question is referring to.
For debugging and information purposes, I would like to be able to add to this from Python on the Pi. I assumed this would be easily achievable through DroneKit but it does not seem trivial - send_mavlink and message_factory looked hopeful but I have found nobody else trying to do this specifically.
How can I easily redirect my 'console messages' from Python to the ground station? I realise there are alternative methods but going through the Pixhawk's existing telemetry system seems a much better option.
Thanks
One thing you can do is to create a bridge (proxy) between Pixhawk and GCS with your RPi, similar to this question.
Then in the middle of that you can send your own text messages with:
gcs_conn.mav.statustext_send(mavutil.mavlink.MAV_SEVERITY_INFO, "your message here")
Be careful not blocking too much the telemetry transmission, otherwise you could have intermittent connection to the drone from your GCS.
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.