Is the Nx Cloud up? Visit our Status Page for the current health and performance of the Nx Cloud.

Status Page

[Event Rule] saveEventRule with Tradionnal Chinese eventCondition

Answered

Comments

9 comments

  • Andrey Terentyev
    • Network Optix team

    Hello,

    Please, provide the following info.

    VMS build, Server OS version, Client OS version.

    Could you please share with us the JSON text you have on the screenshot?

    Copy the text to a file, place the file on a cloud store and share the link here.

    0
  • Join Yang

    Nx Witness client: 5.1.0.37133(850ab7b33950f)

    Server OS:  Windows 8.1 

    Client OS: Windows 10 22H2

    Postman for Windows:  10.19.10

    Post Body:

    {
        "id": "{d36561c9-cb35-43fc-abaa-be8f9ffe875c}",
        "eventType": "softwareTriggerEvent",
        "eventResourceIds": [
            "e0c956b9-a035-b064-3410-120db4bccca5"
        ],
        "eventCondition": "{\"caption\":\"GV-AS810-Join測試 - Door 1 - Unlock Door\",\"description\":\"_door_opened\",\"eventTimestampUsec\":\"0\",\"eventType\":\"undefinedEvent\",\"inputPortId\":\"\",\"metadata\":{\"allUsers\":true,\"level\":\"\"},\"omitDbLogging\":false,\"progress\":0,\"reasonCode\":\"none\"}",
        "eventState": "undefined",
        "actionType": "execHttpRequestAction",
        "actionResourceIds": [],
        "actionParams": "{\"allUsers\":false,\"authType\":\"authBasicAndDigest\",\"durationMs\":5000,\"forced\":true,\"fps\":10,\"httpMethod\":\"GET\",\"needConfirmation\":false,\"playToClient\":true,\"recordAfter\":0,\"recordBeforeMs\":1000,\"streamQuality\":\"highest\",\"url\":\"http: //192.168.0.228:80/ASWeb/WebService.srf?username=1&password=1&module=monitor&is_nx=1&action=DOOR_OPERATION&operation=UNLOCK_DOOR&dvg_id=0&ctrl_id=1&dr_id=0\",\"useSource\":false,\"gateData\":{\"device_type\":0,\"dvg_id\":0,\"dvg_name\":\"Default\",\"node_id\":1001,\"device_id\":1,\"gate_id\":0,\"io_type\":0,\"device_name\":\"GV-AS810-Join測試\",\"gate_name\":\"Door 1\",\"is_input\":0,\"is_elevator\":0,\"cam_idx\":0,\"nx_cams\":[\"67bb95bd-66dc-f753-c1ba-f399faf82e95\",\"01357f1b-0e0d-e85c-a0a7-e07b816cb748\"]}}",
        "disabled":false,
        "comment":"ASManager Software Trigger Event",
        "system":false
    }

    Body json file: https://drive.google.com/file/d/1yi7McayFcSPolHNZEjYM5uCDjPYosB1h/view?usp=drive_link 

    Postman collection: https://drive.google.com/file/d/179VH32x3i9AE2q0aDhby6GGDKYpO3O5V/view?usp=drive_link 

     

    0
  • Join Yang

    Any update?

    0
  • Andrey Terentyev
    • Network Optix team

    hi,

    That seems to be a bug.

    The work around would be creating a rule with Chinese symbols in GUI, then requesting the rule via API and copying symbols.

    Here is the result for your case

    "eventCondition": "{\"caption\":\"GV-AS810-Join 測試 - Door 1 - Unlock Door\",\"description\":\"_door_opened\",\"eventTimestampUsec\":\"0\",\"eventType\":\"undefinedEvent\",\"metadata\":{\"allUsers\":true,\"level\":\"\"},\"omitDbLogging\":false,\"progress\":0,\"reasonCode\":\"none\"}",
    0
  • Andrey Terentyev
    • Network Optix team

    Hi, 

    Deeper investigation gave the following solution.

    The Server expect latin-1 encoded string representing utf-8 encoded JSON.

    That means, before being sent to the Server the JSON has to be

    1. serialized

    2. encoded to utf-8 byte array

    3. byte array has to be decoded to latin-1 string

    In python it look like this.

    import json
    import requests

    # omitting authorization requests

    event_condition = "{\"caption\":\"GV-AS810-Join測試 - Door 1 - Unlock Door\",\"description\":\"_door_opened\",\"eventTimestampUsec\":\"0\",\"eventType\":\"undefinedEvent\",\"inputPortId\":\"\",\"metadata\":{\"allUsers\":true,\"level\":\"\"},\"omitDbLogging\":false,\"progress\":0,\"reasonCode\":\"none\"}"
    rule_json = {
            "id": "{d36561c9-cb35-43fc-abaa-be8f9ffe875d}",
            "eventType": "softwareTriggerEvent",
            "eventResourceIds": [],
        "eventCondition" : event_condition.encode("utf_8").decode("latin_1"),
            "eventState": "undefined",
            "actionType": "execHttpRequestAction",
            "actionResourceIds": [],
            "actionParams": "{\"allUsers\":false,\"authType\":\"authBasicAndDigest\",\"durationMs\":5000,\"forced\":true,\"fps\":10,\"httpMethod\":\"GET\",\"needConfirmation\":false,\"playToClient\":true,\"recordAfter\":0,\"recordBeforeMs\":1000,\"streamQuality\":\"highest\",\"url\":\"http: //192.168.0.228:80/ASWeb/WebService.srf?username=1&password=1&module=monitor&is_nx=1&action=DOOR_OPERATION&operation=UNLOCK_DOOR&dvg_id=0&ctrl_id=1&dr_id=0\",\"useSource\":false,\"gateData\":{\"device_type\":0,\"dvg_id\":0,\"dvg_name\":\"Default\",\"node_id\":1001,\"device_id\":1,\"gate_id\":0,\"io_type\":0,\"device_name\":\"GV-AS810-Join測試\",\"gate_name\":\"Door 1\",\"is_input\":0,\"is_elevator\":0,\"cam_idx\":0,\"nx_cams\":[\"67bb95bd-66dc-f753-c1ba-f399faf82e95\",\"01357f1b-0e0d-e85c-a0a7-e07b816cb748\"]}}",
            "disabled": False,
            "comment":"ASManager Software Trigger Event 測試",
            "system":False
        }

    r = requests.post(API_URL,
                  data=json.dumps(rule_json),
                    headers={
                      'Authorization': f'Bearer {bearer_token}',
                    'Content-Type': 'application/json'
                    })
    0
  • Join Yang

    Hi,

    Thanks for your reply.

    Are there any plans to fix this bug in future versions?

    If so, then I'll wait for it.

    Otherwise I will implement UTF-8 encoding in my project.

    0
  • Andrey Terentyev
    • Network Optix team

    Hi,

    The bug has just been found. Though the bug report has been created, no plans so far.

    My guess, it will be fixed in v6.1

    0
  • Andrey Terentyev
    • Network Optix team

    Join Yang

    Please, pay your attention too my post. 

    https://support.networkoptix.com/hc/en-us/community/posts/18658744103447/comments/19279510380055

    I've corrected it. It's not just about UTF-8 encoding.

    0
  • Join Yang

    Andrey Terentyev,

    I have solved this bug in my Javascript project.

    ec2/saveEventRule: 
    params.eventCondition) = unescape(encodeURI(params.eventCondition));
    ec2/getEventRules:
    params.eventCondition = decodeURIComponent(escape(params.eventCondition));
     
    Thx.
     
    0

Please sign in to leave a comment.