Example #1
0
        //Request configuration from server
        public async static Task requestConfig()
        {
            HavissIoTCommandBuilder commandBuilder = new HavissIoTCommandBuilder();

            //Add user (and password) if available
            if (password.Length > 0 && username.Length > 0)
            {
                commandBuilder.addUser(username, password);
            }
            else if(username.Length > 0)
            {
                commandBuilder.addUser(username);
            }
            //Add request for server configuration
            commandBuilder.getConfig();
            if (SharedVariables.client.isConnected())
            {
                //Store response in string
                string response = await SharedVariables.client.request(commandBuilder.getJsonString());
                //Parses response to an jsonobject
                try
                {
                    JObject jsonObject = JObject.Parse(response);
                    brokerAddress = (string) jsonObject.GetValue("brokerAddress");
                    brokerPort = (int)jsonObject.GetValue("brokerPort");
                    mqttQOS = (int)jsonObject.GetValue("qos");
                }
                catch (Exception ex)
                {
                    //TODO Handle exception
                    Debug.WriteLine(ex.Message);
                }
            }
                        
        }