Skip to content

Commit

Permalink
added testfunction for device info reading
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaus Weber committed Nov 18, 2024
1 parent 333087d commit 6afdcfc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
2 changes: 1 addition & 1 deletion doc/dl-lesen.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ int main(int argc, char *argv[])

/* IP-Zugriff - IP-Adresse und Port sind manuell gesetzt!!! */
if (ip_zugriff && !usb_zugriff)
{
{
sr = start_socket();
if (sr > 1)
{
Expand Down
17 changes: 4 additions & 13 deletions io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,8 @@
"uk": "Адаптер ioBroker для читання входів і виходів контролера UVR16xx від Technische Alternative за допомогою BL-NET.",
"zh-cn": "用于通过 BL-NET 读取 Technische Alternative 的 UVR16xx 控制器的输入和输出的 ioBroker 适配器。"
},
"authors": [
"Klaus Weber <klausatweberesprit@gmail.com>"
],
"keywords": [
"BL-NET",
"UVR1611",
"UVR16x2",
"solar",
"BUSO",
"Technische",
"Alternative"
],
"authors": ["Klaus Weber <klausatweberesprit@gmail.com>"],
"keywords": ["BL-NET", "UVR1611", "UVR16x2", "solar", "BUSO", "Technische", "Alternative"],
"licenseInformation": {
"type": "free",
"license": "MIT"
Expand All @@ -73,7 +63,8 @@
"connectionType": "local",
"dataSource": "poll",
"adminUI": {
"config": "json"
"config": "json",
"custom": "json"
},
"supportCustoms": true,
"eraseOnUpload": true,
Expand Down
53 changes: 53 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class Uvr16xxBlNet extends utils.Adapter {
*/
async testRead() {
try {
await this.testFunction();

const stateValues = await this.fetchStateValuesFromDevice();
const units = {};

Expand Down Expand Up @@ -318,6 +320,56 @@ class Uvr16xxBlNet extends utils.Adapter {
}, pollInterval); // Poll every pollInterval milliseconds
}

async testFunction() {
const client = new net.Socket();
const ipAddress = this.config.ip_address; // IP address from the config
const port = this.config.port; // Port from the config
// Definieren der Konstanten
const VERSIONSABFRAGE = 0x81;
const FWABFRAGE = 0x82;
const MODEABFRAGE = 0x21;

const sendCommand = async (command) => {
return new Promise((resolve, reject) => {
client.write(Buffer.from([command]), (err) => {
if (err) {
return reject(err);
}
client.once("data", (data) => {
resolve(data);
});
});
});
};

client.connect(port, ipAddress, async () => {
try {
let data;

// Senden der Versionsabfrage
data = await sendCommand(VERSIONSABFRAGE);
this.log.info("Vom DL erhalten Version: " + data.toString("hex"));

// Senden der Firmware-Versionsabfrage
data = await sendCommand(FWABFRAGE);
this.log.info("Vom DL erhalten Version FW: " + data.toString("hex"));

// Senden der Modus-Abfrage
data = await sendCommand(MODEABFRAGE);
this.log.info("Vom DL erhalten Modus: " + data.toString("hex"));
} catch (error) {
this.log.error("Error during communication with device: " + error);
} finally {
client.end();
}
});

client.on("error", (err) => {
this.log.error("Connection error: " + err);
});
}


/**
* Fetches state values from the IoT device.
* @returns {Promise<Object>} - A promise that resolves with the state values.
Expand Down Expand Up @@ -357,6 +409,7 @@ class Uvr16xxBlNet extends utils.Adapter {
reject(new Error("Invalid response from device"));
}
} else {
this.logHexDump(data); // Log hex dump of the data;
client.destroy(); // Close the connection
reject(new Error("Unexpected response from device"));
}
Expand Down

0 comments on commit 6afdcfc

Please sign in to comment.