wutu / pimatic-mqtt

MQTT plugin for Pimatic
https://pimatic.org/plugins/pimatic-mqtt/
GNU Affero General Public License v3.0
9 stars 13 forks source link

attributes dht22 temperature/humidity sensor #10

Closed capitalfuse closed 8 years ago

capitalfuse commented 8 years ago

I think this MQTT plugin become the core technology for Pimatic. Thanks for plugin designers.

I updated pimatic-mqtt plugin to latest version, my esp-12e connected with dht-22 published only numbers of temp and humid for each topic like the following;

{ "name": "ESP12 with rgb led", "id": "esp12", "class": "MqttSensor", "attributes": [ { "name": "temperature", "topic": "myhome/firstfloor/office/esp12/dht22/temperature", "type": "number", "unit": "°C", "acronym": "DHT-22-Temperature" }, { "name": "humidity", "topic": "myhome/firstfloor/office/esp12/dht22/humidity", "type": "number", "unit": "%", "acronym": "DHT-22-Humidity" } ] },

I checked whether these numbers published precisely on ubuntu terminal by mosquitto_sub command, but pimatic shows no values. (each value is 0). Any hints do you have?

in this file, devices/mqtt-sensor.coffee It seems that below codes don't work?

try data = flatten JSON.parse(message) if typeof data is 'object' then for key, value of data if key == attr.name if attr.type == 'number' if attr.division @emit attr.name, Number("#{value}") / attr.division else @emit attr.name, Number("#{value}") else @emit attr.name, "#{value}"

wutu commented 8 years ago

Hi, thanks for the compliment, I appreciate it. It looks like a bug, you're using Pimatic v0.9?

capitalfuse commented 8 years ago

Thanks for your quick reply. My Pimatic works under below conditions. pimatic version 0.8.104 ---> changed 0.9.8, but still no data. node v4.4.3 npm v2.15.1 Now I will try to tweak the code in mqtt-sensor.coffee, but I am a beginner for coffescript.

wutu commented 8 years ago

https://github.com/hughsk/flat/issues/45 if you're not using JSON in payload, just remove "flatten" out of line 'try flatten JSON.parse data = (message)'. It is strange that you run Pimatic 8 with Node 4. I got an error when I use Node 4 and Pimatic 9 beta.

capitalfuse commented 8 years ago

Thanks for your advice, I will try it.

I installed latest pimatic by following. Stop pimatic service and...

  1. cd pimatic-app
  2. sudo rm -r node_modules/pimatic
  3. npm install https://github.com/capitalfuse/pimatic.git#v0.9.x (in case of pimatic 0.8.x under node v4, same procedure)

So did I get errors, but pimatic seems to be working with no problem.

---> errors refer to dependencies of plugins installed, need to modify pimatic version(+node and npm version) in package.json in plugin modules.

capitalfuse commented 8 years ago

I adopted the Arduino JSON library. Published the dht22 values by Json decoding. Works great!

wutu commented 8 years ago

Fixed in 0.8.10 https://github.com/wutu/pimatic-mqtt/commit/e93cbeae928193eab3d5aabcd3c1c4fafaef9283