NEWS
ProJet LevelJet Script Problem!
-
Hallo zusammen,,
ich habe hier ein Script für meinen LevelJET das leider nicht geht.
- Werden die Werte nicht Aktualisiert
- Kann ich die werte nicht mir meinem Mediola auslesen, hier führ verwende ich Simple API
Bitte helft mir :/ verzweifelt
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 && options.ip) { this._ip = options.ip; } if (options && 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 >= 24) { me.raw = str.toString('hex') me.data = me._parse(me.raw); me._on.forEach((elem) => { if (typeof (elem) === "function") { elem(me.data); } }); } }); }; LevelJet.prototype.on = function (name, callback) { if (name && 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) => { 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) << 8); //Distanz Lesekopf Daten.Druck = parseToInt(chunks[1], lowByte) + (parseToInt(chunks[1], hiByte) << 8); Daten.Fuellhoehe = parseToInt(chunks[2], lowByte) + (parseToInt(chunks[2], hiByte) << 8); //Füllmenge, muss mit 10 multiplziert werden Daten.Liter = (parseToInt(chunks[3], lowByte) + (parseToInt(chunks[3], hiByte) << 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) << 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) => { 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();Danke
-
Hallo zusammen,,
ich habe hier ein Script für meinen LevelJET das leider nicht geht.
- Werden die Werte nicht Aktualisiert
- Kann ich die werte nicht mir meinem Mediola auslesen, hier führ verwende ich Simple API
Bitte helft mir :/ verzweifelt
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 && options.ip) { this._ip = options.ip; } if (options && 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 >= 24) { me.raw = str.toString('hex') me.data = me._parse(me.raw); me._on.forEach((elem) => { if (typeof (elem) === "function") { elem(me.data); } }); } }); }; LevelJet.prototype.on = function (name, callback) { if (name && 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) => { 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) << 8); //Distanz Lesekopf Daten.Druck = parseToInt(chunks[1], lowByte) + (parseToInt(chunks[1], hiByte) << 8); Daten.Fuellhoehe = parseToInt(chunks[2], lowByte) + (parseToInt(chunks[2], hiByte) << 8); //Füllmenge, muss mit 10 multiplziert werden Daten.Liter = (parseToInt(chunks[3], lowByte) + (parseToInt(chunks[3], hiByte) << 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) << 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) => { 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();Danke
Das ist das funktionierende Script :D
const net = require('net'); function LevelJet(options) { this.data = {}; this.raw = ''; this._on = []; this._client = null; this._ip = "localhost"; this._port = 23; if (options && options.ip) { this._ip = options.ip; } if (options && 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, () => { console.log('Connected to ', me._ip, ":", me._port); }); me._client.on('close', () => { me.disconnect(); me.connect(); }); me._client.on('data', data => { 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) => { if (typeof (elem) === "function") { elem(me.data); } }); } else if (me.raw.length > 24) { me.raw = '' } }); }; LevelJet.prototype.on = function(name, callback) { if (name && name === "data") { this._on.push(callback); } }; LevelJet.prototype.disconnect = function() { this._client.destroy(); }; const parseToInt = (chunk, byteIndex) => parseInt(chunk[byteIndex], 16); LevelJet.prototype._parse = arr => { const perChunk = 2; let chunks = arr.match(/.{1,2}/g).reduce((prev, current, i) => { 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) << 8); //Distanz Lesekopf Daten.Druck = parseToInt(chunks[1], lowByte) + (parseToInt(chunks[1], hiByte) << 8); Daten.Fuellhoehe = parseToInt(chunks[2], lowByte) + (parseToInt(chunks[2], hiByte) << 8); //Füllmenge, muss mit 10 multiplziert werden Daten.Liter = (parseToInt(chunks[3], lowByte) + (parseToInt(chunks[3], hiByte) << 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) << 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) => { 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();
Hey! Du scheinst an dieser Unterhaltung interessiert zu sein, hast aber noch kein Konto.
Hast du es satt, bei jedem Besuch durch die gleichen Beiträge zu scrollen? Wenn du dich für ein Konto anmeldest, kommst du immer genau dorthin zurück, wo du zuvor warst, und kannst dich über neue Antworten benachrichtigen lassen (entweder per E-Mail oder Push-Benachrichtigung). Du kannst auch Lesezeichen speichern und Beiträge positiv bewerten, um anderen Community-Mitgliedern deine Wertschätzung zu zeigen.
Mit deinem Input könnte dieser Beitrag noch besser werden 💗
Registrieren Anmelden