Simple RCI by HTTP

From Digi Developer

Jump to: navigation, search

Contents

Reading DIA channels via web commands

Digi provides many detailed documents explaining web services and remote RCI calls, but most provide too much detail or partial examples. They assume you already know how to move the requests, so just want the core syntax.

Simple Python for use on a PC

Below is a simple script which allows using XML to query data in real-time from a gateway running DIA.

Sample YML

What this DIA system does isn't important. The RCI calls below will read or write the properties from the device named 'level', which are named level.alert and level.config respectively. The RCIHandler must be enabled, plus the setting target_name must match what you place into your RCI calls.

devices:

  - name: count
    driver: devices.template_device:TemplateDevice
    settings:
        update_rate: 10
        
  - name: level
    driver: devices.experimental.alert_output:AlertOutput
    settings:
        source: 'count.adder_total'
        rising: 12.0
        falling: 11.5
        
presentations:

  - name: rci_handler
    driver: presentations.rci.rci_handler:RCIHandler
    settings:
        target_name: idigi_dia

Writing the RCI request

Detailed information on the RCI commands accepted by the DIA RCI presentation can be found in the DIA user documentation.

Those RCI commands, such as <channel_dump />, <channel_set name="..." value="..." />, and <logger_set name="..." /> are wrapped in the following syntax. Notice that the string target="idigi_dia" matches the target name in the YML file.

<rci_request version="1.1">
       <do_command target="idigi_dia">
            <channel_dump/>
       </do_command>
</rci_request>

In DIA versions 2.2.0.1 and below, the RCI handler can only accept a single tag in the <do_command> block. A workaround is to wrap multiple commands in an arbitrary wrapper tag like the following:

<rci_request version="1.1">
       <do_command target="idigi_dia">
            <blob>
                 <channel_get name="level.alert"/>
                 <channel_get name="level.config"/>
            </blob>
       </do_command>
</rci_request>

The only thing to remember with this is that the <blob> tag will wrap the response code in a similar fashion.

For DIA versions newer than 2.2.0.1, the RCI handler does not need a wrapper tag, so the below syntax would work:

<rci_request version="1.1">
       <do_command target="idigi_dia">
            <blob>
                 <channel_get name="level.alert"/>
                 <channel_get name="level.config"/>
            </blob>
       </do_command>
</rci_request>

However, this will generate an XML parse error with DIA versions 2.2.0.1 and below.

Source Code

Below is an actual script written and used under Python 2.4.3 on a Windows 7 PC.

# Simple PC example to query the DIA device
 
import httplib, urllib
 
msg_dump = \
"""<rci_request version="1.1">
       <do_command target="idigi_dia">
            <channel_dump/>
       </do_command>
   </rci_request>"""
 
msg_get = \
    """<rci_request version="1.1">
           <do_command target="idigi_dia">
               <channel_get name="level.alert"/>
           </do_command>
           <do_command target="idigi_dia">
               <channel_get name="level.config"/>
           </do_command>
       </rci_request>"""
 
# notice that the VALUE this channel takes is complex - a list of 3 values.
# That is defined by the DRIVER involved.  Most channels will take a 
# simple True/False, integer, floating point or string value.
# examine the channel_get response to discover what to return channel_set
msg_set = \
    """<rci_request version="1.1">
           <do_command target="idigi_dia">
               <channel_set name="level.config" value="[10,9,True]"/>
           </do_command>
       </rci_request>"""
 
if __name__ == '__main__':
 
    msg = msg_get    
 
    conn = httplib.HTTPConnection("192.168.196.204:80")
    conn.request("POST", "/UE/rci", msg)
 
    response = conn.getresponse()
    print response.status, response.reason
    data = response.read()
    print data
    conn.close()

Sample Output

C:\py\dia\work>python test_rci.py
200 OK
<rci_reply version="1.1"><do_command target="idigi_dia"><channel_get name="level.alert" 
value="False" units="alert" timestamp="Mon Jul 12 11:08:46 2010"></channel_get></do_command>
<do_command target="idigi_dia"><channel_get name="level.config" 
value="[12.000000,11.500000,False,'count.adder_total']" 
units="" timestamp="Mon Jul 12 11:08:46 2010"></channel_get></do_command></rci_reply>

See Also

  • RCI Request Wiki Page This is geared more to using RCI to read/write values in the Digi hardware and not in DIA.
  • Look up the RCI handler module in the DIA HTML documentation, or see the doc strings directly in the DIA source file "src\presentations\rci\rci_handler.py". It supports the commands including, but not limited to:
    • <channel_dump/>
    • <channel_get name="..."/>
    • <channel_refresh name="..."/>
    • <channel_set name="..." value="..."/>
    • <channel_info name="..."/>
    • plus there is a series of logger commands
Personal tools
Wiki Editing