Facility Control

 View Only
  • 1.  Dashboard/Streamdeck (Via Companion) HTTP Requests

    Posted 12-21-2022 21:30
      |   view attached
    Hi! We use dashboard primarily to control our Cobalt 9905/9904/9902 Frame sync cards. I have begun experimenting using a streamdeck (via companion after discovering it on this fourm!) and have a couple questions. 

    Since there is no native Cobalt/Opengear module for companion. I have a working POC using the generic HTTP module for companion which lets you send HTTP POST/GET/PUT/PATCH/DELETE requests to any endpoint/port. I am just running companion/Dashboard on the same PC and sending the requests via loopback. 

    I was wondering if I could get a Dashboard HTTP Listener for dummies document/info on how to set up a task under a HTTP listener to pull the JSON Payload from a HTTP get request and access the data in that JSON within the task to perform tasks (setting parameter values, changing device context etc). I found a sample HTTP listener grid file in Ben Gatien's Example Grid Files but it only seems to pull the endpoint url as a GPI string value to be used. 

    Ideally, I want to be able to push a button on the stream deck that sends a GET request with a JSON payload that includes a ID to Dashboard, and have Dashboard return a few key parameter values of the Device with that ID back to companion in JSON to display on the streamdeck buttons. Then would want similar functionality to send a POST request to change those parameter values.

    I have attached my grid file of my POC, which is an adapted version of the Ben's HTTP listener to give a taste of what I have already developed.

    ------------------------------
    Evan Aaron
    Engineer
    Game Creek Video
    ------------------------------

    Attachment(s)



  • 2.  RE: Dashboard/Streamdeck (Via Companion) HTTP Requests

    Posted 01-04-2023 09:42
    Hi Evan
    To do what you're talking about (2-way communication with your device parameters over HTTP via DashBoard), you will need to go beyond the generic HTTP trigger service and write a listener that can take-in an HTTP request, perform whatever actions you are looking for, and write-back a response.  

    I do not have an example at the ready that does this with JSON payloads but that would be a fairly straight-forward expansion on an example panel that I do have to which takes-in HTTP requests and returns parameter values. 

    This panel looks for http://localhost:8910/OID_GOES_HERE and returns the value as a string.  You could expand the panel to include JSON as part of the query string (or even get to a POST with a little more work and accessing the listener's input stream) and write JSON back the same way that this panel is writing back a simple parameter value string.

    <abs contexttype="opengear" id="_top">
       <meta>
          <params>
             <param access="1" maxlength="0" name="Device Identifier" oid="dev_id" type="STRING" value="231bf459-000000f9&lt;br&gt;Slot 8&lt;br&gt;SRA-8201" widget="512"/>
          </params>
          <context contexttype="opengear" id="my_device" objectid="%value['dev_id'][0]%"/>
       </meta>
       <param expand="true" height="41" left="2" oid="sw_id" right="124" top="5">
          <task tasktype="ogscript">ogscript.reload(null);</task>
       </param>
       <listener autostart="true" buttontype="toggle" delimiter="0A" delimitertype="bytes" height="48" listenport="8910" name="Listen" right="0" style="style:toggleButton;" top="5" width="114">
          <task tasktype="ogscript">if (event.isMessageEvent())
    {
       var responseText = null;
       var byteStr = event.getBytesAsString();
       if (byteStr.indexOf('GET') == 0 || byteStr.indexOf('POST') == 0)
       {
          var pathStart = byteStr.indexOf('/');
          var pathEnd = byteStr.lastIndexOf(' ');
          if (pathStart &gt; 0 &amp;&amp; pathEnd &gt; 0 &amp;&amp; pathStart &lt; pathEnd)
          {
             var requestedParam = unescape(byteStr.substring(pathStart + 1, pathEnd));
             if (requestedParam != 'favicon.ico')
             {
                var p = params.getParam('my_device', requestedParam, 0);
                if (p != null)
                {
                   responseText = p.getValueAsString();
                }
                else
                {
                   responseText = 'Failed to find parameter ' + requestedParam;
                }
             }
          }
    
          if (responseText == null)
          {
             responseText = 'Failed to find a parameter';
          }
       
          this.writeString('HTTP/1.1 200 OK\r\n', false);
          this.writeString('Content-Type: text/plain; charset=utf-8\r\n', false);
          this.writeString('Connection: close\r\n', false);
          this.writeString('Content-Length: ' + responseText.length + '\r\n\r\n', false);
          this.writeString(responseText, false);
       }
    }</task>
       </listener>
    </abs>
    ​


    ------------------------------
    James Peltzer
    Ross Video
    ------------------------------