Facility Control

 View Only
  • 1.  Set parms from Http Json data

    Posted 11-10-2021 02:34
    Now i did get data from http then i want some parms from that json data trigger task
    {"response_at":"2021-11-10 15:25:06","code":0,"msg":"\u64cd\u4f5c\u6210\u529f","data":{"team_data":[{"rank":5,"id":"1","team":"GL","team_img1":"GL.png","team_img2":"GL.png","team_img3":"D:\\Projects_XPression\\2021-6-25_PEN\\Images\\Data material\\Colour_Pic\\GL.png","game_rank":5,"kill":9,"knock_out":8,"score":20,"color_id":"1_color","is_alive":0,"is_die":1,"is_online":1,"alive_num":1,"out_num":11,"team_num":"0","is_outside":0,"alive_player":null,"die_num":4,"down_num":null,"player_1":"out_Image","player_1_is_alive":0,"player_1_name":"GL\u30fbDGZ","player_2":"out_Image","player_2_is_alive":0,"player_2_name":"GL\u30fb\u73a9\u610f\u513f","player_3":"out_Image","player_3_is_alive":0,"player_3_name":"GL\u30fb\u591c\u884c","player_4":"out_Image","player_4_is_alive":0,"player_4_name":"GL\u30fb\u9c7c\u751f","history_kill":40,"history_score":73,"max_kill":15,"max_score":22,"last_game_kill":9,"last_game_rank":5,"top5":2,"top5_percent":"40%","top5_score_avg":18,"color":"200,158,12","sort":1,"sort2":2}
    i want to trigger task when isalive changed and i don't know how to set parms value to this http parms ' isalive'

    <abs contexttype="opengear" id="_top" keepalive="false" style="">

    <timer autostart="false" id="time" pattern="HH:mm:ss" rate="500" start="00:00:00" stop="00:00:00">
    <timertask tasktype="ogparamset">params.setValue('time', 0, event.getDisplay());</timertask>
    </timer>
    <meta>
    <params>
    <param access="1" maxlength="0" name="URL" oid="URL" type="STRING" value="" widget="default"/>
    <param access="1" maxlength="0" name="dataOutput" oid="dataOutput" type="STRING" value="" widget="multiline-text"/>
    <param access="1" maxlength="0" name="time" oid="time" type="STRING" value="00:00:00" widget="default"/>
    </params>
    </meta>
    <param expand="true" height="40" left="80" oid="URL" showlabel="false" top="40" width="360"/>
    <label height="20" left="80" name="URL" style="txt-align:west" top="20" width="160"/>
    <param expand="true" height="40" left="80" oid="time" showlabel="false" top="120" width="120">
    <task tasktype="ogscript">function callback(resultStr)
    {
    if (resultStr != null)
    {
    var json = JSON.parse(resultStr);
    var back = JSON.stringify(json);
    ogscript.debug(back);
    params.setValue('dataOutput',0,back);
    }
    }
    ogscript.asyncPost(params.getValue('URL', 0), null, callback);</task>
    </param>
    <label height="20" left="80" name="timeTrigger" style="txt-align:west" top="100" width="120"/>
    <button buttontype="push" height="40" left="240" name="start" top="120" width="80">
    <task tasktype="timercontrol">ogscript.getTimerManager().getTimer('time').startTimer(true);</task>
    </button>
    <button buttontype="push" height="40" left="340" name="stop" top="120" width="80">
    <task tasktype="timercontrol">ogscript.getTimerManager().getTimer('time').stopTimer(true);</task>
    </button>
    <param expand="true" height="340" left="80" oid="dataOutput" showlabel="false" top="200" widget="default" width="920"/>
    <label height="20" left="80" name="output" style="txt-align:west;" top="180" width="160"/>
    <button buttontype="push" height="40" left="460" name="clean" top="120" width="120">
    <task tasktype="ogscript">params.setValue('dataOutput',0,'');</task>
    </button>
    </abs>

    ------------------------------
    Haoran YE
    ------------------------------


  • 2.  RE: Set parms from Http Json data

    Posted 11-23-2021 08:39

    Well you need to acces the "isAlive" value from your json object.

    You parse the json string into an object with the line:

    var json = JSON.parse(resultStr);

    From there you need to look through your JSON data (online formatter f.ex: https://jsonformatter.curiousconcept.com/ )
    And then you need to find the data you want. Based on the JSON response you're including in your post it should be:

    var isAlive = json.data.team_data.is_alive;

    Then use that var to set a parameter value wich in turn can trigger a change based on its value.
    Or even better yet, do all the changes within the function allready.



    ------------------------------
    Aleksander Stalsberg
    Lillehammer Icehockey Club
    ------------------------------