Webserver Pro KTA-223 Commands
netRestart Ethernet Shield
opt(0-15, 0/1, Duration)Set Opto-Inputs HIGH or LOW
0-15 identifies Opto-Ins to set HIGH:
0 - none (Sets All LOW), 1 = Opto-in 1, 2 = Opto-in 2,
4 = Opto-in 3, 8 = Opto-in 4, 15 = All HIGH
0/1 - Test/Save, 1 saves setting on restart.
Duration is in tenths of seconds,  0 = no timer
Example:  opt(12,1,1800)
Sets Opto-ins 3 and 4 HIGH for 3 minutes and saves setting to memory
Opto-ins 1 and 2 are set LOW immediately and not reset
(Save to memory does not save duration, timer is for current session only)
pin(0-15, 0/1)Set Input pinModes
0-15 identifies Input pins to set as OUTPUT or INPUT:
0 - none (All INPUT), 1 = Opto-in 1, 2 = Opto-in 2,
4 = Opto-in 3, 8 = Opto-in 4, 15 = All OUTPUT
0/1
- Test/Save
rct(0-255, 0/1, Duration)Turn Relays ON or OFF
0-255 identifies Relays to turn ON:
0 - none (All OFF), 1 = Relay 1, 2 = Relay 2, 4 = Relay 3,
8 = Relay 4, 16 = Relay 5, 32 = Relay 6, 64 = Relay 7,
128 = Relay 8, 255 = All Relays ON
0/1 - Test/Save,  Duration in tenths of seconds,  0 = no timer
Example:  rct(240,0,72000)
Turns Relays 5, 6, 7 and 8 ON for two hours,  Relays 1 - 4 OFF (immediately, with no timed reset)
The timer can also be used to switch an active relay off, but that's only really useful when other relays are left on.  As relay commands specify those to switch off as well as on, the timer always effectively leaves all off on expiring.
rdaDisplay Analog input levels,  0 - 1023
rdiDisplay Input pinModes and levels
0 = IN / LOW,  1 = OUT / HIGH
rdoDisplay Relay settings
0 = OFF,  1 = ON
Commands requiring parameters rct, opt or pin will do nothing if called without brackets and the first number, Test/Save and Duration are optional.  Calling them with just (0) resets all of their resective pins.
 
Issuing USB Serial Commands

Commands can be issued remotely to the USB port or a local network when connected.  Communication through the USB port requires FTDI Drivers. In Linux 2.6.26 kernels the optional module is called ftdi_sio.

Example, a Linux command to turn the first relay on for five seconds:

echo "rct(1,0,50)" >/dev/ttyUSB0&

Or from a Windows Command Prompt:

echo rct(1,0,50) > COM5

If you don't get a result in Windows XP, and you're sure the port is not COM (some other number), try setting the device mode first:

mode COM5 BAUD=9600 PARITY=N DATA=8 STOP=1

Reading Command Output
Command results can be viewed on the Arduino Serial Monitor.  The desktop monitor distributed with the KTA-223 "OC RelayDuino ASCII Slave" will not work with this sketch.  To start a viewer from a command line, a background command should be given to view the port before the command to test.  Linux example:

cat /dev/ttyUSB0&

As well as the obvious output of the rd* status commands, changing or switching multiple pins produces multi-line output.  Each line indicates the pin changed, it's current setting and the new setting.

For output, pin numbers start at 0 not 1, so a command to switch Relay 2 on will output 1 0 1 on success, even though it is called 2 in the command.  No output means the Relay is already on.  Giving the Save option 1 as second parameter should output the value saved as well.

UDP Command Interface

The same Serial Interface commands can be issued in a UDP 'datagram' packet over a local network.  While the web interface is a better testing environment for viewing outcomes of procedures, the UDP interface is quicker and more robust for complex operations involving multiple relays or pins.

An example using the Linux 'netcat' command:

netcat -nuc 'echo "rct(1,0,50)"' 192.168.1.223 61223

Sends a UDP packet containing the text rct(1,0,50) to the Relay Controller's network port, which should turn Relay 1 ON for five seconds.  Note the single quotes around the 'send' command and the double quotes within, denoting the actual command "to be received".  UDP commands don't have to end with a new line or carriage-return.
 
Using the Webserver
The Webserver Pro requires a computer on the same network or the controller's address changed to an unused on on a LAN.  As the Ethernet Shield also requires a unique MAC Address, they should only need to be changed the first time the sketches are compiled and uploaded.  Network configuration is stored in non-volatile memory and not the main program.

If your network number starts with 192.168.1. then you should be able to acces the Relay Controller by typing (or copying) 192.168.1.223 into the location bar of a browser (and <Enter>).

There are three virtual pages, Relays, Opto-Inputs and Input Pinmodes.  Reloading or changing pages only reloads the webserver unless the Reboot button is pressed, which restarts the main program.

The control to set All Relays or Inputs is unchecked as the setting overrides any separately selected pins.

Setting a Duration also triggers a timed auto-refresh, which can be disabled by checking off the Timer Refresh option.  Switching timer refreshes off does not affect the timer, however the set pins must be unchecked or the page refreshed before any more can be set without resetting those pins a second time.  Duration has no effect in Pinmode, where unsaved changes remain in place for the session or until reset.

Default Page sets the current page to show first when the Relay Controller starts up.  'Relays' is the default page.

Apply saves settings for the current session or duration if specified.  They are forgotten on reboot unless Save Settings is also selected.  The defaults (that don't need to be saved) are all Relays OFF and all Inputs (as INPUT) HIGH.

© MMXI Network Kontrol