Send Email+TXT When You Return Home (detects When IPhone Rejoins Network)

2,233

43

5

Posted in TechnologyRaspberry-pi

Introduction: Send Email+TXT When You Return Home (detects When IPhone Rejoins Network)

This project sends a daily text message and email alert when your iPhone gets close to your Wi-Fi network, such as when you return home. The alerts are limited to send only once a day and only during a user selected time window, such as 4-8 PM. The program is written in Python and introduces basic concepts for beginners learning to use the Raspberry Pi.

Video how-to for this project:

http://youtu.be/4B592qe2LWQ

Step 1: Download Raspberry Pi Code for This Project

Download the code for this project here:

https://justpaste.it/iphonescan

Step 2: Download Nmap to Your Raspberry Pi

Open a terminal window on your raspberry pi (click on lxterminal on the raspian desktop) and type this to install nmap:

sudo apt-get install nmap

Step 3: Personalize the Code for Your Email Address and Phone Number

The code clearly indicates where you need to enter the following:

1. The email address that you want alerts sent to (i.e. Where you receive alerts)

2. The email address and password of the account that you want to send alerts from

3. The phone number that you want to alerts sent to. You'll need to input the appropriate email-sms gateway for this phone number, all of which are noted in the code for major cell phone providers. For instance, you would type in 2025551212@txt.att.net to send a text message to phone number 202-555-1212 if that phone number is an AT&T subscriber.

4. The MAC address of the smartphone you carry with you. This is the phone that the program will constantly search for on your home network and will detect when you first return home.

Step 4: Run the Program!

Open IDLE on your Raspian desktop. Paste the code you just copied from justpaste.it into the blank window in IDLE and save the file (name it something like iphonescan.py)

Click on RUN and then click on RUN MODULE. You should see a new Python shell pop up and the program start to search for your iPhone.

Share

Recommendations

  • Spotless Contest

    Spotless Contest
  • Trash to Treasure

    Trash to Treasure
  • Pocket-Sized Contest

    Pocket-Sized Contest
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

5 Comments

Nice Idea

I implemented this myself...

Although I used arping -c 2 xxx.xxx.xxx.xxx >> /dev/null

Hey I really loved this tutorial but for some reason I cannot find my iPhone on the network. Do you know what might have caused this?

2 replies

Hey, thanks. There could be a few different reasons for this. Check the following:

1. Goes without saying, but double check that you typed in your iPhone's Wi-Fi MAC address correctly into the python script

2. Is your iPhone's ip address 192.168.2.(something)? If not and it's something like 192.168.1.(something) or 10.0.0.(something), then just go and edit the line of code in the python script to reflect your router's subnet:

For instance, if your iPhone's IP is 192.168.1.4, you'll need to change the nmap line in the code to this:

response = os.popen("sudo nmap -sP 192.168.1.1/24 | grep " + IphoneMac + " | awk '{print$3}' ","r").readline()

3. As I noted in the video, even if everything is working perfectly, sometimes nmap won't find my iPhone on the network if my iphone is idle and not pulling/pushing data. However, that doesn't matter for this project because when my iPhone rejoins my WiFi network, at that moment nmap is, in fact, able to find it.

A. The way I did a lot of my testing was to get the python script up and running on the RaspPI while my iPhone is in Airplane mode. You can easily simulate your arrival back to your house by getting out of airplane mode and triggering your iphone to rejoin your WiFi network, just like when you pull the driveway.

Let me know if that stuff fixes it. If you get really stuck, try messing around with nmap directly on the command line while your iPhone is pulling/pushing data to help me narrow down what the issue is.

Yea I downloaded nmap and tried testing stuff on that directly. I realized the ip address range should be in 192.168.1.xxx instead of 192.168.2.xxx. Thanks a lot it works now.

Thanks for sharing this!