Problems initializing and using websocket_json

Begonnen von AlxDmr, 18 März 2015, 10:08:39

Vorheriges Thema - Nächstes Thema

AlxDmr

Hello,
I am using websocket/JSON to communicate with Fhem. I encounter a strange behavior on loading and when usding it. The library I use is the one done by ntruchsess that I downloaded from here :
https://github.com/ntruchsess/fhem-mirror/raw/websockets/fhem/FHEM/00_websocket.pm
https://github.com/ntruchsess/fhem-mirror/raw/websockets/fhem/FHEM/10_websocket_json.pm


I installed Protocol::WebSocket and JSON using cpan and added following lines to fhem.cfg :
define wsPort websocket 8080 global
define wsPort_json websocket_json


When loading, fhem trace the following lines related to websocket:
2015.03.18 08:57:52 3: wsPort: port 8080 opened
2015.03.18 08:57:52 2: Error messages while initializing FHEM: configfile: 0 0


Using telnet, I can see that websocket_json is not properly loaded (I suppose) as STATE is ??? :
fhem> list wsPort_json
Internals:
   IODev      wsPort
   NAME       wsPort_json
   NOTIFYDEV
   NR         7
   NTFY_ORDER 50-wsPort_json
   STATE      ???
   TYPE       websocket_json
   resource   /
   Typesubscriptions:
   websockets:
     HASH(0x1da4680)
Attributes:
   IODev      wsPort



Now the behaviour is a bit strange, I do not know where the problem come from. When I use the javascript example provided by ntruchsess at :
https://raw.githubusercontent.com/ntruchsess/fhem-mirror/websockets/fhem/www/fhem_websocket.js
https://github.com/ntruchsess/fhem-mirror/blob/websockets/fhem/www/websocket.html

the connection is done, the list of items is sent to the browser but I never receive any event.
I was wondering what kind of tests I could perform in order to find more clues about the problem.
I use enOcean sensors such as a switch, thermometers etc. When I press the switch, I can see that readings are updated in the dedicated fhem webpage however nothing come to the browser... :(

AlxDmr

#1
I did another test, in telnet I entered :
define bob notify EnO_switch_00258ED6 attr EnO_switch_00258ED6 dummy 0
on the webpage of the switch, the attribute dummy was not present.
After pressing the switch and refreshing the webpage, it appeared in the attribute list, so I think that the event is triggered by Fhem but not catched by websocket module, don't know why and how to check that.
I also went to the eventmonitor webpage and I can see all the events being displayed when I press the switch.

Also, in the logs, I get :
2015.03.18 11:55:27 2: Error messages while initializing FHEM: configfile: 0 0 statefile: Usage: setstate <name> <state> where <name> is a single device name, a list separated by komma (,) or a regexp. See the devspec section in the commandref.html for details.  Usage: setstate <name> <state> where <name> is a single device name, a list separated by komma (,) or a regexp. See the devspec section in the commandref.html for details.

gaggi

I just tested the websocket Module myself.
I get the same Error Message at Startup when the websocket_json module is loaded (configfile: 0 0) and the websocket server only sends a message when FHEM triggers an action. I'm not getting any websocket messages from status updates of bidirectional EnOcean actors, my KS300 weather station, the logitech harmony hub, fs20 remotes and so on...
As a new father i didnt have much spare time at this moment but i will try to look for the error this weekend.

AlxDmr

Hello,
actually I "solved" the problem. There are some modification to do in the source code (server side) and also when subscribing from Javascript.
I added debugged version of source code here (actually I only debugged 10_websocket_json.pm, I did not tested the pseudo telnet over websocket protocol) :
https://github.com/AlexDmr/tacthab/tree/master/FHEM
In the javascript file provided by ntruchness, parameters must be transmited to the server, so default regexp should be set, leading to this new definition of subscribeEvent :
fhem.subscribeEvent = function(id,type,name,changed) {
fhem.sendCommand({
command: 'subscribe',
arg:     id,
type:    type || '.*',
name:    name || '.*',
changed: changed || '.*'
});
};