sarnau / MMMMobileAlerts

Documentation about the protocols of ELV Mobile Alerts sensors plus a node MQTT gateway and an Arduino UDP gateway
46 stars 27 forks source link

Sensor ID error: ID0e #47

Closed Iminet72 closed 1 year ago

Iminet72 commented 1 year ago

I received the identification error ID0e and was able to solve it with the following line of code (sensors.js). I hope I didn't make a mistake anywhere.

// ID0e: Temperature/Humidity sensor function Sensor_ID0e() {} util.inherits(Sensor_ID0e, SensorBase); Sensor_ID0e.prototype.bufferSize = function() { return 8; } Sensor_ID0e.prototype.transmitInterval = function() { return 7; } Sensor_ID0e.prototype.generateJSON = function(buffer) { return { 'temperature': [ this.convertTemperature(buffer.readUInt16BE(0)) , this.convertTemperature(buffer.readUInt16BE(4))], 'humidity': [ this.convertHumidity(buffer.readUInt16BE(2)) , this.convertHumidity(buffer.readUInt16BE(6))] }; } Sensor_ID0e.prototype.debugString = function() { return this.temperaturAsString(this.json.temperature[0])

Iminet72 commented 1 year ago

It seems that the humidity reading does not work because of the decimal point

Iminet72 commented 1 year ago

This was the final solution:

// Main function .. this.IDxx = buffer.toString('hex', 6, 7)

....----

SensorBase.prototype.convertHumidity = function(value) { // values: 0%…100% if (this.IDxx=="0e") { // console.log(this.IDxx) return this.round((value & 0x7ff) * 0.1, 1); }else { return value & 0x7f ; } ...---- // ID0e: Temperature/Humidity sensor function Sensor_ID0e() {} util.inherits(Sensor_ID0e, SensorBase); Sensor_ID0e.prototype.bufferSize = function() { return 8; } Sensor_ID0e.prototype.transmitInterval = function() { return 7; } Sensor_ID0e.prototype.generateJSON = function(buffer) { return { 'temperature': [ this.convertTemperature(buffer.readUInt16BE(0)) , this.convertTemperature(buffer.readUInt16BE(5))], 'humidity': [ this.convertHumidity((buffer.readUInt16BE(2))) , this.convertHumidity((buffer.readUInt16BE(7)))] }; } Sensor_ID0e.prototype.debugString = function() { return this.temperaturAsString(this.json.temperature[0])

GreatSUN commented 1 year ago

This was the final solution:

// Main function .. this.IDxx = buffer.toString('hex', 6, 7)

....----

SensorBase.prototype.convertHumidity = function(value) { // values: 0%…100% if (this.IDxx=="0e") { // console.log(this.IDxx) return this.round((value & 0x7ff) * 0.1, 1); }else { return value & 0x7f ; } ...---- // ID0e: Temperature/Humidity sensor function Sensor_ID0e() {} util.inherits(Sensor_ID0e, SensorBase); Sensor_ID0e.prototype.bufferSize = function() { return 8; } Sensor_ID0e.prototype.transmitInterval = function() { return 7; } Sensor_ID0e.prototype.generateJSON = function(buffer) { return { 'temperature': [ this.convertTemperature(buffer.readUInt16BE(0)) , this.convertTemperature(buffer.readUInt16BE(5))], 'humidity': [ this.convertHumidity((buffer.readUInt16BE(2))) , this.convertHumidity((buffer.readUInt16BE(7)))] }; } Sensor_ID0e.prototype.debugString = function() { return this.temperaturAsString(this.json.temperature[0]) + ' ' + this.humidityAsString(this.json.humidity[0]) }

Would you mind to push it into the code and request a merge?

Iminet72 commented 1 year ago

Sorry I may have messed up the submission. I'm not very experienced in this kind of thing

Iminet72 commented 1 year ago

The solution works, it's included in the code