示例#1
0
        public static void GetValue(TBRpcRequest rpcRequest)
        {
            TBRpcResponse rpcResponse = new TBRpcResponse(rpcRequest.RpcRequestId);

            rpcResponse.Add(someDeviceValue);
            thingsBoard.SendRPCReply(rpcResponse);
        }
        public static void GetGpioStatus(TBRpcRequest rpcRequest)
        {
            TBRpcResponse rpcResponse = new TBRpcResponse(rpcRequest.RpcRequestId);

            rpcResponse.Add(pins);
            thingsBoard.SendRPCReply(rpcResponse);

            Debug.WriteLine("Get Gpio Status: " + rpcResponse.ToJson());
        }
示例#3
0
        public static void GetValue(TBRpcRequest rpcRequest)
        {
            Console.WriteLine("Get Value: " + someDeviceValue);

            TBRpcResponse rpcResponse = new TBRpcResponse(rpcRequest.RpcRequestId);

            rpcResponse.Add(someDeviceValue);
            thingsBoard.SendRPCReply(rpcResponse);
        }
        void Client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
        {
            string topic   = e.Topic;
            string message = Encoding.UTF8.GetString(e.Message, 0, e.Message.Length);

            string[] splitTopic  = topic.Split('/');
            int      rpcActionId = int.Parse(splitTopic[splitTopic.Length - 1]);

            Hashtable deserializedObject = JsonSerializer.DeserializeString(message) as Hashtable;

            if (topic.StartsWith(RPC_REQUEST_TOPIC))
            {
                TBRpcRequest rpcRequest = new TBRpcRequest((string)deserializedObject["method"], deserializedObject["params"], rpcActionId);

                if (OnRpcRequestTopic != null)
                {
                    OnRpcRequestTopic(this, new RpcEventArgs(rpcRequest));
                }
            }
            else if (topic.StartsWith(RPC_RESPONSE_TOPIC))
            {
                string error = (string)deserializedObject["error"];


                if (error != null)
                {
                    RpcError rpcError = new RpcError(error, rpcActionId);

                    if (OnRpcError != null)
                    {
                        OnRpcError(this, new RpcEventArgs(rpcError));
                    }
                }
                else if (OnRpcResponseTopic != null)
                {
                    TBRpcResponse rpcResponse = new TBRpcResponse(rpcActionId);
                    OnRpcResponseTopic(this, new RpcEventArgs(rpcResponse));
                }
            }

            else if (topic == ATTRIBUTES_TOPIC)
            {
            }
            else if (topic.StartsWith(ATTRIBUTES_TOPIC_RESPONSE))
            {
                TBAttributesResponse tBAttributesResponse = new TBAttributesResponse(deserializedObject["client"], deserializedObject["shared"], rpcActionId);
                if (OnAttributesResponseTopic != null)
                {
                    OnAttributesResponseTopic(this, new RpcEventArgs(tBAttributesResponse));
                }
            }
        }
        public static void SetGpioStatus(TBRpcRequest rpcRequest)
        {
            var pin     = (Int64)(rpcRequest.RpcParams as Hashtable)["pin"];
            var enabled = (Boolean)(rpcRequest.RpcParams as Hashtable)["enabled"];

            pins[pin] = enabled;

            Debug.WriteLine("Set Gpio Pin:" + pin + " Value:" + enabled);

            TBRpcResponse rpcResponse = new TBRpcResponse(rpcRequest.RpcRequestId);

            rpcResponse.Add(pin, pins[pin]);

            thingsBoard.SendRPCReply(rpcResponse);
        }
 public RpcEventArgs(TBRpcResponse RpcResponse)
 {
     this.RpcResponse = RpcResponse;
 }
 public void SendRPCReply(TBRpcResponse rpcResponse)
 {
     client.Publish(RPC_RESPONSE_TOPIC + rpcResponse.RpcResponsetId, Encoding.UTF8.GetBytes(rpcResponse.ToJson()), QoS, false);
 }