RedEye #5: Receive a Message from VSX via IP

After completing RedEye: Connect to Pioneer VSX via IP, the RedEye is already receiving messages from the VSX.
Unfortunately, the VSX sends messages that may be longer than expected. This makes using the received messages more complicated than might otherwise be expected.
The issue addressed here is how to display what the VSX is sending out. This will give a better idea as to how to proceed using using the received messages.
The technique outlined here is generic in that it can be used to monitor any IP port via RedEye.


Add Required Custom Variables

  • Point your web browser at the RedEye.
  • Click Setup
  • Click the Room
  • Click Custom Variables


  1. Click Add New Variable
  2. For Name enter IPmsgCount
  3. Value can remain empty
  4. Click Save
  5. Repeat for variable HTMLbody
  6. REpeat for variable HTMLmsg

Edit Port Script


From the RedEye Room, click Devices
Select your device.
Click Edit Port Script

Modify the script


Add the following functions to the Port Script as indicated:

function string:split(sep) -- split (parse) string --> table
    local sep, fields = sep or ":", {}
    local pattern = string.format("([^%s]+)", sep)
    self:gsub(pattern, function(c) fields[#fields+1] = c end)
    return fields

function buildHTML(ipMsg)
    local c = tonumber(Scripting.GetVariable("IPmsgCount"))
    local b = Scripting.GetVariable("HTMLbody")
    if c > 90 then
        c = 0
        b = ""
    c = c + 1
    b = [[<tr>
      <td style="border-style: none; text-align:left;">]]
        .. c .. "/" .. #ipMsg ..
      <td style="border-style: none; text-align:left;">]]
        .. table.concat(ipMsg,"<br>") ..
    </tr>]] .. b



    Scripting.SetVariable("IPmsgCount", c)
    Scripting.SetVariable("HTMLbody", b)
[[<table style="font-size: 80%;">]]
    .. b ..

Click Apply Changes

Process Input


Add the following to the Port Script as indicated.


    local t = inputData:split("\r\n") -- store message elements in table "t"
    Scripting.SetVariable("HTMLmsg", buildHTML(t))


Click Apply Changes

Final Script


At this point, the Port Script will accumulate all messages received from the VSX and store it in the State Variable named HTMLmsg.
Building the html code in this way, isn’t very efficient. Using a table would no doubt improve the speed.
All that remains is to display the HTML.


Return to the VSX device page.
Click Layout Edit

Add HTML Control to the Layout


The default buttons won’t be use right now, so they may be deleted or moved down the layout to make room.

  1. Select HTML
  2. Click Add Control

Connect the HTML received message variable to the display control

  1. Click the HTML control in the Layout (indicated by the yellow #1 and blue line)
  2. Within the Device Remote Layout > HTML Values > HTML Content Variable, select the variable HTMLmsg
  3. Click Save Changes
  4. Return the the Devices page and click Save Changes
  5. Click (Exit) to return to the RedEye home screen

From the RedEye home page:

  • Click Devices
  • Click the device VSX A/V Receiver

The control pane should appears as shown above.

  1. The left column indicates: message number / number of distinct elements in this message
  2. The right column shows the list of messages.

When the number of received messages exceeds 90, the storage variable (HTMLbody) is cleared. See line 16 of the final script.
As shown in the screen shot, there are frequently multiple elements in any given message. This explains why control is unreliable when this fact is ignored.