Securifi Community Forum

Securifi Products => Almond+ => Topic started by: sjd4 on March 21, 2016, 01:20:14 pm

Title: WebSocket API C#
Post by: sjd4 on March 21, 2016, 01:20:14 pm
I found a good way to easily access the WebSocket API in C# for the Almond+.  I used WebSocket4Net's C# implementation.  I didn't see anyone else mention too much.  Was just hoping this is helpful if anyone else wants to get started.  I created this in Xamarin on a Mac, but the basics should work for C# in Visual Studio or MonoDevelop as well on Linux or Windows (or iPhone or Android through Xamarin).  Here is my source.  Obviously you need to change the pass variable in Client.cs.  It's very basic.  It sends typed commands in a console.  It outputs responses in the same console.

https://bitbucket.org/sjd4skipz/anotherwebsockets (https://bitbucket.org/sjd4skipz/anotherwebsockets)

Title: Re: WebSocket API C#
Post by: Automate on March 21, 2016, 04:55:28 pm
Thanks for posting your code
Title: Re: WebSocket API C#
Post by: mikeys63 on March 21, 2016, 10:58:11 pm
Thanks for posting the code.  I just started coding a Python script for my Raspberry PI 2.  My plan is to recognize when the garage door switch is open and then send my cell a text if is is not closed within a certain time period because I don't believe that there is away to do this with the Almond+ rules engine.  The Python script uses the ws4py package that can be found at https://ws4py.readthedocs.org/en/latest/ (https://ws4py.readthedocs.org/en/latest/)   I have included my starting script.  So far it just logs in to the almond+ and keeps reporting the almond+ messages to the screen.

Code: [Select]
from ws4py.client.threadedclient import WebSocketClient

class DummyClient(WebSocketClient):
    def opened(self):
print "Connected"
    def closed(self, code, reason=None):
        print "Closed down", code, reason

    def received_message(self, m):
        print m

if __name__ == '__main__':
    try:
        ws = DummyClient('ws://your ip address:7681/your user/your password')
        ws.connect()
        ws.run_forever()
    except KeyboardInterrupt:
        ws.close()