Skip to main content
Skip table of contents

Filtering Position Updates by Mobile MAC Address

Filtering logs by device (Mobile and Virtual Mobile) MAC address can be important for managing large amounts of data effectively. Use the LOCATION_RAW_UPDATE filter to capture Mobile and Virtual Mobile position updates by MAC address in Python.

The Difference Between Mobile and Virtual Mobile MAC Addresses

Mobile MAC Address

The 12-digit identifier assigned to the physical device. This MAC address is referenced in positioning logs and the ZeroKey dashboard.

  • Example: D4:66:A0:E6:71:22

Virtual Mobile MAC Address

The last 8-digits of the Virtual Device MAC address are assigned by the user. The first 4-digits default to FF:FF for every Virtual Device.

  • Example: FF:FF:D4:66:A0:E6

Prerequisites

LOCATION_RAW_UPDATE_EVENTS

Refer to our help article Utilizing Location Raw Update Events in Python for example code. To add MAC address filtering, you’ll need to modify the HANDLE_LOCATION_RAW_UPDATE function in the example code.

Steps to Filter Logs by Mobile MAC Address

Follow the steps below to filter LOCATION_RAW_UPDATE logs based on the MAC address prefix.

  1. Modify the Function to Include MAC Address Filtering

Update the HANDLE_LOCATION_RAW_UPDATE function to filter by MAC address by checking if the MAC field in the Source section of each log starts with the specified prefix. The example below shows how to apply this filter.

Current code (Without MAC Address Filtering)

def handle_location_raw_update(data):
json_str = data[0]
event_data = json.loads(json_str)
if event_data['Type'] == 'LOCATION_RAW_UPDATE':
print(f"Received LOCATION_RAW_UPDATE:(event_data)")

Updated Code (With MAC Address Filtering)

def handle_location_raw_update(data):
    json_str = data[0]
    event_data = json.loads(json_str)

    if event_data['Type'] == 'LOCATION_RAW_UPDATE':
        if event_data['Source']['MAC'].startswith("Enter Mobile MAC"):
            mac_address = event_data['Source']['MAC']
            print(f"Received LOCATION_RAW_UPDATE for device with MAC '{mac_address}': {event_data}")

 

  1. Specify the Mobile’s MAC Address

Replace “Enter Mobile MAC” with either the full MAC address or the starting portion of the Mobile MAC address.

  • For example, if the MAC address is D4:66:A0:E6:71:22, you can either enter the full MAC address or set it to “D4:66” to match any device starting with D4:66.

 

  1. Save and Execute the Script

Save the code and run it in your command prompt or terminal. The following is an example of the execution output:

C:\Users\admin\PycharmProjects\API 4\API\API>python TestingZKAPI.py

Connection opened and handshake received; ready to send messages

Received LOCATION_RAW_UPDATE for device with MAC 'D4:66:A0:E6:71:22': {'Category': 'POSITION', 'Type': 'LOCATION_RAW_UPDATE', 'Timestamp': '2024-11-07T18:29:02.8031Z', 'Content': {'Position': [1.02906, -0.69719, 0.0166], 'Orientation': [0.74942, 0.09172, -0.11673, 0.64524], 'Sequence': 50739, 'Flag': 0, 'InsState': 4, 'UsState': 3, 'RelativeTimestamp': 5074679472, 'Velocity': [0.00018, 0.00261, 0.00017], 'InsSequence': 0}, 'Source': {'SiteID': 0, 'MAC': 'D4:66:A0:E6:71:22', 'GatewayURI': 'ZK://0::c0ee9f7a-83dc-47f8-94b1-e7f647a4e33e::USB::/dev/ttyACM0'}, 'LocalTimestamp': '2024-11-07T11:29:02.8031'}

Steps to Filter Logs by Virtual Mobile MAC Address

To filter logs by a virtual MAC Address, modify the MAC filter to include the virtual MAC that starts with “FF:FF:”. An example is shown below.

def handle_location_raw_update(data):
    json_str = data[0]
    event_data = json.loads(json_str)

    if event_data['Type'] == 'LOCATION_RAW_UPDATE':
        if event_data['Source']['MAC'].startswith("FF:FF:Enter Mobile MAC"):
            mac_address = event_data['Source']['MAC']
            print(f"Received LOCATION_RAW_UPDATE for device with MAC '{mac_address}': {event_data}")

  1. Update the Virtual MAC Preffix

Replace “Enter Mobile MAC” with the Virtual Mobile MAC address.

  • For Example "FF:FF:D4:66:A0:E6".

  1. Run the Code

Save the code and run it in your command prompt or terminal. The following is an example of the execution output:

C:\Users\admin\PycharmProjects\API 4\API\API>python TestingZKAPI.py

Connection opened and handshake received; ready to send messages

Received LOCATION_RAW_UPDATE for device with MAC 'FF:FF:D4:66:A0:E6': {'Category': 'POSITION', 'Type': 'LOCATION_RAW_UPDATE', 'Timestamp': '2024-11-07T18:33:03.9545Z', 'Content': {'Position': [1.775990793800354, -0.09460324853897095, 0.2878848897457123], 'Velocity': [0, 0, 0], 'Orientation': [0.93479, 0.01884, -0.14079, 0.32555], 'Sequence': 53150, 'Flag': 0, 'InsState': 4, 'UsState': 3, 'InsSequence': 1}, 'Source': {'SiteID': 1, 'MAC': 'FF:FF:D4:66:A0:E6', 'GatewayURI': 'ZK://0::FF:FF:D4:66:A0:E6::VIRTUAL::100'}, 'LocalTimestamp': '2024-11-07T11:33:03.9545'}

 

NOTE: The Virtual Device will report in the output after GatewayURI which confirms parsing for a Virtual Device is enabled.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.