Choose style:

Author Topic: WebSocket API C#  (Read 5496 times)

0 Members and 1 Guest are viewing this topic.

Offline sjd4

  • Backer
  • *
  • Posts: 26
  • Thanks: 0
  • Registered : 16/08/2014
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
WebSocket API C#
« 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


Offline Automate

  • Backer
  • *
  • Posts: 175
  • Thanks: 1
  • Registered : 03/08/2013
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
Re: WebSocket API C#
« Reply #1 on: March 21, 2016, 04:55:28 pm »
Thanks for posting your code

Offline mikeys63

  • Newbie
  • **
  • Posts: 14
  • Thanks: 0
  • Registered : 16/07/2015
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYears
Re: WebSocket API C#
« Reply #2 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/   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()

 

Page created in 0.029 seconds with 17 queries.