Looking into the option of things control throw url read and set

For now my system is from ISYGLT, a wired system. Old but works, hard to manage setup and control, not really made to control by smartphone tablet
However I can set and read the status of the home by network address.

so i can write a script to set and get status of a light
in what language and where to place the script.

the below script [Array] has all information I need to set and read the status of the on/off dim and rgb lights in the house.

var x + "", resources = [
// Name '',		k1		k2		k3		k4		k5		k6		k7
['name',			'type',	'M',    	'M-b',	'B',   	'B-b',	'M-B',	'B-B'],
['Beam',			'au',         10,		1,		0,		7,		0,		0],
['KitchenLED',		'dim',	10,		2,		0,		6,		107,  	9],
['Mirror',			'dim',	10,		3,		0,		5,		108, 	10],
['Diner',			'au',	        10,		4,		0,		4,		0,		0],
['Bar',			'au',	        10,		5,		0,		3,		0,		0],
['LedBar',			'dim',	10,		6,		0,		2,		106, 	8],
['Corridor',		'au',   	10,		7,		0,		1,		0,		0],
['Outsidelight',	        'au',	        10,		8,		0,		0,		0,		0],
['KitchenRGB',		'rgb',	11,		1,		0,		7,		100,	        2],
['LivingRGB',		'rgb',	11,		2,		0,		6,		103,	        5],
['Meterkast Deur',	'deur',	0,		0,		0,		0,		0,		0],
['Haldeur',		'deur',	0,		0,		0,		1,		0,		0],
['Voordeur',		'deur',	0,		0,		0,		2,		0,		0]];
//-----------------------------------------------------------
//k1	type
//k2	Memory bank turn off/on
//k3 	bit of memorybank K2
//k4	byte 0/15 read status
//k5	bit of byte k4, 0 tot 7 
//k6	set byte address, dim/rgb 0-255
//k7	read byte for dim/rgb
//----------------------------------------------------------

for example to toggle the ‘KitchenLED’ I load the following url ‘http://192.168.1.13/cgi-bin/mc?t=3&m=10&b=2
to read the status of the ‘KitchenLED’ I look at a string i can load, (see below) byte 0 bit 6 (1)
10001010,00000000,00000000,00000000,01111000,00000000,00000000,00000000,01101111,01011111,00101000,0000,000,00000000,00001010,00000000,00000000

Some pointers is all i am looking for, surely not a complete code snipped.

Since you can send commands using http, you can easily use the HTTP Binding: https://www.openhab.org/addons/bindings/http1/#item-configuration

Now this is harder…
I assume that this string of numbers is the result of another http call to the web interface of your ISYGLT system… correct? (how does the http request look like by the way?)

Here you would need the HTTP Binding and a transformation service to extract the 6th (or 7th?) character from the big string: https://www.openhab.org/addons/transformations/regex/#examples

1 Like

It is, I have written a java script page to get that string,

var y="", z, q="", arr = [];
readPC();

function readPC(pageNr = 1) {
  var xhttp;
  xhttp=new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
		var x = xhttp.responseText 
		// select string top.r1[string] from source
		var x = x.slice((x.search("r1")+4),(x.search("r2")-8));
		//window.AppInventor.setWebViewString(x);
			var z = x.split(","); // built nice array from it
			// add colomn name to arr0
			arr[0] = [0,1,2,3,4,5,6,7];
			// split 2byte into 1 byte and load up
			for (var i=0; i < 8; i++){
				y += toBinary(z[i]);
				arr[(2*i)+1] = y.substring(0, 8).split("");
				arr[(2+(i*2))] = y.substring(8, 16).split("");
			}
	for (var col = 0; col < arr[0].length; col++) {
	for (var row = 0; row < arr.length; row++) {
	if (row == 0){
		q+=	'"' + arr[row][col] + '","';
		} else {
		q+=	arr[row][col] + " ";
		}
			if (row == arr.length-1){
		q+=	arr[row][col] + '"\n';
		}
	}
}
		//window.AppInventor.setWebViewString(q);
		      document.getElementById("demo").innerHTML = y;

    }
  }
  xhttp.open("GET", 'http://192.168.1.13/cgi-bin/readpc?p=' + pageNr, true);
  xhttp.send();
}
//readPC(window.AppInventor.getWebViewString());
function toBinary(nr) {
	// 2byte to 16bit, add zero's if needed
	return parseInt(nr).toString(2).padStart(16, '0');
}

But first things first, i’ll read up to the http binding,
getting the write part of the string isn’t the hardest thing, i think, telling openhab to load the string if (not sure what to write now(thing/item)) is loaded on a gui

1 Like

Oke now i am lost
I have 1 item,

Switch DEMOSW "test switch" { http=">[ON:GET:http://192.168.1.13/cgi-bin/mc?t=1&m=10&b=1 >[OFF:GET:http://192.168.1.13/cgi-bin/mc?t=2&m=10&b=1]" }

and the following errors

2018-11-06 16:11:49.615 [ome.event.ItemCommandEvent] - Item 'DEMOSW' received command ON

KNIP

omg small typo,

Switch DEMOSW "test switch" { http=">[ON:GET:http://192.168.1.13/cgi-bin/mc?t=1&m=10&b=1**`]`** >[OFF:GET:http://192.168.1.13/cgi-bin/mc?t=2&m=10&b=1]" }

Oke, I am getting familiar with openhab, after reading and watching youtube.
putty, visual studio samba mounts all set to go.

it’s a call to http://IP-nr-ISYGLT/cgi-bin/readpc?p=1
source code of that side

<html><head><title>r</title><meta http-equiv="expires" content="0">
<script>
function run()
{if(n==top.rfrcount){top.update_anzvalues();top.start_read_values(top.anzreptime);}}
</script></head><body>
<script>
top.r1=[34816,0,30720,0,28555,10240,16,0];
top.r2=[0,0,0,0,0,0,16,0];
top.r3=[0,0,0,0,0,0,45,0];
top.SichPageNr=1;
top.SichPageTyp=2;
n=0;
run();
</script>
</body>
</html>

the above mentioned site reads that page and parse the source code to get the string top.r1 out.
The ISYGLT webserver runs java, no php ajax I can put files .html .js on it

So if i want to get the state of things out i need to call a (function or maybe a persistence) script to pass the status to my things?

The question is, if OH needs the state of things, can it call a function/script?

Yes, of course: take a look at the Exec Binding: https://www.openhab.org/addons/bindings/exec/

but wait… since you can customize your own js, why don’t you continue working with the http binding?

You can have a http bound item that can send and receive data to your js script running on the ISYGLT webserver.

Getting your head around the OH system is hard but i have a feeling i am getting somewhere.

the state of my things, are in this string " 10001010,00000000,00000000,00000000,01111000,00000000,00000000,00000000,01101111,01011111,00101000,0000,000,00000000,00001010,00000000,00000000"
it comes from this string “[34816,0,30720,0,28555,10240,16,0]”
I can parse it it anyway we would like it.
The big question is, parse it to, ??? xml json
Do the parsing on the ISYGLT system or download it to my RPI3 do it there.
there are so many ways, options (Can’t see the forest throw all the tree’s)

Over time the whole ISYGLT will be replaced with other hardware (wired) But for sure, setting OH now up to take the place as the master instead of the ISYGLT MA-IP-2 is the way to go, It will force me to learn the OH way, and what i have seen of it i like IT

If you can do it in 1 shot (within your javascript running on the web server of the ISYGLT), I would recommend to do it there and provide a json as a response to the http request that OH2 will issue to query the status of an object.

Then, it will be easy for OH2 to read it and parse the resulting json in order to update the state of a http bound Item.

If you grab the “raw” result, download it to your rPi3 using a script and then process it in OH2 it will be slower, more complicated and more prone to faults (I think).

edit: I don’t know how “powerful” is the ISYGLT System and if it will be able to handle lots of parsing activity. You need to check this aspect in order to avoid ISYGLT system overload.

From here: https://www.light-technology.nl/sites/default/files/MA-IP-2.pdf I see that it has very limited resources

Just to clarify:

You execute a call to http://IP-nr-ISYGLT/cgi-bin/readpc?p=1

Source of 1st script:
<html><head><title>r</title><meta http-equiv="expires" content="0">
<script>
function run()
{if(n==top.rfrcount){top.update_anzvalues();top.start_read_values(top.anzreptime);}}
</script></head><body>
<script>
top.r1=[34816,0,30720,0,28555,10240,16,0];
top.r2=[0,0,0,0,0,0,16,0];
top.r3=[0,0,0,0,0,0,45,0];
top.SichPageNr=1;
top.SichPageTyp=2;
n=0;
run();
</script>
</body>
</html>

and this results to the following string:

[34816,0,30720,0,28555,10240,16,0]

Then, you use another javascript to “transform” the string above to:

Source of 2nd script:
var y="", z, q="", arr = [];
readPC();

function readPC(pageNr = 1) {
  var xhttp;
  xhttp=new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
		var x = xhttp.responseText 
		// select string top.r1[string] from source
		var x = x.slice((x.search("r1")+4),(x.search("r2")-8));
		//window.AppInventor.setWebViewString(x);
			var z = x.split(","); // built nice array from it
			// add colomn name to arr0
			arr[0] = [0,1,2,3,4,5,6,7];
			// split 2byte into 1 byte and load up
			for (var i=0; i < 8; i++){
				y += toBinary(z[i]);
				arr[(2*i)+1] = y.substring(0, 8).split("");
				arr[(2+(i*2))] = y.substring(8, 16).split("");
			}
	for (var col = 0; col < arr[0].length; col++) {
	for (var row = 0; row < arr.length; row++) {
	if (row == 0){
		q+=	'"' + arr[row][col] + '","';
		} else {
		q+=	arr[row][col] + " ";
		}
			if (row == arr.length-1){
		q+=	arr[row][col] + '"\n';
		}
	}
}
		//window.AppInventor.setWebViewString(q);
		      document.getElementById("demo").innerHTML = y;

    }
  }
  xhttp.open("GET", 'http://192.168.1.13/cgi-bin/readpc?p=' + pageNr, true);
  xhttp.send();
}
//readPC(window.AppInventor.getWebViewString());
function toBinary(nr) {
	// 2byte to 16bit, add zero's if needed
	return parseInt(nr).toString(2).padStart(16, '0');
}
10001010,00000000,00000000,00000000,01111000,00000000,00000000,00000000,01101111,01011111,00101000,0000,000,00000000,00001010,00000000,00000000

correct? (I am not sure that I got the flow right)

this is a page that i can’t edit, but it holds the needed info. in it’s source code. The page itself is blank (empty) it’s part of the ISYGLT web interface (Ugly) and so 1990 wink
before I made the transition to OH I was working on an Android app to set and get the status of the lights.

That’s a page that i wrote to parse and reveal the string, it it’s uploaded to the root of the webpage of ISYGLT master, so the string could be displayed on the web page and in the webpage title. had to do that because of
CORS policy: No ‘Access-Control-Allow-Origin’

So a call from OH to http://IP-nr-ISYGLT/cgi-bin/readpc?p=1 is all we need to get the state of all the things in the house if we can read the source of that page.

Oh sweet DIM that triangle to hide/reveal code

Learning had to edit this in to the post

I don’t know how much I can help further… I am not a hard core coder :slight_smile:
I believe that you will make it work and maybe others can offer some ideas here