enablebinstatusupdate

Einklappen
X
 
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge
  • K.Clemens
    Smart Home'r
    • 28.08.2015
    • 92

    #1

    enablebinstatusupdate

    All,

    I'm working on a dashboard for general overview of the amount of windows that are open, lights that are on, heating on/off, radio station selection with logitech media server etc..
    For getting this to work I have to enable status updates. This can be done by sending the command "jdev/sps/enablebinstatusupdate".

    The status of every update is retrieved as binary data.
    This data has to be parsed with the help of following 2 scripts, as stated previous on the old loxone forum.

    parser: http://pastebin.com/NcMukMUM
    library: https://github.com/kig/DataStream.js.../DataStream.js

    Is there anybody that has any experience with this setup? Or somebody that has created his own UI?
  • Gast

    #2
    I am working on a LCARS (Star Trek) dashboard with Siri integration and my starting document was http://www.loxone.com/enen/service/d...ion-logic.html which use dev/sps/enablestatusupdate on a WebSocket channel.

    For parsing status events I reversed engineer Loxone Web Interface (function LoxSocket and messageDispatcher)

    Kommentar

    • K.Clemens
      Smart Home'r
      • 28.08.2015
      • 92

      #3
      tbd, Thanks for you response. I'm also looking at the js scripts of the new web interface to reverse engineer to my script.
      I will take a look at both (Loxsocket & messageDispatcher). Yesterday evening I started looking at the binary.event script used in the new interface which is what I need.

      If I understand you correctly, you already have this issue of status updated solved? If so, would you like to share?

      Kommentar

      • Gast

        #4
        I just started yesterday and now I am fiddling with getting the new released XCode7 to work on HomeKit/Siri integration.

        Hope to post something on my github page this week

        Kommentar

        • K.Clemens
          Smart Home'r
          • 28.08.2015
          • 92

          #5
          ok, will let you know when I got the statusupdate working. Will also check your github regulary

          Kommentar

          • Paul Sinnema
            Smart Home'r
            • 29.12.2015
            • 54

            #6
            Hi all,

            Ok, I see this is an older thread but did anyone get this working. I'm using a Raspberry PI with .Net IoT Framework to create a Gateway for my Loxone system. I've opened a WebSocket as described in the .PDF but the command enablebinstatusupdate fails with the following:

            {"LL": { "control": "http://<IP address>:80/jdev/sps/enablebinstatusupdate", "value": "Bad request", "Code": "400"}}

            Regards,
            Paul

            Here's my code so far:

            Code:
            using Newtonsoft.Json.Linq;
            using System;
            using System.Linq;
            using System.Net.Http;
            using System.Security.Cryptography;
            using System.Text;
            using System.Threading.Tasks;
            using TGBGateway.Viewmodel;
            using WebSocketSharp;
            using Windows.ApplicationModel.Resources.Core;
            using Windows.UI.Xaml.Controls;
            
            namespace TGBGateway
            {
                /// <summary>
                /// An empty page that can be used on its own or navigated to within a Frame.
                /// </summary>
                public sealed partial class MainPage : Page
                {
                    private const string m_Host = "<my servers IP address>";
                    private const int m_Port = 80;
            
                    private readonly string m_WsUrl = $"ws://{m_Host}:{m_Port}/ws/rfc6455";
                    private readonly string m_GetkeyUrl = $"http://{m_Host}:{m_Port}/jdev/sys/getkey";
                    private readonly string m_ApiBaseUrl = $"http://{m_Host}:{m_Port}/jdev/cfg/api/";
                    private readonly string m_SpsBaseUrl = $"http://{m_Host}:{m_Port}/jdev/sps/";
                    private readonly Uri m_WsUri;
                    private readonly Uri m_GetkeyUri;
                    private string m_loxoneKey;
            
                    struct LoxoneHeaderDef
                    {
                        byte cBinType; // fix 0x03
                        byte cIdentifier; // 8-Bit Unsigned Integer (little endian)
                        byte cInfo; // Info
                        byte cReserved; // reserved
                        uint nLen; // 32-Bit Unsigned Integer (little endian)
                    };
            
                    public MainPage()
                    {
                        this.InitializeComponent();
            
                        this.DataContext = new SettingViewmodel();
            
                        m_WsUri = new Uri(m_WsUrl);
                        m_GetkeyUri = new Uri(m_GetkeyUrl);
            
            #pragma warning disable CS4014
                        StartServer();
            #pragma warning restore CS4014
                    }
            
                    private string Parameter(string id)
                    {
                        var subtree = ResourceManager.Current.MainResourceMap.GetSubtree("Constants");
                        var result = subtree.GetValue(id, ResourceContext.GetForViewIndependentUse());
                        return result.ValueAsString;
                    }
            
                    private string AuthenticateUrl => $"{m_ApiBaseUrl}authenticate/";
                    private string EnableBinStatusUpdate => $"{m_SpsBaseUrl}enablebinstatusupdate";
                    private string UserId => Parameter("UserId");
                    private string Password => Parameter("Password");
            
                    private async Task StartServer()
                    {
                        try
                        {
                            m_loxoneKey = await AuthenticateWithLoxone();
            
                            var socket = new WebSocket(m_WsUrl, "remotecontrol");
            
                            socket.SetCredentials(UserId, Password, true);
            
                            socket.OnMessage += Client_OnMessage;
                            socket.OnError += Socket_OnError;
                            socket.OnClose += Socket_OnClose;
                            socket.OnOpen += Socket_OnOpen;
            
                            socket.Connect();
                            socket.Send(EnableBinStatusUpdate);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
            
                    private void Socket_OnOpen(object sender, EventArgs e)
                    {
                    }
            
                    private void Socket_OnClose(object sender, CloseEventArgs e)
                    {
            
                    }
            
                    private void Socket_OnError(object sender, ErrorEventArgs e)
                    {
            
                    }
            
                    private void Client_OnMessage(object sender, WebSocketSharp.MessageEventArgs e)
                    {
            
                    }
            
                    private async Task<string> AuthenticateWithLoxone()
                    {
                        var key = await GetKeyFromLoxone();
            
                        var authenticateUri = new Uri($"{AuthenticateUrl}{key}");
            
                        var result = await SendHttpMessage(authenticateUri, string.Empty);
            
                        var content = await result.Content.ReadAsStringAsync();
            
                        return key;
                    }
            
                    private async Task<string> GetKeyFromLoxone()
                    {
                        // Get a key from the mini server
                        HttpResponseMessage result = await SendHttpMessage(m_GetkeyUri, string.Empty);
            
                        // Get the answer from the mini server
                        var json = await result.Content.ReadAsStringAsync();
            
                        // Parse the received string into a JSON object
                        dynamic keypacket = JObject.Parse(json);
            
                        // Get the 'LL' part from the JSON (result is a JSON)
                        dynamic LL = keypacket["LL"];
            
                        // Get the hashkey (value) from the JSON
                        var hashkey = (string)LL["value"];
            
                        // Convert it into a byte array
                        var array = ConvertToByteArray(hashkey);
            
                        // Initialize the SHA1 converter with the key received from the mini server
                        var sha1Converter= new HMACSHA1(array);
            
                        // Convert the UserId:Password string into a byte array
                        var userIdPasswordBytes = Encoding.ASCII.GetBytes($"{UserId}:{Password}");
            
                        // Calculate the hash
                        byte[] hashArray = sha1Converter.ComputeHash(userIdPasswordBytes);
            
                        // Convert to a hexadecimal string
                        return hashArray.Aggregate("", (s, e) => s + String.Format("{0:x2}", e), s => s);
                    }
            
                    /// <summary>
                    /// Converts an input string into a byte array
                    /// </summary>
                    private static byte[] ConvertToByteArray(String input)
                    {
                        // Convert the input string into a byte array
                        var inputArray = input.ToCharArray();
            
                        // Calculate the number of pairs in the array
                        var outputArray = new byte[input.Length / 2];
            
            
                        for (int i = 0; i < input.Length; i += 2)
                        {
                            // From each pair take the first and second digit and parse it into an integer
                            // and fill the output array with it.
                            outputArray[i / 2] = (byte)uint.Parse($"{inputArray[i]}{inputArray[i + 1]}");
                        }
            
                        return outputArray;
                    }
            
                    private async Task<HttpResponseMessage> SendHttpMessage(Uri uri, string message)
                    {
                        HttpClient client = new HttpClient
                        {
                            BaseAddress = uri
                        };
            
                        HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, message);
                        request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(
                                                        "Basic",
                                                        Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes($"{UserId}:{Password}")));
            
                        return await client.SendAsync(request);
                    }
                }
            }
            Zuletzt geändert von Paul Sinnema; 25.05.2018, 12:53.

            Kommentar

            • Paul Sinnema
              Smart Home'r
              • 29.12.2015
              • 54

              #7
              Is anybody watching this?

              Kommentar

              Lädt...