0
Good morning, I need your help. I am receiving data from the serial port "/dev/ttyUSB0", my goal" is to recover some information ( temperature and humidity ) and replace in the object enoceanRecords
.
// Constants
const DEFAULT_SERIAL_PORT = "/dev/ttyUSB0";
// Dependancies
var fs = require('fs');
var vm = require('vm');
var events = require('events');
var cache = require('./plugins_cache.js');
var util = require('util');
var pk = require('node-enocean')();
// Type de données
var enoceanRecords = {
Humidity: { 'value': '', 'type': 'TEXT', 'unit': '' },
Temperature: { 'value': '', 'type': 'INTEGER', 'unit': 'A' }
};
// Includes
vm.runInThisContext(fs.readFileSync(__dirname + "/" + "plugins_table.js"));
var table = new Table();
// Class
var PluginEnocean = function () {
this.infos = { name: "enocean",
version: "0.0.1"
};
};
PluginEnocean.prototype.query = function () {
return this.infos;
}
PluginEnocean.prototype.init = function (config) {
var options = config.get('plugin:enocean');
var path = DEFAULT_SERIAL_PORT;
if(options !== undefined) {
if(options['path'] !== undefined) {
path = options['path'];
}
}
// Open serial port
console.log(path);
pk.listen(path);
// Set table name
table.setName(this.infos['name']);
// Collect data
pk.on('data', function (data) {
// =====================
var temp = enoceanRecords['Temperature'];
var humid = enoceanRecords['Humidity'] ;
var valTemp = (data['values'])[1];
var valHumid = (data['values'])[0];
temp['value'] = valTemp['value'];
temp['type'] = valTemp['type'];
temp['unit'] = valTemp['unit'];
humid['value'] = valHumid['value'];
humid['type'] = valHumid['type'];
humid['unit'] = valHumid['unit'];
//=====================
var uuid = data['senderId'] ;
for(key in enoceanRecords) {
table.setRecord(key, enoceanRecords[key]);
}
// Feed data
if(uuid !== undefined) {
table.setUuid(uuid);
table.setRecord(key, enoceanRecords[key]);
table.setStamp();
cache.push(table);
}
});
};
PluginEnocean.prototype.run = function () {
};
PluginEnocean.prototype.exit = function () {
};
var enocean = module.exports = new PluginEnocean();
Good morning, I need your help! I am receiving data from the serial port "/dev/ttyUSB0", my goal" is to recover some information ( temperature and humidity ) and replace in the object "enoceanRecords" !!
– PululuK
Which is the line where that mistake is making?
– Miguel
@Miguel the error is in these two lines var valTemp = (date['values']); var valHumid = (date['values'])[0];
– PululuK
In the line before the error make a
console.log(data['values']);
and see what you print on the console, I think this is not getting the values as it should– Miguel
@Miguel the program is working 100% when I test on firefox console for example, only it doesn’t work on "nodejs"... The behavior is not the same in the "nodejs" to which it is due ?!
– PululuK
Do you run Ode through the terminal? See what you print there
– Miguel
@Miguel, as I used to say, Script goes very well outside the "nodejs" but when I call : "sudo nodejs Scriptcolletiodedonnes.js " ça marche pas ! ( does not work )
– PululuK
Okay, I was just wondering what
data['values']
store, I suspect that when the flame sudo Nod it will not have the value/values you are thinking– Miguel
@Miguel this is + or - the format of the date I receive :
data = { loadFromBuffer: [Function],
 senderId: '018a75ba',
 raw: '0088860a',
 sensor:
 { id: '018a75ba',
 eep: 'a5-04-01',
 manufacturer: 'ENOCEAN_GMBH',
 title: 'New Temperature and Humidity Sensor',
 desc: 'I\'m a new sensor...',
 eepFunc: 'Temperature and Humidity Sensor',
 eepType: 'Range 0°C to +40°C and 0% to 100%',
 last: [ [Object], [Object] ] },
 values:
 [ { type: 'humidity', unit: '%rF', value: 54.400000000000006 },
 { type: 'temperature', unit: '°C', value: 21.44 } ] };
– PululuK
I think I’ve already noticed the bug friend. paying on that showed => data for the 1st obj of the array
data['values']
:data.values[0].type = "humidity"
,data.values[0].value = 54.400
,data.values[0].unit = "%rF"
– Miguel
@Miguel what’s the mistake bro? Exclaim better bro ?
– PululuK
If what is being stored in
data
That’s what you showed me, so I was having a hard time accessing the values I wanted– Miguel
@Miguel what would be the correct procedure ? Merci !!
– PululuK
But in fact it seems to me that that’s what you’re doing in your code. Here you are: https://jsfiddle.net/9d23pqrb/ . Now the important thing is to know if
data
has even the data in this format that showed me– Miguel
@Miguel thank you very much, It is worth noting that the data are not coming in the format that I was guessing ! I will take a look then give a sign ! ... Have a good afternoon @ Miguel... Merci Beaucoup !
– PululuK
Hi @Miguel once again I came by to thank you, I just solved the problem... Logic was right, the error was in the "format" of the data !! GRATEFUL AND ONCE AGAIN GRATEFUL !
– PululuK
Nothing. I’m glad you solved
– Miguel
@James in peace bro !
– PululuK