Raspberry Pi 3 UART Communication with NEO 6mv2 Gps Module (Part B): Email Notification
Hi guys, Last tutorial, we got the data from the GPS module and did all the setup necessary to allow the PI communicate via Serial as we disabled the Mini UART and enabled the PL011 UART. For this second part of the tutorial, we will learn how to send data from the Pi to an email address and for this tutorial, we will be sending the GPS location data converted to a link, so the user can just click on the link and the location on google map pops up.
For this tutorial we will need the same components used in part A but in case you missed it, here they are.
Connect the components Listed above as shown in the Image below.
Before we jump into writing the python script to send the data to our email (Gmail for this tutorial) we have to prepare both our email and the raspberry pi for the communication.
The first thing we need to do is to setup our gmail to allow access from not too secure apps. To do that follow the steps below.
- Go to the “Less secure apps” section on the my account section
- Turn on Access for less secure apps.
If you are a G-Suite User, this settings will be hidden if your administrator has locked less secure app account access.
With our Email setup, the next thing we will need to do before moving to the code is install the pynmea2 library.
The Pynmea2 library will be used to make sense of the GPS NMEA data and extract the longitude and latitude from the data that will be dumped via the serial port by the GPS module.
To install the pynmea2 library;
1. Make sure you are at the home directory using;
2. Then run;
Sudo pip install pynmea2
This will install the pynmea2 library for use by your python Idle.
With this all done, we are ready to move to the code.
For the Last tutorial we already handled part of the code that had to do with the GPS. You can check it out here. Lets do some explanation of the code.
The first thing we do is include all the libraries needed to make the code work. The first library that was included is the time library which contains the sleep function that was used to set a kind of wait period during the code.
The next line includes the serial library which was used to communicate with the GPS module.
The next line includes the string library which enables string conversions. After string conversions, we include the pynmea2 library and the smtplib library which helps send the google map link created to an email.
With the libraries all added, the next things is for us to enter the email details.
from addr should be the email address from which it will appear the mail originated from.
pword is the password of that email address
To addr is the email address to which the location should be sent.
Most of the other part of the code have been discussed in the previous tutorial, but you can hit me up via the comment section if you have any questions.
Full code for this project is available below.
load it up on the pi and run.
you should get an output that looks like the image below in your mail box.
That’s it guys. Let me know if you have any questions.