wburgers / Open-Zwave-Socket-Server

Open-Zwave Socket Server
http://willemburgers.nl/zwave/open-zwave-socket-server
9 stars 8 forks source link

OZWSS is not working with the latest version of OZW #4

Closed wburgers closed 9 years ago

wburgers commented 9 years ago

In the latest version of OZW, there has been a rewrite of parts of the API. OZWSS is not updated to work with these changes yet. Since March, I have a full time job after graduating from the university. Therefore I don't have much time anymore to work on things like this. I do plan to upgrade to the latest version soon.

In the meantime, you can do a checkout of revision 444b990 of OZW. This is one of the latests commits before the branch merge.

Check back here to see if the code incompatibility of OZWSS is resolved.

hellracer commented 9 years ago

Hi Willem,

Thanks for picking up the work of Thomas, I hope if you don't mind asking does your server socket code is fully compatible with what originally Thomas had made?

wburgers commented 9 years ago

Hi there :-),

I like it when people are interested in my projects, so you can always ask me anything!

No, the server code is not completely the same. Do you have a custom client in PHP or something like that? If so, there are a few changes in the commands you can send to the server. I removed the "DEVICE" command, because it works similar to "SETNODE". These two are merged together and I only kept the "SETNODE" command.

In the latest version of the server, I included JSON. Responses from server to client are sent in JSON format.

Finally I enhanced the server with some scheduling/timers. If you have sunrise and sunset timers in your client for example, you may want to move them to the server for better synchronization between multiple clients.

I think that these are the most important changes. Please see the commandlist.md file for more information about the commands to send to the server.

If you have any more questions, feel free to ask them anytime!

P.S. I'm currently working on the Polymer client, to update it to Polymer version 1.0 I'm almost done (see the custom components repo's). When I'm done, I'll work on updating the server to work with the latest version of Open-Zwave.

hellracer commented 9 years ago

Hi Willem, First of all thanks for picking up the project, I was able to compile your Socket Server component it works great but I just want to ask some few question a.) since websocket is a bidirectional technology I think this is pretty much preferred because we don't poll the information right it can be push to the websocket client right? please let me know if this was the case. b.) I noticed that openzwave-server bails out from time to time without giving a hint as to why this happen? Do we have a daemonized mode instead on running on a foreground process?  right now I used screen because I don't know how to do it, I don't want to send this to background using conventional openzwave-server & c.) Do you intended to design the socket component in the future if time permits using multiple thread just like any webserver? d.) any command or hint you could give me on how I can pull a detail device information hooked on the controller? I think the JSON output below is insufficient because it doesn't return the actual device model or brand. and lastly can you reformat the JSON output without using space on the keys e.g Application Version becomes Application_Version? 

JSON Result from ALIST command stdClass Object(    [command] => ALIST    [nodes] => Array        (            [0] => stdClass Object                (                    [ID] => 3                    [LastSeen] => Fri 17 Jul 00:38                    [Location] => Living Room                    [Name] => Living Room Outlet 1                    [Type] => Binary Power Switch                    [Values] => stdClass Object                        (                            [Acked Frames] => 182                            [Application Version] => 3.32                            [Frame Count] => 182                            [Library Version] => 6                            [Powerlevel] => Normal                            [Protection] => Unprotected                            [Protocol Version] => 3.40                            [Report] => False                            [Set Powerlevel] => False                            [Switch] => True                            [Switch All] => On and Off Enabled                            [Test] => False                            [Test Node] => 0                            [Test Powerlevel] => Normal                            [Test Status] => Failed                            [Timeout] => 0                        )                 )         ) )

Sorry for my poor english :) and thanks a lot and keep up the good work!!!

Best regards, Ronald

 Anyone who has never made a mistake has never tried anything new

--Albert Einstein

 On Tuesday, July 7, 2015 5:31 PM, Willem Burgers <notifications@github.com> wrote:

Hi there :-),I like it when people are interested in my projects so you can always ask me anything!No, the server code is not completely the same. Do you have a custom client in PHP or something like that? If so, there are a few changes in the commands you can send to the server. I removed the "DEVICE" command, because it works similar to "SETNODE". These two are merged together and I only kept the "SETNODE" command.In the latest version of the server, I included JSON. Responses from server to client are sent in JSON format.Finally I enhanced the server with some scheduling/timers. If you have sunrise and sunset timers in your client for example, you may want to move them to the server for better synchronization between multiple clients.I think that these are the most important changes. Please see the commandlist.md file for more information about the commands to send to the server.If you have any more questions, feel free to ask them anytime!P.S. I'm currently working on the Polymer client, to update it to Polymer version 1.0 I'm almost done (see the custom components repo's). When I'm done, I'll work on updating the server to work with the latest version of Open-Zwave.— Reply to this email directly or view it on GitHub.

hellracer commented 9 years ago

Hi Wilem, Sorry to bother you on point #b I think it has something to do with segfault on the cp210x driver, by the way I'm running on newest ubuntu 14.04 i've seen some similar posting on google, I hope if you don't mind asking what ubuntu version you are on ? I'm going to try centos 5 or centos 6 just to narrow this, i'm really frustrated openzwave-server keep on crashing 10 minutes tops, though no really traffic is going on, thanks in advance :)

Best regards, Ronald Anyone who has never made a mistake has never tried anything new

--Albert Einstein

 On Friday, July 17, 2015 3:20 PM, Ronald Chan <loloski@yahoo.com> wrote:

Hi Willem, First of all thanks for picking up the project, I was able to compile your Socket Server component it works great but I just want to ask some few question a.) since websocket is a bidirectional technology I think this is pretty much preferred because we don't poll the information right it can be push to the websocket client right? please let me know if this was the case. b.) I noticed that openzwave-server bails out from time to time without giving a hint as to why this happen? Do we have a daemonized mode instead on running on a foreground process?  right now I used screen because I don't know how to do it, I don't want to send this to background using conventional openzwave-server & c.) Do you intended to design the socket component in the future if time permits using multiple thread just like any webserver? d.) any command or hint you could give me on how I can pull a detail device information hooked on the controller? I think the JSON output below is insufficient because it doesn't return the actual device model or brand. and lastly can you reformat the JSON output without using space on the keys e.g Application Version becomes Application_Version? 

JSON Result from ALIST command stdClass Object(    [command] => ALIST    [nodes] => Array        (            [0] => stdClass Object                (                    [ID] => 3                    [LastSeen] => Fri 17 Jul 00:38                    [Location] => Living Room                    [Name] => Living Room Outlet 1                    [Type] => Binary Power Switch                    [Values] => stdClass Object                        (                            [Acked Frames] => 182                            [Application Version] => 3.32                            [Frame Count] => 182                            [Library Version] => 6                            [Powerlevel] => Normal                            [Protection] => Unprotected                            [Protocol Version] => 3.40                            [Report] => False                            [Set Powerlevel] => False                            [Switch] => True                            [Switch All] => On and Off Enabled                            [Test] => False                            [Test Node] => 0                            [Test Powerlevel] => Normal                            [Test Status] => Failed                            [Timeout] => 0                        )                 )         ) )

Sorry for my poor english :) and thanks a lot and keep up the good work!!!

Best regards, Ronald

 Anyone who has never made a mistake has never tried anything new

--Albert Einstein

 On Tuesday, July 7, 2015 5:31 PM, Willem Burgers <notifications@github.com> wrote:

Hi there :-),I like it when people are interested in my projects so you can always ask me anything!No, the server code is not completely the same. Do you have a custom client in PHP or something like that? If so, there are a few changes in the commands you can send to the server. I removed the "DEVICE" command, because it works similar to "SETNODE". These two are merged together and I only kept the "SETNODE" command.In the latest version of the server, I included JSON. Responses from server to client are sent in JSON format.Finally I enhanced the server with some scheduling/timers. If you have sunrise and sunset timers in your client for example, you may want to move them to the server for better synchronization between multiple clients.I think that these are the most important changes. Please see the commandlist.md file for more information about the commands to send to the server.If you have any more questions, feel free to ask them anytime!P.S. I'm currently working on the Polymer client, to update it to Polymer version 1.0 I'm almost done (see the custom components repo's). When I'm done, I'll work on updating the server to work with the latest version of Open-Zwave.— Reply to this email directly or view it on GitHub.

wburgers commented 9 years ago

Hi,

Glad tot hear you like the improvements I made. I'll answer your questions point by point. A) you are completely right about the websockets. Websockets are great to push new data to the clients (that are available). There is no need for polling. That is why I included websockets and the polymer client. B) That sounds really weird. I run my server for weeks without crashing. I'm using Ubuntu 14.04 on an Odroid-X. I indeed use screen to make sure that it keeps on running even when I end the SSH session. Maybe you could try to use debug mode to see where the program crashes. I'm unfortunately unable to check it out myself, because I'm on a holiday. There is no demonized version yet, but that could be a nice feature. C) What do you mean specifically with this question? I already made it such that the socket part is multi threaded. It should allow multiple socket clients. (I believe up to 5 clients can connect simultaneously. It is defined in socket.h somewhere.) D) what information would you like to see? The ALIST command outputs all the details that open-zwave keeps about a device if I'm remembering correctly. If there is anything missing in ALIST that you are sure is available in open-zwave, I'm happy to add the info to ALIST.

Sure the spaces can be removed. That will be part of the changes I need to make to make sure ozwss works with the latest version of ozw, which this issue is about ;-).

Hope this answers all your questions.

Best regards, Willem

P.S. your English is fine, don't worry about it. Where are you from?

hellracer commented 9 years ago

HI Willem, Sorry for bothering and spoiling your holidays :) anyway I'm from the Philippines, ok please let me describe the crashes i'm seeing they are in two folds.

1) the server socket application  just bailed out for no apparent reason and i'm being dropped on the shell. b.) the server socket application still respond when i manually on or off one of my device, I can still telnet on port 60004 but issuing command like ALIST just hang and I don't see JSON output anymore. when this happen I can see on dmesg that the socket program encountering sefgault, i'm going to capture it sometimes the message was on dmesg sometimes it's not there. by the way I'm using aeon labs z-stick S2 with recent firmware version.

Best regards, Ronald

 Anyone who has never made a mistake has never tried anything new

--Albert Einstein

 On Saturday, July 18, 2015 4:17 AM, Willem Burgers <notifications@github.com> wrote:

Hi,Glad tot hear you like the improvements I made. I'll answer your questions point by point. A) you are completely right about the websockets. Websockets are great to push new data to the clients (that are available). There is no need for polling. That is why I included websockets and the polymer client. B) That sounds really weird. I run my server for weeks without crashing. I'm using Ubuntu 14.04 on an Odroid-X. I indeed use screen to make sure that it keeps on running even when I end the SSH session. Maybe you could try to use debug mode to see where the program crashes. I'm unfortunately unable to check it out myself, because I'm on a holiday. There is no demonized version yet, but that could be a nice feature. C) What do you mean specifically with this question? I already made it such that the socket part is multi threaded. It should allow multiple socket clients. (I believe up to 5 clients can connect simultaneously. It is defined in socket.h somewhere.) D) what information would you like to see? The ALIST command outputs all the details that open-zwave keeps about a device if I'm remembering correctly. If there is anything missing in ALIST that you are sure is available in open-zwave, I'm happy to add the info to ALIST.Sure the spaces can be removed. That will be part of the changes I need to make to make sure ozwss works with the latest version of ozw, which this issue is about ;-).Hope this answers all your questions.Best regards, WillemP.S. your English is fine, don't worry about it. Where are you from?— Reply to this email directly or view it on GitHub.

hellracer commented 9 years ago

HI Willem, I modify your server socket code and tweak it a bit to include Manufacturer Name/Product Name and Product ID, please see attached diff file, I'm not a real coder  please bare with me refactor it if needs to be :), Please see attached JSON result from ALIST command

 "command":"ALIST",    "nodes":[       {          "ID":3,          "LastSeen":"Sat 18 Jul 22:55",          "Location":"Living Room",          "Manufacturer":"GE",          "Name":"Living Room Outl",          "ProductId":"3031",          "ProductName":"45603 Plugin Appliance Module",          "Type":"Binary Power Switch",          "Values":{             "Acked Frames":"48",             "Application Version":"3.32",             "Frame Count":"100",             "Library Version":"6",             "Powerlevel":"Normal",             "Protection":"Unprotected",             "Protocol Version":"3.40",             "Report":"False",             "Set Powerlevel":"False",             "Switch":"False",             "Switch All":"On and Off Enabled",             "Test":"False",             "Test Node":"0",             "Test Powerlevel":"Normal",             "Test Status":"Failed",             "Timeout":"0"          }       }

Best regards, Ronald Chan

 Anyone who has never made a mistake has never tried anything new

--Albert Einstein

 On Saturday, July 18, 2015 8:01 AM, Ronald Chan <loloski@yahoo.com> wrote:

HI Willem, Sorry for bothering and spoiling your holidays :) anyway I'm from the Philippines, ok please let me describe the crashes i'm seeing they are in two folds.

1) the server socket application  just bailed out for no apparent reason and i'm being dropped on the shell. b.) the server socket application still respond when i manually on or off one of my device, I can still telnet on port 60004 but issuing command like ALIST just hang and I don't see JSON output anymore. when this happen I can see on dmesg that the socket program encountering sefgault, i'm going to capture it sometimes the message was on dmesg sometimes it's not there. by the way I'm using aeon labs z-stick S2 with recent firmware version.

Best regards, Ronald

 Anyone who has never made a mistake has never tried anything new

--Albert Einstein

 On Saturday, July 18, 2015 4:17 AM, Willem Burgers <notifications@github.com> wrote:

Hi,Glad tot hear you like the improvements I made. I'll answer your questions point by point. A) you are completely right about the websockets. Websockets are great to push new data to the clients (that are available). There is no need for polling. That is why I included websockets and the polymer client. B) That sounds really weird. I run my server for weeks without crashing. I'm using Ubuntu 14.04 on an Odroid-X. I indeed use screen to make sure that it keeps on running even when I end the SSH session. Maybe you could try to use debug mode to see where the program crashes. I'm unfortunately unable to check it out myself, because I'm on a holiday. There is no demonized version yet, but that could be a nice feature. C) What do you mean specifically with this question? I already made it such that the socket part is multi threaded. It should allow multiple socket clients. (I believe up to 5 clients can connect simultaneously. It is defined in socket.h somewhere.) D) what information would you like to see? The ALIST command outputs all the details that open-zwave keeps about a device if I'm remembering correctly. If there is anything missing in ALIST that you are sure is available in open-zwave, I'm happy to add the info to ALIST.Sure the spaces can be removed. That will be part of the changes I need to make to make sure ozwss works with the latest version of ozw, which this issue is about ;-).Hope this answers all your questions.Best regards, WillemP.S. your English is fine, don't worry about it. Where are you from?— Reply to this email directly or view it on GitHub.

wburgers commented 9 years ago

I'm sorry but I can't see the diff file. Not in my email and not on github. Maybe you can fork the project, add your changes there and create a pull-request on github. This way I can see the changes even here on my holiday ;-).

Best regards, Willem

hellracer commented 9 years ago

 Hi Willem, Good day, the changes was so trivial let me create a github account first to create a fork and submit a pull request, for the time being please see attached diff

+++ /home/rpchan/Open-Zwave-Socket-Server/Server/Main.cpp    2015-07-18 22:53:35.998779764 +0800 @@ -51,7 +51,6 @@  #include "ValueList.h"  #include "ValueShort.h"

 #include "ValueString.h"

 //External classes and libs  #include "Socket.h"  #include "SocketException.h" @@ -1269,6 +1268,9 @@              for(list<NodeInfo>::iterator it = g_nodes.begin(); it != g_nodes.end(); ++it) {                  NodeInfo* nodeInfo = it;                  std::string nodeType = Manager::Get()->GetNodeType(g_homeId, nodeInfo->m_nodeId); +                std::string manufacturerName = Manager::Get()->GetNodeManufacturerName(g_homeId, nodeInfo->m_nodeId);     +                std::string productName = Manager::Get()->GetNodeProductName(g_homeId, nodeInfo->m_nodeId); +                std::string productId = Manager::Get()->GetNodeProductId(g_homeId, nodeInfo->m_nodeId);                  if(nodeType == "Static PC Controller" || nodeType == "") {                      continue;                  } @@ -1278,6 +1280,9 @@                  if(nodeName.size() == 0) {                      nodeName = "Undefined";                  } +                node["Manufacturer"] = manufacturerName; +                node["ProductName"] = productName; +                node["ProductId"] = productId;                  node["Name"] = nodeName;                  node["ID"] = nodeInfo->m_nodeId;                  node["Location"] = Manager::Get()->GetNodeLocation(g_homeId, nodeInfo->m_nodeId); @@ -2215,4 +2220,4 @@          alarm((alarmList.front().alarmtime - now));          alarmset = true;      } -} \ No newline at end of file +}

Anyone who has never made a mistake has never tried anything new

--Albert Einstein

 On Tuesday, July 7, 2015 5:31 PM, Willem Burgers <notifications@github.com> wrote:

Hi there :-),I like it when people are interested in my projects so you can always ask me anything!No, the server code is not completely the same. Do you have a custom client in PHP or something like that? If so, there are a few changes in the commands you can send to the server. I removed the "DEVICE" command, because it works similar to "SETNODE". These two are merged together and I only kept the "SETNODE" command.In the latest version of the server, I included JSON. Responses from server to client are sent in JSON format.Finally I enhanced the server with some scheduling/timers. If you have sunrise and sunset timers in your client for example, you may want to move them to the server for better synchronization between multiple clients.I think that these are the most important changes. Please see the commandlist.md file for more information about the commands to send to the server.If you have any more questions, feel free to ask them anytime!P.S. I'm currently working on the Polymer client, to update it to Polymer version 1.0 I'm almost done (see the custom components repo's). When I'm done, I'll work on updating the server to work with the latest version of Open-Zwave.— Reply to this email directly or view it on GitHub.

hellracer commented 9 years ago

Hi Willem,

Good day, when you get back and have time I hope you can take a look on the issue, this is the message below I got from dmesg, whenever the socket program won't process any commands, I can connect on the ports (60004) but any command you send has no effect, that's the crash i'm talking about in the above thread thanks in advance.

by the way I'm using PHP client in lieu of the the Polymer client.

dmesg snippet

[20207.832481] openzwave-serve[22894]: segfault at 8 ip b7774eab sp bfdaa9a0 error 4 in libwebsockets.so.5[b776f000+14000]

wburgers commented 9 years ago

Hi, So it says there is a segfault in the libwebsockets code. When I get back from my holiday, I'll try to reproduce the problem. Can you please tell me what version of libwebsockets you are using? Did you install the latest master branch or have you downloaded a released zip? As far as I know, libwebsockets has not changed that much since I implemented it in my server. So the way my code calls libwebsockets should be ok.

If you are using the master branch of libwebsockets, you could try a git pull and recompile the libwebsockets project. That may help.

I'll report here when I get back home ☺.

hellracer commented 9 years ago

HI WIllem,

I don't know if this has anything useful, please see attached backtrace

(gdb) backtrace

0 0xb7fdbd4c in __kernel_vsyscall ()

1 0xb7e42028 in accept () at ../sysdeps/unix/sysv/linux/i386/socket.S:95

2 0x080fe068 in Socket::accept (this=0x8169d40, new_socket=...)

at Socket.cpp:88

3 0x08053fe3 in main (argc=1, argv=0xbffff7c4) at Main.cpp:1004

(gdb) frame 2

2 0x080fe068 in Socket::accept (this=0x8169d40, new_socket=...)

at Socket.cpp:88

for the libwebsocket version I just clone it based on your docs and it appears i'm already on the latest version.

aileen@aileen-ThinkCentre-M57:~/libwebsockets$ git pull Already up-to-date.

Ok, no worries no rush I can pull some older revision of libwebsocket then recompile against it, thanks for the time and have a nice Holiday :)

wburgers commented 9 years ago

Thank you very much for the information. This will definitely help to find the problem. I see I have not updated libwebsockets for a while now. I'm on a commit with hash: 3ae1badae7a05e0982e0dfbcb078da3d4b92a81d Edit: oh wait, this is the latest master commit 😐. Well, I'll get back to you later!

Best regards, Willem

wburgers commented 9 years ago

Hi Ronald,

I have pushed some updates regarding the Polymer client and authentication over websockets. Can you please try the latest code and tell me if you are still having issues? I still need to update the docs, but I have added a new dependency, namely libsocket. (https://github.com/dermesser/libsocket) This socket implementation is used to connect to a google api wrapper written in nodejs. (used for auth)

I plan to replace the standard socket port (60004) for OZWSS with this socket library as well. I think that there is something wrong with the custom socket implementation that Thomas got from a website somewhere. That can also cause your segfault. By replacing this custom implementation with libsocket, the problem may be gone.

My holiday is over, but I also started working again, so I hope to find the time for this next weekend.

Best regards, Willem

hellracer commented 9 years ago

HI Willem, Will surely do and revert back to you with the result thanks for giving some of your free time on this, if somehow you got here in Manila, I'll buy you a drink :). by the way can you tell me what's the purpose of the roomlist aside from an identifier that a given device was assigned to it the way I see it it has some other purpose right?

Best regards, Anyone who has never made a mistake has never tried anything new

--Albert Einstein

 On Wednesday, August 5, 2015 8:30 PM, Willem Burgers <notifications@github.com> wrote:

Hi Ronald,I have pushed some updates regarding the Polymer client and authentication over websockets. Can you please try the latest code and tell me if you are still having issues? I still need to update the docs, but I have added a new dependency, namely libsocket. (https://github.com/dermesser/libsocket) This socket implementation is used to connect to a google api wrapper written in nodejs. (used for auth)I plan to replace the standard socket port (60004) for OZWSS with this socket library as well. I think that there is something wrong with the custom socket implementation that Thomas got from a website somewhere. That can also cause your segfault. By replacing this custom implementation with libsocket, the problem may be gone.My holiday is over, but I also started working again, so I hope to find the time for this next weekend.Best regards, Willem— Reply to this email directly or view it on GitHub.

wburgers commented 9 years ago

Haha cool man, if I'm ever in Manila, I'll let you know ;-)

Most of the purpose of the roomlist is internal in the server. It provides a cache of the temperatures (current and setpoint) for a certain room. I included this such that when you have multiple radiator thermostat knobs (such as the danfoss living connect that I have), you can also use the buttons on the device to set the thermostat setpoint for the entire room. If you change the setpoint on the thermostat itself, it will report back to OZW that the setpoint was updated. My server uses the roomlist to determine which devices should receive a new setpoint. Danfoss has a similar function for their controller. This also makes sure that all devices in a certain room are set to the same setpoint. It prevents you from having one radiator fully on and the other radiator being cold.

I exposed the ROOMLIST command such that the client is able to retrieve the cached information. This makes it easier to display the temperatures (especially setpoint) for a certain room. (Otherwise the client would have to calculate the setpoint from multiple devices by itself). I rather have this centralized in the server.

Hope this clears up the ROOMLIST choices I made :-)

Best regards, Willem

wburgers commented 9 years ago

I replaced the custom socket lib (Socket.cpp, Socket.h and SocketException.h) with the libsocket++ library. This library is now required to compile and start OZWSS. I'll update the docs later today or maybe tomorrow. As libsocket is more stable than the custom socket lib files, it should resolve the segfault issue. Please check it out and let me know what you think.

Next week I'll try to update OZWSS to use the latest version of OZW (which this issue is really about :-P)

hellracer commented 9 years ago

HI Willem, Yes please update the docs and go ahead with the aforementioned change you want to commit on the code, I''l lab it up tomorrow or the other day and I will let you know the result :) Best regards, Ronald Anyone who has never made a mistake has never tried anything new

--Albert Einstein

 On Saturday, August 8, 2015 7:09 PM, Willem Burgers <notifications@github.com> wrote:

I replaced the custom socket lib (Socket.cpp, Socket.h and SocketException.h) with the libsocket++ library. This library is now required to compile and start OZWSS. I'll update the docs later today or maybe tomorrow. As libsocket is more stable than the custom socket lib files, it should resolve the segfault issue. Please check it out and let me know what you think.Next week I'll try to update OZWSS to use the latest version of OZW (which this issue is really about :-P)— Reply to this email directly or view it on GitHub.