-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOS0285.js
60 lines (50 loc) · 1.83 KB
/
BOS0285.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const axios = require('axios');
// Function to get sensor value from a specified parameterIndex and subindex
const getSensorValue = async (parameterIndex, subindex) => {
const baseUrl = 'http://10.10.13.62/iolink/v1/devices/master1port1/parameters';
const url = `${baseUrl}/${parameterIndex}/subindices/${subindex}/value?format=byteArray`;
try {
// Use axios to make the HTTP request
const response = await axios.get(url);
// Check if the response is OK (status code 200-299)
if (response.status !== 200) {
throw new Error(`HTTP error! status: ${response.status}`);
}
// Get the data from the response
const data = response.data;
console.log(`Fetched data for parameterIndex ${parameterIndex}, subindex ${subindex}:`, data.value);
return data.value;
} catch (error) {
console.error('Fetch error:', error.message);
return [];
}
};
// Function to initialize the myscada application
const init = async (myscada) => {
try {
// Get the inclination status from the sensor
const inclinationStatus = await getSensorValue(8530, 0);
console.log('Inclination Status:', inclinationStatus);
// Prepare options for writing tags to myscada
const options = {};
options['name'] = 'BOS0285';
options['values'] = {};
options['values']['inclinationStatus'] = inclinationStatus;
// Write the tags to myscada
myscada.writeTags(options, (err, data) => {
if (err) {
console.error('Write error:', err);
} else {
console.log('Write successful:', data);
}
});
// Export the fetched values
exports.messageBOS0285 = {
inclinationStatus
};
} catch (error) {
console.error('Initialization error:', error.message);
}
};
// Export the init function
exports.init = init;