1

Listing existing geofences using the Wialon Python API

Тема: Listing existing geofences using the Wialon Python API

Hi,
I am new to the Wialon API and therefore the problem I have is a relatively simple one. I am currently trying to use the Python Wialon module to get a list of existing geofences and their details. Attached below is the code I used:

from wialon.api import Wialon, WialonError
from wialon import flags

try:
    wialon_api = Wialon()
    result = wialon_api.token_login(token='MYKEY')
    wialon_api.sid = result['eid']

    result = wialon_api.avl_evts()

    spec = {
        'itemId': '4096',
        'col': '[]',
    }

    try:
        geofences = wialon_api.resource_get_zone_data(spec=spec)
        print(geofences)
    except WialonError as e:
        print(e)


    wialon_api.core_logout()
except WialonError as e:
    pass

However, this resulted in the following error:

WialonError(Invalid input resource_get_zone_data (4))

What might I be doing wrong?

Thank you in advance.

2

Listing existing geofences using the Wialon Python API

Re: Listing existing geofences using the Wialon Python API

Hey
You have to pass spec directly, not as named parameter

    try:
        geofences = wialon_api.resource_get_zone_data(spec)
        print(geofences)
    except WialonError as e:
        print(e)

Also check If you have access to resource with id=4096. If you don't have it, you'll get Error:7

    spec = {
        'itemId': '4096',
        'col': '[]',
    }
3

Listing existing geofences using the Wialon Python API

Re: Listing existing geofences using the Wialon Python API

Thanks a lot shmi!

I did as you said but it looks like I do not have access to that resource as I get Error:7.

How to I rectify this error?

It should be said that the I am able to retrieve geofence details from the JavaScript API.

4

Listing existing geofences using the Wialon Python API

Re: Listing existing geofences using the Wialon Python API

Check example below

from wialon.api import Wialon, WialonError
from wialon import flags

try:
    token = 'TOKEN'
    wialon_api = Wialon()
    result = wialon_api.token_login(token=token)
    wialon_api.sid = result['eid']

    # search for resources to find resource id
    params = {
        "spec": {
            "itemsType": 'avl_resource',
            "propName": 'sys_name',
            "propValueMask": '*',
            "sortType": 'sys_name',
        },
        "flags":0x1001,
        "force": 1,
        "from": 0,
        "to": 0
    }
    result = wialon_api.core_search_items(params)
    # list of all available resources
    print(result['items']) 
    
    # get first available resource id
    resource_id = result['items'][0]['id']
    
    # use resource id to get all its geofences
    spec = {
        'itemId': resource_id,
        'col': '[]',
    }
    try:
        geofences = wialon_api.resource_get_zone_data(spec)
        print(geofences)
    except WialonError as e:
        print(e)

    wialon_api.core_logout()
except WialonError as e:
    print(e)
5

Listing existing geofences using the Wialon Python API

Re: Listing existing geofences using the Wialon Python API

Thanks a lot shmi it works like a charm!