Message1 = dict(subject='AC Alarm Alert', body='The AC alarm signal was detected.') Msg = The main body is just another attachment """The main function for sending an email using gmail""" """Get the state of the AC signal 0 is low and 1 is high""" #Make sure the alarm does not exceed 3.3V Import email # Import the email modules we'll need Import smtplib # for communicating with an email server I agree with the previous poster that you should look around the web for examples to learn the basics. This is pretty standard example, which I got off the web somewhere and did some adaptation. For the emailer function, you will need to change the email parameters for your email account. It's not tested on a "real" input signal so use at your own risk. I'm no python expert so this is the best I can do. I took a stab at some code for you to mess around with. Lastly, you need some logic to set the status of detecting the alarm (low or high, False or True) and if an email was sent (False/True). Then you need a definition for sending emails. The first is the sensor function, which simply reads the GPIO of a pin set to input. For the python code you are going to need several functions. You may need to use a level shifter on the sensor pin going into the Pi. You will need to make sure your alarm voltage is 3.3V or less. This article has been adapted with the author's permission from the original article, found here.This sounds like a great project for the Pi. With these few simple open source commands, you can integrate your own scripts, applications, and tasks with your desktop. Type 'remind' without any parameters to see syntax."Įcho "notify-send '$MESSAGE' 'Reminder' -u critical" | at $TIME 2>/dev/null Install it with your package manager of choice, for example 'sudo apt install at'."Įcho "remind: unknown command $COMMAND. If ] thenĮcho " Displays notification at specified time"Įcho ' remind "Time to wake up" in 5 minutes'Įcho "remind: AT utility is required but not installed on your system. Local Display help if no parameters or help command Reload the terminal, then type remind to see the syntax. bashrc profile so that it's loaded when you log in: $ source ~/bin/remind Save the code somewhere, for example, in the ~/bin/remind file, and source the function in your. necessary white-noise in any large application. The rest is responsible for help, parameter validation, etc., which roughly matches the proportion of useful code vs. The actual work is done in the last two lines. It defines a shell function called remind, which supports the above syntax. This is better than Alexa! How to get this goodness? Free online course: RHEL Technical Overview.For example: $ echo "notify-send 'Stop it and go home now?' 'Enough work for today.' -u critical" | at now We can combine it with notify-send to show ourselves reminders at some time in the future. From absolute time, such as 10:00 through relative time, such as now + 2 hours, to special times such as noon or midnight. Luckily, at accepts parameters from standard input so that we can use it this way: $ echo "npm run build" | at now + 1 minute If you run it like this, it starts in interactive mode, where you can enter commands to execute at a given time: $ at 12:00 The at command schedules the single execution of a command at a specified time. Combine notify-send with atĬron is commonly used to schedule commands at regular intervals. They will have the same consistent look, feel, and behavior. Sent notifications are picked up by the desktop environment and displayed just like any other notification. On top of that, URLs are rendered as clickable. You can use a small set of HTML tags in the notification body to give your messages a nice touch. You can customize the notification with options such as urgency level, custom icon, and so on. $ notify-send "Tip of the Day" "How about a nap?" On Debian-based distributions, type: $ sudo apt install notify-sendĪ few examples of simple notifications: $ notify-send "Dinner ready!" On Fedora and similar distributions, type: $ sudo dnf install libnotify If it's not installed yet, install it with your package manager of choice. It's often already installed as a part of your desktop, but you can run which notify-send to confirm. To send notifications from the Linux terminal, use the notify-send command. Sending notifications from the Linux terminal See the last section for some hints and tips. It can also be done on macOS with a bit of effort. The below code has been written and tested on Linux.
0 Comments
Leave a Reply. |