Posts tagged: Lua

RedEye #0: Notes

Things learned about RedEye.


RedEye IP Stops Responding or Slows Down

If the Port Script is edited, there may be an error in the script. There is no way for RedEye to gracefully accommodate errors, which normally involve syntax.
To help avoid scripting errors, test your code in an IDE outside of RedEye.
If the IP address or Port number is changed and saved within RedEye’s Devices Edit Port Settings, click Edit Port Script and click Apply Changes. Even if no changes are made to the script, the link between the script and port must be re-established, apparently.
If you find the RedEye isn’t as snappy as expected, try resetting it.
From the RedEye Maintenance page

  1. Backup Data
  2. Factory Reset
  3. Restore Data

If this doesn’t seem to help…
Download the latest firmware update from ThinkFlood
From the RedEye Maintenance page

  1. Backup Data (if needed)
  2. Upgrade Software (using the downloaded update)
  3. Restore Data (after RedEye restarts)

If RedEye continues to act-up, search the ThinkFlood Forums for advice on reseting.

Lua Script Testing For RedEye

To help develop error free code, use an IDE like ZeroBrane Studio. Of course, there are other options.

Finding IP Control Codes

Try searching google for your device and ip rs232 or custom install. Here’s a list for Pioneer, Pioneer AV Receivers
And specifically for the VSX-1121-K

Lua Block Comment Error

A block comment is fine …

--[[this is a


… unless it contains an embedded [[…


--[[this is a

… which totally whacks out RedEye.

RedEye Slider Values

Slider, Show value can’t be set (won’t stick) in web browser setup. Changes made using an IOS device do stick.

Custom Variables Are Stored as Strings

Using RedEye’s



always returns a string.
Convert it to a number before comparing to another number in an if statement. Example:

local c = tonumber(Scripting.GetVariable("IPmsgCount"))


iOS Stops updating Custom Variables

If iOS stops updating variables quit and re-launch on the iGadget.

Port Script Changes

To take effect, changes to the Port Script must be saved using the Save Changes (green) button on the Devices page.

RedEye Infinite Loops

Do not send device commands from within the PortListener. It can enter an infinite loop if the sent command returns a result (always for Pioneer VSX).
Infinite loops can be terminated by editing the PortListener script and saving it to the RedEye.

Multiple RedEye Device Entries for a Single Device

There can be a device (e.g. AV Receiver) that is setup in RedEye twice. Don’t use the IP address and Port combination more than once.


RedEye #6: Testing IP Control Codes

Knowing what a device returns after a command is received (sent by redid), helps design a control strategy.


Create System Variable, myInput, for the Control Code

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


  1. Click Add New Variable
  2. For Name enter myInput
  3. Value can remain empty
  4. Click Save

Create a New Command


Click Add New Command

Create a Command to send an IP Control Code

  1. For Type select Other
  2. For Name enter Send IP Cmd
  3. Click Edit Script and go to the next step – Enter Script.
  4. When the next step is complete, click OK

Enter Script


Replace line 5, as indicated above, with the following script .

local c = string.upper(Scripting.GetVariable("myInput"))
local b = Scripting.GetVariable("HTMLbody")
    b = [[<tr>
    <td style="border-style: none; text-align:left;">(user)</td>
      <td style="border-style: none; text-align:left;">]]
        .. c .. " -----" ..
    </tr>]] .. b
Scripting.SetVariable("HTMLbody", b)
Scripting.SetVariable("HTMLmsg", [[<table style="font-size: 80%;">]] .. b .. [[</table>]])


Click Apply Changes
Complete step 4 of the previous step.

Edit Layout

  1. Click Save Changes
  2. Click Layout > Edit

Make Room on Layout

  1. Click on HTML field to highlight
  2. Click and drag to make room at the top

Add Text Field

  1. Select Text Field
  2. Click Add Control
  3. Position new Text Field

Link Variable to Field

  1. Click to highlight Text Field
  2. Click Text Field Values
  3. Select Text Variable, myInput

Add Button

  1. Select Button
  2. Click Add Control
  3. Drag to reposition button

Set Button Action

  1. Select button
  2. Click Actions / Toggles
  3. Select Type as Normal
  4. Select Action Type as Command
  5. Select VSX A/V Receiver (your device)
  6. Select Send IP Cmd
  7. Click green, Save Changes button

Test Changes


Return to Devices page and click (Exit)
Select the device (VSX A/V Receiver)

  1. Enter a command
  2. Click outside of the text box (so the entered text is stored in the System Variable)
  3. Click Send IP Cmd

After a short delay, the sent command should display, followed by the response sent by the VSX.


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.


RedEye #4: Connect to Pioneer VSX via IP

To proceed, you must have the following for the VSX:

  • IP address (
  • Port number (23)

Pioneer Receiver Network Settings
Reserving an IP address for a client on your local network


Add the VSX

  1. Select the desired Manufacturer
  2. And Type
  3. Change the Port to Add New IP Port
  4. Enter your desired Display Name
  5. Click Find Codes

Select a Codeset


At the time of this tutorial, there was just a single codeset for the VSX. It doesn’t quite match the VSX-1121-K, but the commands can be edited later as needed.
If you device doesn’t have a codeset, save the device without.

  1. Click the Codeset desired
  2. Click Save This Device

Port Settings

  1. Click Edit Port Settings

IP Settings

  1. Ensure the Protocol is set to TCP
  2. Enter the IP address as the Host Name
  3. Enter the Port Number
  4. Click OK

Test the IP Connection: Mute Toggle


With your VSX reveiver turned on, test the IP control from RedEye.

  1. Click Mute On/OFF
  2. Click Save Changes