Enviando correspondência do Beaglebone Black (Parte 9/15)

Sending Beaglebone Black Mail (Part 9/15)

This tutorial explains how to send email from Beaglebone black using the SMTP protocol. SMTP stands for Simple Mail Transfer Protocol. The main objective of this tutorial is to obtain notification by mail about certain activity. BBB will send an email with a predefined message to the registered email address when any activity occurs. Network (Internet) connectivity is required for this tutorial. You can also attach some file to the mail. The program is written in python script with SMTP library and adafruit GPIO library.

Required tools :

  • Black Beaglebone
  • push button
  • LED
  • 1 kΩ resistor
  • 330Ω resistor

Test board

  • Female to female connectors

Software environment configuration

Install the latest version of python on BBB as explained in the tutorial How to make the first python program with Beaglebone Black. The Adafruit python –GPIO library is already installed, but you can also manually install the library called adafruit_BBIO. The SMTP library is installed with python, but check it once before applying.

Working

In this tutorial, a simple alert notification is sent to a specific email ID. Before running the application, you need to establish an Internet connection with the Beaglebone black. You can choose an Ethernet connection or a WI-FI device. This tutorial uses Ethernet cable to provide Internet connection. When the button is pressed, the email is sent to a specific email ID with a predefined message. When the script is running, the program enters a continuous loop. The LED turns on when the button is pressed and turns off after the BBB email is sent.

When the email is sent, the following message appears at the command prompt:

The email has been sent

Press Ctrl+C to stop the program from running in the SSH command terminal.

Open the recipient's mailbox and check whether the message was received or not.

Captura de tela de e-mail enviado de Beaglebone Black

Fig. 1: Screenshot of correspondence sent from Beaglebone Black

Description

Let's first prepare the circuit connection. Take a breadboard and supply VCC and ground from BBB to the breadboard line. Connect 3.3V power from pin number 3 third of header P9 and ground from pin number 2 and header P8. Connect the negative terminal of the LED to ground and the positive to the 330 Ohm resistor. Connect other end of resistor to pin number 10 of header P8. The push button has two terminals. Any of them connect to the ground. Supply 3.3V to 1k ohm VCC resistor to other button terminal. Connect the common end of the resistor and the button with pin number 11 of the P8 header. Supply power to the black Beaglebone by connecting it to the PC via a USB cable. Now your circuit is prepared.

Open the command terminal and access Beaglebone black through SSH as explained in getting started with Beaglebone black. Create a new file using play command with .py extension (i.e. led.py). Open the file with any text editor (i.e. nano, vim etc.) and write code in python language.

SMTP Configuration

You can send email using SMTP over the Internet, which manages the service over the TCP/IP network. Two things are required to establish a connection to the email server:

  1. Mail server address
  2. Port number

SMTP library has built-in function to configure email sending configuration. Set the email address and port number as per the following function:

smtplib.SMTP (“smtp.gmail.com”, 587)

Here I used Gmail server with appropriate port number for sending email. The first argument is the mail server address and the second argument is the port number.

After connecting to the email server, BBB (acting as a client) identifies and establishes a secure connection by following the functions respectively.

ehlo – Enables and identifies connection to an email server

starttls – provides secure connection for data transfer

Configure the sender's email ID, password, recipient's email ID and the message you want to send to the recipient.

To = “recipient email ID”

From = “Sender Email ID”

Password = “Sender Email ID Password”

message = “Alert!!! The button is pressed”

You can write a message as per your wish.

Login to the server with specific ID and password. Send the message on the recipient's email ID and close the connection.

GPIO Configuration

I already explained the GPIO configuration in Switch interface with black Beaglebone.

Run the script in the terminal:

Enter the following command with the file name at the command prompt:

python.py file name

i.e. python sendmail.py

Project source code

###


 import smtplib
import time
import Adafruit_BBIO.GPIO as GPIO LED = "P8_10" BUTTON = "P8_11" GPIO.setup (LED, GPIO.OUT) GPIO.setup (BUTTON, GPIO.IN) GPIO.output (LED, GPIO.LOW) while True: Button_State = GPIO.input (BUTTON) if Button_State == 0: GPIO.output (LED, GPIO.HIGH) sleeptime (1) server = smtplib.SMTP("smtp.gmail.com", 587) server.ehlo server.starttls server.ehlo To = "(email protected)" From = "(email protected)" Password = "Password" message = "Alert!!! Button pressed" server.login (from, password) server.sendmail (From, To, message) server.quit print("The message was sent") GPIO.output (LED, GPIO.LOW)

###

Circuit diagrams

Circuit Diagram-Beaglebone-Black

Project video

Conteúdo Relacionado

A network of sensors is embedded in every vehicle,...
The motor controller is one of the most important...
ESP32-CAM is a compact camera module that combines the...
A evolução dos padrões USB foi fundamental para moldar...
A SCHURTER anuncia um aprimoramento para sua conhecida série...
A Sealevel Systems anuncia o lançamento da Interface Serial...
A STMicroelectronics introduziu Diodos retificadores Schottky de trincheira de...
Determinar uma localização precisa é necessário em várias indústrias...
O novo VIPerGaN50 da STMicroelectronics simplifica a construção de...
A Samsung Electronics, fornecedora de tecnologia de memória avançada,...
O mercado embarcado tem uma necessidade de soluções de...
You have probably come across the term ' drag...
You probably have a support insulator if you've noticed...
You've probably seen stand an insulator sit on power...
You've probably seen shackle insulators enthroned on electricity poles,...
You have probably experienced situations where controlling a circuit...
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.