-
Notifications
You must be signed in to change notification settings - Fork 9
The changes we talked about in issue #23 #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 9 commits
983d357
26c197d
00b7932
b8170d3
2a1087c
0c9bcf2
43b3ac0
448f07f
8c07bd8
e079774
6c72d35
cf6a115
e145d3f
cd93621
3f5d777
492317e
4bd1205
7a7fb59
4efaef6
1b93405
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| FROM node:slim | ||
| LABEL maintainer="Holger Imbery <contact@connectedobjects.cloud>" \ | ||
| version="1.1a" \ | ||
| description="HM2MQTT (hm2mqtt.js) dockerized version of https://github.com/hobbyquaker/hm2mqtt.js" | ||
|
|
||
| RUN npm config set unsafe-perm true && npm install -g hm2mqtt | ||
| COPY . /node | ||
|
|
||
| RUN cd /node && \ | ||
| npm install | ||
|
|
||
| EXPOSE 2126 | ||
| EXPOSE 2127 | ||
| ENTRYPOINT ["hm2mqtt"] | ||
|
|
||
| ENTRYPOINT [ "node", "/node/index.js" ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| FROM hypriot/rpi-node:slim | ||
| LABEL maintainer="Holger Imbery <contact@connectedobjects.cloud>" \ | ||
| version="1.1a" \ | ||
| description="HM2MQTT (hm2mqtt.js) dockerized version of https://github.com/hobbyquaker/hm2mqtt.js" | ||
| FROM arm32v7/node:slim | ||
|
|
||
| RUN npm config set unsafe-perm true | ||
| RUN npm install -g hm2mqtt | ||
| COPY . /node | ||
|
|
||
| RUN cd /node && \ | ||
| npm install | ||
|
|
||
| EXPOSE 2126 | ||
| EXPOSE 2127 | ||
| ENTRYPOINT ["hm2mqtt"] | ||
|
|
||
| ENTRYPOINT [ "node", "/node/index.js" ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,12 +129,14 @@ mqtt.on('message', (topic, payload) => { | |
| const parts = topic.split('/'); | ||
| if (parts.length >= 4 && parts[1] === 'set') { | ||
| // Topic <name>/set/<channel>/<datapoint> | ||
| const channel = parts.slice(2, parts.length - 1).join('/'); | ||
| var channel = parts.slice(2, parts.length - 1).join('/'); | ||
| if ( config.replaceColons ) channel = channel.replace("_",":"); | ||
| const datapoint = parts[parts.length - 1]; | ||
| rpcSet(channel, 'VALUES', datapoint, payload); | ||
| } else if (parts.length >= 5 && parts[1] === 'paramset') { | ||
| // Topic <name>/paramset/<channel>/<paramset>/<datapoint> | ||
| const channel = parts.slice(2, parts.length - 2).join('/'); | ||
| var channel = parts.slice(2, parts.length - 2).join('/'); | ||
| if ( config.replaceColons ) channel = channel.replace("_",":"); | ||
| const paramset = parts[parts.length - 2]; | ||
| const datapoint = parts[parts.length - 1]; | ||
| rpcSet(channel, paramset, datapoint, payload); | ||
|
|
@@ -295,27 +297,20 @@ function rpcType(payload, paramset) { | |
| break; | ||
| case 'FLOAT': | ||
| val = parseFloat(val); | ||
| if (val < paramset.MIN) { | ||
| val = paramset.MIN; | ||
| } else if (val > paramset.MAX) { | ||
| val = paramset.MAX; | ||
| } | ||
| val = {explicitDouble: val}; | ||
| /* JavaScript doesn't seperate integer and float/double types, so in JavaScript there's only "Number". | ||
| * However, the XML-RPC library needs to determine whether to wrap the value in <i4>22</i$> or <double>22</double>, | ||
| * see [list of allowed datatypes](https://ws.apache.org/xmlrpc/types.html). | ||
| * | ||
| * node-xmlrpc does this with an `if ( value % 1 == 0)`, see [serializer.js:188](https://github.com/baalexander/node-xmlrpc/blob/d9c88c4185e16637ed5a22c1b91c80e958e8d69e/lib/serializer.js#L188) | ||
| * | ||
| * homematic-xmlrpc introduced an object like `{explicitDouble: val}`. | ||
| * | ||
| * The CCU2 seems to accept <string>22</string> messages and does a string to int/float conversion itself - currently in testing. | ||
| */ | ||
| val = String(val); | ||
| break; | ||
| case 'ENUM': | ||
| if (typeof val === 'string') { | ||
| if (paramset.ENUM && (paramset.ENUM.indexOf(val) !== -1)) { | ||
| val = paramset.ENUM.indexOf(val); | ||
| } | ||
| } | ||
| // eslint-disable-line no-fallthrough | ||
| case 'INTEGER': | ||
| val = parseInt(val, 10); | ||
| if (val < paramset.MIN) { | ||
| val = paramset.MIN; | ||
| } else if (val > paramset.MAX) { | ||
| val = paramset.MAX; | ||
| } | ||
| break; | ||
| case 'STRING': | ||
| val = String(val); | ||
|
|
@@ -357,12 +352,23 @@ function rpcSet(name, paramset, datapoint, payload) { | |
|
|
||
| const val = rpcType(payload, ps); | ||
|
|
||
| log.debug('rpc', iface, '> setValue', [address, datapoint, val]); | ||
| rpcClient[iface].methodCall('setValue', [address, datapoint, val], err => { | ||
| if (err) { | ||
| log.error(err); | ||
| } | ||
| }); | ||
| if ( paramset == "VALUES" ) { | ||
| log.debug('rpc', iface, '> setValue', [address, datapoint, val]); | ||
| rpcClient[iface].methodCall('setValue', [address, datapoint, val], err => { | ||
| if (err) { | ||
| log.error(err); | ||
| } | ||
| }); | ||
| } else { | ||
| const set = {}; | ||
| set[datapoint] = val; | ||
| log.debug('rpc', iface, '> putParamset', [address, paramset, set]); | ||
| rpcClient[iface].methodCall('putParamset', [address, paramset, set], err => { | ||
| if (err) { | ||
| log.error(err); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| function rega(script, callback) { | ||
|
|
@@ -635,9 +641,9 @@ process.on('SIGTERM', stop); | |
| function initIface(name, protocol) { | ||
| let url; | ||
| if (protocol === 'binrpc') { | ||
| url = 'xmlrpc_bin://' + (config.initAddress || config.listenAddress) + ':' + config.binrpcListenPort; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why remove this? listenAdress is needed if hm2mqtt runs in a vm with nat networking or in a container that exposes the listenPort to the hosts interface
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's actually the other way around. In a Docker environment you can and will have multiple network interfaces. It's therefore a good idea to bind the socket to The line from this comment creates the url-string that is sent to the CCU. If you don't specify the You can leave the line in here but combined with the change from line 44, this makes no semantical sense anymore. |
||
| url = 'xmlrpc_bin://' + (config.initAddress) + ':' + config.binrpcListenPort; | ||
| } else { | ||
| url = 'http://' + (config.initAddress || config.listenAddress) + ':' + config.listenPort; | ||
| url = 'http://' + (config.initAddress) + ':' + config.listenPort; | ||
| } | ||
| const params = [url, 'hm2mqtt_' + name]; | ||
| log.info('rpc', name, '> init', params); | ||
|
|
@@ -831,7 +837,9 @@ const rpcMethods = { | |
| ps = {}; | ||
| } | ||
|
|
||
| const topic = config.name + '/status/' + (names[params[1]] || params[1]) + '/' + params[2]; | ||
| var channel = (names[params[1]] || params[1]); | ||
| if ( config.replaceColons ) channel = channel.replace(":","_"); | ||
| const topic = config.name + '/status/' + channel + '/' + params[2]; | ||
|
|
||
| let payload = {val: params[3], ts, lc: changes[key], hm: {ADDRESS: params[1]}}; | ||
| if (ps.UNIT && ps.UNIT !== '""') { | ||
|
|
@@ -842,7 +850,8 @@ const rpcMethods = { | |
| } | ||
| } | ||
| if (ps.TYPE === 'ENUM') { | ||
| payload.hm.ENUM = ps.VALUE_LIST[params[3]]; | ||
| payload.val = ps.VALUE_LIST[params[3]]; | ||
|
||
| payload.hm.VALUE_LIST = ps.VALUE_LIST; | ||
| } | ||
| payload = JSON.stringify(payload); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... I'm asking myself if this works with the binrpc protocol also...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question, because I never checked.
Funny thing is - it does 😄
I started the script a few weeks ago with my most recent branch. It used
xmlrpc_binas protocol and yeah.. works since then. For e.g.hm/set/NEQ0881133_4/SET_TEMPERATUREaccepts either19and19.5doing the string conversion.