How To Track All Devices with Raspberry Pi - Raspberry Pi Projects, Tutorials, Learning DIY Electronics - Makergenix

Breaking

 


How To Track All Devices with Raspberry Pi

 Using a Raspberry Pi, you can track your phone, tablet, laptop, and other wireless devices.

How To Track All Devices with Raspberry Pi

Using a Raspberry Pi, keep track of your phone, tablet, laptop, and other wireless devices! The more Raspberry Pis you have, the better you'll be able to monitor your house for gadget movement. Send the data from all the Pi's to an IoT platform to record and visualise your home as well as the positions of all your wireless gadgets!

Raspberry Pi HAT's & Shields

Make sure you're at the source of the problem.

    $ sudo su

    Make a directory switch.

      $ cd /usr/local/src

      Download the most recent Re4son kernel version.

        $ wget  -O re4son-kernel_current.tar.xz https://re4son-kernel.com/download/re4son-kernel-current/

        To extract the file, use the tar command.

          $ tar -xJf re4son-kernel_current.tar.xz

          Rename the folders

            $ cd re4son-kernel_4*

            Install the firmware.

            $ ./install.sh

            Step 2: Examine Monitor Mode:

            • Make sure you're in root once more.
            $ sudo iw phy phy0 interface add mon0 type monitor

              Create an interface for monitor mode.

                $ iw dev

                Make sure the interface exists.

                $ ifconfig mon0 up

                Step 3: Install the most recent scapy version:

                • Clone the scapy repository into a new folder.

                  $ git clone https://github.com/secdev/scapy.git

                  Rename the directory

                    $ cd scapy

                    Setup the setup.py script.

                    $ sudo python3 setup.py install
                    After you've performed these three steps, you should be able to run the code without issue!

                    First, we must import all of the required libraries.

                    from scapy.all import *
                    import json
                    import threading
                    import http.client
                    After that, you'll need to enter your uBeac Gateway URL, which we'll go over later. Set the interval for how often you want your device to deliver data and give it a nice name.
                    UBEAC_URL = 'hub.ubeac.io'
                    GATEWAY_URL = 'http://INSERT GATEWAY URL HERE'
                    DEVICE_FRIENDLY_NAME = 'RPi detector 4'
                    SENT_INTERVAL = 10 # Sent data interval in second

                    You'll need to know the MAC address of your own devices in order to track them. In the devices dictionary, type them in.

                    devices = {"00:00:00:00:00:00" : "DEVICE 1",
                    "00:00:00:00:00:00" : "DEVICE 2",
                    "00:00:00:00:00:00" : "DEVICE 3"}
                    Data is written to the uBeac sensor format using the get sensor function.
                    def get_sensor(id, value, type=None, unit=None, prefix=None, dt=None):
                    sensor = {
                    'id': id,
                    'data': value
                    }
                    return sensor
                    The PacketHandler function keeps track of the Wi-Fi packets that your wireless devices send out.
                    def PacketHandler(pkt):
                    if pkt.haslayer(Dot11):
                    dot11_layer = pkt.getlayer(Dot11)
                    if dot11_layer.addr2 and (dot11_layer.addr2 in devices) and (dot11_layer.addr2 not in check_devices):
                    check_devices.add(dot11_layer.addr2)
                    sensors_dbm.append(get_sensor(devices[dot11_layer.addr2], {"dBm Signal" : pkt[RadioTap].dBm_AntSignal}))
                    The main method delivers the data from the PacketHandler to uBeac's IoT service. It will reset every 10 seconds by default, but you may modify this.
                    def main():
                    threading.Timer(SENT_INTERVAL, main).start()
                    sniff(iface = "mon0", prn = PacketHandler, timeout = SENT_INTERVAL)
                    device = [{
                    'id': DEVICE_FRIENDLY_NAME,
                    'sensors': sensors_dbm
                    }]
                    connection = http.client.HTTPSConnection(UBEAC_URL)
                    connection.request('POST', GATEWAY_URL, json.dumps(device))
                    response = connection.getresponse()
                    print(response.read().decode())
                    sensors_dbm.clear()
                    check_devices.clear()

                    Configure uBeac

                    Simply follow this lesson on OS monitoring for an introduction to uBeac. You'll learn how to acquire your uBeac Gateway URL, check sure your devices are providing data, and create a dashboard in this lesson!

                    Raspberry Pi Pico hat's & expansions

                    To receive the floor plan with the devices laid out on it, go to the Buildings module and build a Building by typing in an address, selecting it on a map, and giving it a name. After that, you must construct a floor for your structure. To access the Floor modules and build a new floor, select the Floor tab. Insert a floor plan, whether it's your own or one you found on the internet.

                    Go to the Devices module, choose your individual device, and select settings to add it to the floor layout. Select your building and floor from the buildings tab. Drag your device to the appropriate location on the floor layout. Once you've made changes to your device's icon picture, size, and colour, click submit.

                    You should see all of your new devices and their data if you go to the Dashboard module, create a dashboard, and enter the floor widget! An example of such a dashboard is shown below.

                    Note that signal strength, which is a negative value, is used to calculate the distance between the RaspberryPi and the wireless device. As a result, the closer an item is, the narrower the bar on the bar graph.

                    Create a free uBeac account here.

                    Code

                    from scapy.all import *
                    import json
                    import threading
                    import http.client
                    
                    # Configuration section
                    UBEAC_URL = 'hub.ubeac.io'
                    GATEWAY_URL = 'http://INSERT GATEWAY URL HERE'
                    DEVICE_FRIENDLY_NAME = 'RPi detector #'
                    SENT_INTERVAL = 10 # Sent data interval in second
                    
                    sensors_dbm = []
                    
                    check_devices = set()
                    devices = {"00:00:00:00:00:00" : "DEVICE",
                                "00:00:00:00:00:00" : "DEVICE",
                                "00:00:00:00:00:00" : "DEVICE"}
                                
                    def get_sensor(id, value, type=None, unit=None, prefix=None, dt=None):
                        sensor = {
                            'id': id,
                            'data': value
                        }
                        return sensor
                    
                    def PacketHandler(pkt):
                        if pkt.haslayer(Dot11):
                            dot11_layer = pkt.getlayer(Dot11)
                            if dot11_layer.addr2 and (dot11_layer.addr2 in devices) and (dot11_layer.addr2 not in check_devices):
                                check_devices.add(dot11_layer.addr2)
                                sensors_dbm.append(get_sensor(devices[dot11_layer.addr2], {"dBm Signal" : pkt[RadioTap].dBm_AntSignal}))
                                    
                    def main():
                        threading.Timer(SENT_INTERVAL, main).start()
                        sniff(iface = "mon0", prn = PacketHandler, timeout = SENT_INTERVAL)
                        device = [{
                            'id': DEVICE_FRIENDLY_NAME,
                            'sensors': sensors_dbm
                        }]
                        connection = http.client.HTTPSConnection(UBEAC_URL)
                        connection.request('POST', GATEWAY_URL, json.dumps(device))
                        response = connection.getresponse()
                        print(response.read().decode())
                        sensors_dbm.clear()
                        check_devices.clear()
                    
                    main()
                    

                    Posts You May like

                     


                    Most Viewed Posts

                    Write For Us

                    Name

                    Email *

                    Message *

                    All Blogs