<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[ProJet LevelJet Script Problem!]]></title><description><![CDATA[<p dir="auto">Hallo zusammen,,</p>
<p dir="auto">ich habe hier ein Script für meinen LevelJET das leider nicht geht.</p>
<ol>
<li>Werden die Werte nicht Aktualisiert</li>
<li>Kann ich die werte nicht mir meinem Mediola auslesen, hier führ verwende ich Simple API</li>
</ol>
<p dir="auto">Bitte helft mir :/ <em>verzweifelt</em></p>
<pre><code>const net = require('net');

function LevelJet(options) {
	this.data = {};
	this.raw = '';
	this._on = [];
    this._client = null;

	this._ip = "192.168.0.65";
	this._port = 10001;

	if (options &amp;&amp; options.ip) {
		this._ip = options.ip;
	}
	if (options &amp;&amp; options.port) {
		this._port = options.port;
	}

}

LevelJet.prototype.connect = function () {
	let me = this;
	me._client = new net.Socket();

	me._client.connect(me._port, me._ip, function () {
		console.log('Connected to ' + me._ip + ":" + me._port);
	});
	me._client.on('close', function () {
		me.disconnect();
		me.connect();
	});
	me._client.on('data', function (str) {
		if (str.length &gt;= 24) {
			me.raw = str.toString('hex')
			me.data = me._parse(me.raw);
			me._on.forEach((elem) =&gt; {
				if (typeof (elem) === "function") {
					elem(me.data);
				}
			});
		}
	});
};

LevelJet.prototype.on = function (name, callback) {
	if (name &amp;&amp; name === "data") {
		this._on.push(callback);
	}
};

LevelJet.prototype.disconnect = function () {
	this._client.destroy();
};

function parseToInt(chunk, byteIndex) {
	return parseInt(chunk[byteIndex], 16);
}

LevelJet.prototype._parse = function (arr) {
	const perChunk = 2;
	let chunks = arr.match(/.{1,2}/g).reduce((prev, current, i) =&gt; {
		const ch = Math.floor(i / perChunk);
		prev[ch] = [].concat((prev[ch] || []), current);
		return prev
	}, []);
	const lowByte = 0, hiByte = 1;
	let Daten = {};
	Daten.Geraetekennung = parseToInt(chunks[0], lowByte) + (parseToInt(chunks[0], hiByte) &lt;&lt; 8);
	//Distanz Lesekopf
	Daten.Druck = parseToInt(chunks[1], lowByte) + (parseToInt(chunks[1], hiByte) &lt;&lt; 8);
	Daten.Fuellhoehe = parseToInt(chunks[2], lowByte) + (parseToInt(chunks[2], hiByte) &lt;&lt; 8);
	//Füllmenge, muss mit 10 multiplziert werden
	Daten.Liter = (parseToInt(chunks[3], lowByte) + (parseToInt(chunks[3], hiByte) &lt;&lt; 8)) * 10;
	//Prozenzangabe Füllmenge und Zustand Auslauf, nur 1 Byte
	Daten.Prozent = parseToInt(chunks[4], lowByte);
	Daten.Zustand = parseToInt(chunks[4], hiByte);
	Daten.KontrollByte = parseToInt(chunks[5], lowByte) + (parseToInt(chunks[5], hiByte) &lt;&lt; 8);
	return Daten;
};


createState("Gerätekennung");
createState("Druck");
createState("Liter");
createState("Füllhöhe");
createState("Prozent");
createState("Zustand");
createState("KontrollByte");

let levelJet = new LevelJet({ip: "192.168.0.65", port: 10001});

levelJet.on("data", (Daten) =&gt; {
    console.log(Daten);
    setState('Gerätekennung', Daten.Geraetekennung, true);
    setState('Druck', Daten.Druck, true);
    setState('Liter', Daten.Liter, true);
    setState('Füllhöhe', Daten.Fuellhoehe, true);
    setState('Prozent', Daten.Prozent, true);
    setState('Zustand', Daten.Zustand, true);
    setState('KontrollByte', Daten.KontrollByte, true);
});


levelJet.connect();
</code></pre>
<p dir="auto">Danke</p>
]]></description><link>https://forum.iobroker.net/topic/31462/projet-leveljet-script-problem</link><generator>RSS for Node</generator><lastBuildDate>Sun, 17 May 2026 20:27:49 GMT</lastBuildDate><atom:link href="https://forum.iobroker.net/topic/31462.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 23 Mar 2020 04:34:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ProJet LevelJet Script Problem! on Tue, 22 Dec 2020 21:02:36 GMT]]></title><description><![CDATA[<p dir="auto">Das ist das funktionierende Script :D</p>
<pre><code>const net = require('net');

function LevelJet(options) {
	this.data = {};
	this.raw = '';
	this._on = [];
	this._client = null;

	this._ip = "localhost";
	this._port = 23;

	if (options &amp;&amp; options.ip) {
		this._ip = options.ip;
	}
	if (options &amp;&amp; options.port) {
		this._port = options.port;
	}

}

LevelJet.prototype.connect = function () {
	let me = this;
	me._client = new net.Socket();

	me._client.connect(me._port, me._ip, () =&gt; {
		console.log('Connected to ', me._ip, ":", me._port);
	});
	me._client.on('close', () =&gt; {
		me.disconnect();
		me.connect();
	});
	me._client.on('data', data =&gt; {
		me.raw += data.toString('hex');
		console.log('me.raw length ' + me.raw.length);
		if(me.raw.length === 24) {
			me.data = me._parse(me.raw);
			me.raw = '';
			me._on.forEach((elem) =&gt; {
				if (typeof (elem) === "function") {
					elem(me.data);
				}
			});
		} else if (me.raw.length &gt; 24) {
			me.raw = ''
		}
	});
};

LevelJet.prototype.on = function(name, callback) {
	if (name &amp;&amp; name === "data") {
		this._on.push(callback);
	}
};

LevelJet.prototype.disconnect =  function() {
	this._client.destroy();
};

const parseToInt = (chunk, byteIndex) =&gt; parseInt(chunk[byteIndex], 16);


LevelJet.prototype._parse = arr =&gt; {
    const perChunk = 2;
	let chunks = arr.match(/.{1,2}/g).reduce((prev, current, i) =&gt; {
		const ch = Math.floor(i / perChunk);
		prev[ch] = [].concat((prev[ch] || []), current);
		return prev
	}, []);
	const lowByte = 0, hiByte = 1;
	let Daten = {};
	Daten.Geraetekennung = parseToInt(chunks[0], lowByte) + (parseToInt(chunks[0], hiByte) &lt;&lt; 8);
	//Distanz Lesekopf
	Daten.Druck = parseToInt(chunks[1], lowByte) + (parseToInt(chunks[1], hiByte) &lt;&lt; 8);
	Daten.Fuellhoehe = parseToInt(chunks[2], lowByte) + (parseToInt(chunks[2], hiByte) &lt;&lt; 8);
	//Füllmenge, muss mit 10 multiplziert werden
	Daten.Liter = (parseToInt(chunks[3], lowByte) + (parseToInt(chunks[3], hiByte) &lt;&lt; 8)) * 10;
	//Prozenzangabe Füllmenge und Zustand Auslauf, nur 1 Byte
	Daten.Prozent = parseToInt(chunks[4], lowByte);
	Daten.Zustand = parseToInt(chunks[4], hiByte);
	Daten.KontrollByte = parseToInt(chunks[5], lowByte) + (parseToInt(chunks[5], hiByte) &lt;&lt; 8);
	return Daten;
};

let levelJet = new LevelJet({
                            ip: "192.168.0.65",
                            port: 10001
                            });

createState("javascript.0.Wasser.Gerätekennung");
createState("javascript.0.Wasser.Druck");
createState("javascript.0.Wasser.Liter");
createState("javascript.0.Wasser.Füllhöhe");
createState("javascript.0.Wasser.Prozent");
createState("javascript.0.Wasser.Zustand");
createState("javascript.0.Wasser.KontrollByte");

levelJet.on("data", (Daten) =&gt; {
    console.log(Daten);
    setState('javascript.0.Wasser.Gerätekennung', Daten.Geraetekennung, true);
    setState('javascript.0.Wasser.Druck', Daten.Druck, true);
    setState('javascript.0.Wasser.Liter', Daten.Liter, true);
    setState('javascript.0.Wasser.Füllhöhe', Daten.Fuellhoehe, true);
    setState('javascript.0.Wasser.Prozent', Daten.Prozent, true);
    setState('javascript.0.Wasser.Zustand', Daten.Zustand, true);
    setState('javascript.0.Wasser.KontrollByte', Daten.KontrollByte, true);
});


levelJet.connect();
</code></pre>
]]></description><link>https://forum.iobroker.net/post/542388</link><guid isPermaLink="true">https://forum.iobroker.net/post/542388</guid><dc:creator><![CDATA[acidsubway]]></dc:creator><pubDate>Tue, 22 Dec 2020 21:02:36 GMT</pubDate></item></channel></rss>