Personal tools
The Open Lighting Project has moved!

We've launched our new site at www.openlighting.org. This wiki will remain and be updated with more technical information.

Difference between revisions of "OLA JSON API"

From wiki.openlighting.org

Jump to: navigation, search
(Example JSON)
 
m (Examples: Add a Get Perl example)
 
(One intermediate revision by the same user not shown)
Line 12: Line 12:
  
 
my $response = $ua->post('http://127.0.0.1:9090/set_dmx',
 
my $response = $ua->post('http://127.0.0.1:9090/set_dmx',
   {u => 0, d => join(",",(0,1,2,3,4,5,6))}
+
   {u => 1, d => join(",",(0,10,20,30,40,50,60,255))}
 
);
 
);
  
 
if ($response->is_success) {
 
if ($response->is_success) {
 
   print $response->decoded_content;
 
   print $response->decoded_content;
 +
} else {
 +
  die $response->status_line;
 +
}</pre>
 +
 +
====curl====
 +
<pre>curl -d u=1 -d d=0,10,20,30,40,50,60,255 http://localhost:9090/set_dmx</pre>
 +
 +
===Get a universe of DMX===
 +
====Perl====
 +
<pre>#!/usr/bin/perl -w
 +
 +
use JSON::XS;
 +
use LWP::UserAgent;
 +
 +
my $ua = LWP::UserAgent->new;
 +
$ua->timeout(5);
 +
 +
my $url = "http://localhost:9090/get_dmx?u=1";
 +
 +
my $response = $ua->get($url);
 +
 +
if ($response->is_success) {
 +
  my $data  = decode_json($response->decoded_content);
 +
 +
  print "DMX Data: " . join(", ", @{$data->{dmx}}) . "\n";
 
} else {
 
} else {
 
   die $response->status_line;
 
   die $response->status_line;
 
}</pre>
 
}</pre>

Latest revision as of 08:25, 21 April 2018

Browse to /help on your OLA webserver to see the available commands (append ?help=1 to the end of a command for more info in newer versions of OLA)

Examples

Set a universe of DMX

Perl

#!/usr/bin/perl -w

use LWP::UserAgent;

my $ua = LWP::UserAgent->new;
$ua->timeout(5);

my $response = $ua->post('http://127.0.0.1:9090/set_dmx',
  {u => 1, d => join(",",(0,10,20,30,40,50,60,255))}
);

if ($response->is_success) {
  print $response->decoded_content;
} else {
  die $response->status_line;
}

curl

curl -d u=1 -d d=0,10,20,30,40,50,60,255 http://localhost:9090/set_dmx

Get a universe of DMX

Perl

#!/usr/bin/perl -w

use JSON::XS;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new;
$ua->timeout(5);

my $url = "http://localhost:9090/get_dmx?u=1";

my $response = $ua->get($url);

if ($response->is_success) {
  my $data  = decode_json($response->decoded_content);

  print "DMX Data: " . join(", ", @{$data->{dmx}}) . "\n";
} else {
  die $response->status_line;
}