waciworld waciworld
Home
Code Samples
WACI IR Files
Support
 
 
 
Jump to auroramultimedia.com

WACI Control Page Source Code Samples

Welcome to the WACI programming sample page. This is the place to be if you are doing WACI development. We have provided source code for some of our demos so you can quickly learn how to program a WACI using standard web languages (Flash, DHTML, etc). The source code is provided as-is. If you are having trouble getting anything to work, or need something more specific please post a message to the forum and one of our WACI experts will get back to you. If you have developed a new way of accessing the WACI's RPC server, we would like to hear about it. Please email webmaster@waciworld.com, and we will add it to this list.

Currently, sample code is available for the following programming languages:


Adobe Flash Examples
WACI NX XML-RPC Functions
Flash Programming Demo

This component utilizes the XML RPC socket based connection supported by the WACI NX and NXT series controllers. Unlike the HTTP components below, this technology allows for bidirectional communication, eliminating the need for polling variables. The XML RPC server also runs on a separate port, freeing up additional resources for the web server on port 80. This is recommended for any project using an NX or NXT series controller.

This component will allow you to make the connection to the WACI NX and has the most popular functions already coded into it. In addition, there is a generic function that will allow you to send any available RPC. Feel free to view the source so you can make your own modifications to it.

WACI NX and NXT series controllers

Download Flash CS6 Source Code (.FLA)
Download Flash CS5 Source Code (.FLA)


WACI NX Functions
Flash Programming Demo

If you are programming a WACI NX for the first time using Flash, Download this file now. It will save you a LOT of time making the connections to the WACI NX and setting up your commands. This file will demonstrate all pertinent functions on the WACI RPC server from within a flash movie. You should only need basic flash experience to get this to work. Just look at the source code and read the detailed comments and you will be on your way to creating WACI control pages in no time.

This component will allow you to make the connection to the WACI NX and has the most popular functions already coded into it. Feel free to view the source so you can make your own modifications to it.

All WACI controllers (except original WACI+ and WACI Jr.)
Use XML RPC above for NX/NXT series

Download Flash 8 Source Code (.FLA)


WACI Functions (Legacy)
Flash Programming Demo

This component will allow you to make the connection to the WACI and has the most popular functions already coded into it. Feel free to view the source so you can make your own modifications to it.

WACI+ and WACI Jr

Download Flash MX 2004 Source Code (.FLA)



Javascript / DHTML / AJAX Examples

The following is some sample code that will allow you to control the WACI NX using only HTML and JavaScript.

To use this code, simply copy and paste the code below into a text editor and save with a .html extension. Make sure you set the JavaScript variable "WACIip" to the IP address of your WACI. All commmands are commented within the code.

<script language="JavaScript">

///////////////////////////////////////////////
//DHTML SCRIPT V2 - SETUP
///////////////////////////////////////////////

//Set your WACI IP or Hostname Here *****************************
var WACIip = "192.168.1.165";

///////////////////////////////////////////////
//
// To Send IR Commands make a link to: "javascript:IRSend(port, group, command)"
// To Send Serial Commands make a link to: "javascript:serialSend(port, command, timeout)"
// To Trigger an Event make a link to: "javascript:TriggerEventByName('eventname', '0', '0', '0')"
// To Trigger an Event make a relay turn on: "javascript:relayToggle('Relay_On', '1')"
// To Trigger an Event make a relay turn off: "javascript:relayToggle('Relay_Off', '1')"
//
///////////////////////////////////////////////

var RPCurl = "http://"+WACIip+"/RPC";

var xmlhttp = null;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}

function getResponse(){
if (xmlhttp.readyState == 4) {

}
alert(xmlhttp.readyState);


}

function relayToggle(method, param1) {

// Relay Example:
// Param 1: RPC Method Name
// Param 2: Relay Port

xmlhttp.open("POST",RPCurl,false);
var theString = "method=" + method + "&Param1=" + param1;
xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = getResponse;
xmlhttp.send(theString);
}


function serialSend(param1, param2, param3) {

// Param 1: Port
// Param 2: Serial String
// Param 3: Timeout

xmlhttp.open("POST",RPCurl,false);
var theString = "method=Serial_Send&Param1=" + param1 + "&Param2=" + param2 + "&Param3=" + param3;
xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(theString);
}

function IRSend(param1, param2, param3) {

// Param 1: IR port on WACI to send from
// Param 2: Group name of the IR commands
// Param 3: Name of the command to send

xmlhttp.open("POST",RPCurl,false);
var theString = "method=IR_SendCommand&Param1=" + param1 + "&Param2=" + param2 + "&Param3=" + param3;
xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(theString);
}

function TriggerEventByName(param1, param2, param3, param4) {

// Param 1: Name of event to trigger

xmlhttp.open("POST",RPCurl,false);
var theString = "method=TriggerEventByName&Param1=" + param1 + "&Param2=" + param2 + "&Param3=" + "&Param4=" + param4;
xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(theString);
}

</script>

<br><br><br><br>

<a href="javascript:TriggerEventByName('test', '0', '0', '0')">Run 'test' event</a><br><br>

<a href="javascript:relayToggle('Relay_On', '1')">r1 on</a><br><br>

<a href="javascript:relayToggle('Relay_Off', '1')">r1 off</a><br><br>

<a href="javascript:serialSend(1, 'SOME DATA', 200)">Send data through Serial 1</a><br><br>

<a href="javascript:IRSend(1, 'VCR', 'POWER')">Send VCR Power Command</a><br><br>


ASP 3.0

Here is an example using ASP VBScript to call functions on the WACI

Dim waciUser
set waciUser = CreateObject("WACI.UserAPI.1")

'Gets the current value of "myInputVar"
inputId = waciUser.GetVariableByName("myInputVar")
inputValue = waciUser.GetVariableValue(inputId)

'Sets the current value of "myInputVar"
setInputVar = waciUser.AssignVariable("myInputVar", "0", "newvalue")

'Find out how many relays the WACI has
relayCount = waciUser.Relay_GetPortCount()

'Turn Relay On
setRelay1ON = waciUser.Relay_On(1)

'Turn Relay Off
setRelay1OFF = waciUser.Relay_Off(1)

'Get Relay Status (on or off)
getRelay1Status = waciUser.Relay_GetState(1)



JAVA Sample Code

XML-RPC Example (NX and NXT series controllers)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
*
* @author Aurora Multimedia Corp.
*
*/
public class WaciXmlRpcSample {
Socket socket;

BufferedReader reader;
PrintWriter writer;

public static void main(String[] args) {
WaciXmlRpcSample object = new WaciXmlRpcSample();
object.go();

}

public void go() {
try {


//Change the ip address for your waci
String ipAddressForWaci = "192.168.1.100";

//Create a socket client
socket = new Socket(ipAddressForWaci, 2996);
InputStreamReader streamReader = new InputStreamReader(
socket.getInputStream());
reader = new BufferedReader(streamReader);
writer = new PrintWriter(socket.getOutputStream());

System.out.println("networking established");

//Create a seperate thread to listen to the socket connection
Thread readerThread = new Thread(new IncomingReader());
readerThread.start();

//Send the xml to get variable values by their names
getVariableValuesByName();

//Send the xml to toggle relay
toggleRelay();

} catch (IOException e) {

e.printStackTrace();
}
}

private void toggleRelay() {
// This method will cause relay port 1 to toggle
String portNumber = "1";
String xmlStringToSend = "<?xml version=’1.0’ standalone=’yes’?>"
+ ""
+ "Version 2.0"
+ "1"
+ "Relay_Toggle" + ""
+ "" + portNumber + "" + "
"
+ "true" + "
";
System.out.println("Client sent: " + xmlStringToSend);
writer.write(xmlStringToSend);
writer.flush();
System.out.println("Asked Waci to toggle relay port 1!");

}

private void getVariableValuesByName() {
// You have to have these variables in your Event Manager or waci
// won’t understand your xml and give an error!
// Seperate variable names with a comma.
System.out.println("Get the variable values for var1 and var2");
String strVarNames = "var1,var2";
String xmlStringToSend = "<?xml version=’1.0’ standalone=’yes’?>"
+ ""
+ "Version 2.0"
+ "1"
+ "GetVariableValuesByName"
+ ""
+ "" + strVarNames + ""
+ "
"
+ "true"
+ "
";
System.out.println("Client sent: " + xmlStringToSend);
writer.write(xmlStringToSend);
writer.flush();

}

class IncomingReader implements Runnable {
StringBuilder sb;

public void run() {
String message;
try {
while ((message = reader.readLine()) != null) {
if (message
.equals("<?xml version=\"1.0\" standalone=\"yes\"?>")) {
sb = new StringBuilder();
sb.append(message);
} else if (message.endsWith("")) {
sb.append(message);
sb.delete(0, sb.length());

}
System.out.println("client read " + message);
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
Download Full JAVA Source Code


HTTP RPC Example (All controllers)
import java.net.*;
import java.io.*;

class HttpPost
{
public static void main(String args[])

{
if (args.length < 1)
{
System.err.println
("usage: java HttpPost [WACI_IP_Address]");
System.exit(1);
}
try
{
// Construct Date
String data = URLEncoder.encode("method", "UTF-8") + "=" + URLEncoder.encode("Relay_On", "UTF-8");
data += "&" + URLEncoder.encode("param1", "UTF-8") + "=" + URLEncoder.encode("1", "UTF-8");

URL url = new URL("http", args[0], 80, "/RPC");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());

// Send Data
wr.write(data);
wr.flush();

// Get the reponse
BufferedReader rd =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}
catch (MalformedURLException e)
{ System.err.println(e.toString()); }
catch (IOException e)
{ System.err.println(e.toString()); }
}
}

Download Full JAVA Source Code


C# Sample Code

Here is how you would do an HTTP Post using C#

public static string HttpPost(string URI, string Parameters)
{
System.Net.WebRequest request = System.Net.WebRequest.Create(URI);
//request.Proxy = new System.Net.WebProxy(ProxyString, true);//Not needed
//Add these, as we're doing a POST
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.Timeout = 7000;
byte [] bytes = System.Text.Encoding.Default.GetBytes(Parameters);
request.ContentLength = bytes.Length;
System.IO.Stream os = request.GetRequestStream();
os.Write (bytes,0,bytes.Length); //Push it out there
os.Close ();
System.Net.WebResponse resp = request.GetResponse();
//resp.Close();

if (resp == null) return null;
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream(), System.Text.Encoding.Default);
string i = sr.ReadToEnd().Trim();
sr.Close();
resp.Close();
return i;
}


VisualBasic / VB.NET

SUBMITTED BY: Chris Kolkman
Precision Data Products, Inc.

In an effort to make it easier to program for the WACI in programming languages that support the .NET framework I have been working on a custom control. This control models the behavior of the WACI Flash Demo project available.

Download it here

Once the control has been added to your form accessing it is simple.
Example: Waci.General.GetFrameworkVersion() 'returns the framework version of the WACI.

All examples are done using VB.NET, but the control can be used in other languages as well. A demo program is included in the zip file, along with all of the source code. HTML help files have also been included. Just about every function listed in the WACI manual has been added to the control.
©2017 Aurora Multimedia
Privacy Policy
|
Contact Us