Maker Pro
Raspberry Pi

Bluetooth Presence Detector with Raspberry Pi and makerarena.com

October 16, 2021 by Mutlu Yağlıoğlu
Share
banner

Presence detection for bluetooth devices based on their mac addresses (no pairing is required).

Hardware

Software

1 makerarena.com

This example shows that a python code for a raspberry pi device which can ping bluetooth enabled devices in the list. If response is received from the device (smartphone), status "1" is sent to Maker Arena platform. Otherwise status "0" is sent.

makerarena.com 

Free, flexible and easy to use IoT platform for your DIY projects. It has configurable alert, filter, e-mail functions, live data graphics and more. You can monitor your sensors or control on/off relays remotely.

1- Sign Up

2- Add a project or select a project from your project list

3- Go to "Devices" page

4- Add a device and get the key

5- Get mac addresses for your bluetooth devices

6- Use your mac addresses and keys at your sketch below

Make sure your Raspberry Pi is connected to the local WiFi network at the beginning.

Add device at the Maker Arena Platform and copy "key" from the setting page. Get device (smartphone) bluetooth mac address. Replace the mac address and related key at the python code below (keyList part of the code).

In the example code, 3 devices have been used.

blog-19-950x400.jpg
import time
import subprocess
import requests
import json


keyList = {
    'D0:87:E2:0B:89:E2':'c8g98Ccfx06XeouqMDwNlMJDGp48pPST',
    '39:C0:1B:C9:CF:23':'PTtf7Wu1xZCNWPL4mU4gTm5D1nLWriDC',
    '40:83:1D:46:61:72':'EI9cHLGMa8L7LgFH1EIDGhGFhc9XqeER'
}


def post (key,data):
    url='http://makerarena.com/api/insertpost.php'
    msg = json.dumps({"k":key,"d":data})
    print(msg)
    try:
        postdata = requests.post(url, data = {'apipost': msg})
    except:
        print("Post exception!")


while 1:
    try:
        for addr,key in keyList.items():
        pingout = subprocess.run(["sudo","l2ping","-c","3",addr],capture_output=True)
        rc = pingout.returncode
        if rc == 0:
            post(key,"1")
        else:
            post(key,"0")
    except:
        print("Ping exception!")
    time.sleep(10)

This example is created with Python and tested with Raspberry Pi 4. 

For more details please visit makerarena.com

Related Content

Categories



You May Also Like