Exemple #1
0
 /// <summary>
 /// constructor
 /// </summary>
 public DistanceScanClient(string id, IotHttpClient client, IotNode parent)
     : base(id, client, parent)
 {
     DistanceScanData = new DistanceScanData {
         Id = nameof(DistanceScanData)
     };
 }
Exemple #2
0
 /// <summary>
 /// constructor
 /// </summary>
 public PiCar(string path, IotHttpClient httpIotClient)
     : base(path, null, null)
 {
     Client = httpIotClient;
     //Server = httpSystem;
     //Initialize(server, videoPort);
 }
Exemple #3
0
 /// <summary>
 /// constructor
 /// </summary>
 public KasaHs1xxClient(string path, IotHttpClient client) : base(path, client, null)
 {
     System = new KasaHs1xxSystemClient("system", client, this);
     Children.Add(System);
     Time = new KasaHs1xxTimeClient("time", client, this);
     Children.Add(Time);
     Emeter = new KasaHs1xxEmeterClient("emeter", client, this);
     Children.Add(Emeter);
 }
Exemple #4
0
 /// <summary>
 /// constructor
 /// </summary>
 public SystemClient(string id, IotHttpClient client, IotNode parent)
     : base(id, client, parent)
 {
     CpuClient = new CpuClient("cpu", Client, this);
     Children.Add(CpuClient);
     MemoryClient = new MemoryClient("memory", Client, this);
     Children.Add(MemoryClient);
     SystemData = new SystemData()
     {
         Id = nameof(SystemData)
     };
 }
Exemple #5
0
 /// <summary>
 /// constructor
 /// </summary>
 public GpioClient(string id, IotHttpClient client, IotNode parent)
     : base(id, client, parent)
 {
     GpioData = new GpioData {
         Parent = this, Pins = new List <GpioPinData>()
     };
     for (int jj = 1; jj <= 40; jj++)
     {
         GpioPinClient pinClient = new GpioPinClient(jj.ToString(), Client, this);
         GpioPinClients.Add(pinClient);
         Children.Add(pinClient);
     }
 }
Exemple #6
0
        static void Discover(string server, string credential)
        {
            IotHttpClient httpIotClient = new IotHttpClient();

            httpIotClient.SetServer(server);
            httpIotClient.SetCredential(credential);

            // discover server endpoints and paths
            IList <HttpServiceEndpoint> endpoints = httpIotClient.DiscoverAvailableEndpoints();

            if (endpoints?.Count > 0)
            {
                Console.WriteLine($"Server {server} endpoints:");
                foreach (HttpServiceEndpoint endpoint in endpoints)
                {
                    Console.WriteLine($" name:{endpoint.Name} type:{endpoint.Type} path:{endpoint.Path} parent:{endpoint.Parent} url:{endpoint.Url}");
                }
            }
            else
            {
                Console.WriteLine($"Server {server} does not support REST IOT.");
            }
        }
Exemple #7
0
 /// <summary>
 /// send a request to the host itself
 /// </summary>
 /// <param name="path"></param>
 /// <param name="json"></param>
 public void SendSelfRequest(string path, string json)
 {
     if (_client == null)
     {
         _port = GetServicePort();
         DeviceSettings settings   = DeviceSettings.Instance;
         string         credential = settings.ServiceCredentials;
         if (!string.IsNullOrEmpty(credential))
         {
             string[] parts = credential.Split(CommaDelimiter);
             credential = parts[0];
         }
         _client = new IotHttpClient($"localhost{_port}", credential);
     }
     if (string.IsNullOrEmpty(json))
     {
         _client.GetResponse(path);
     }
     else
     {
         _client.Post(path, json);
     }
 }
Exemple #8
0
        /// <summary>
        /// create client node (and possible subnodes) based on the endpoints
        /// </summary>
        /// <param name="endpoints">the list of endpoints</param>
        /// <returns>returns the root client node that may contain all the child nodes</returns>
        protected override IotClientNode CreateClientNode(IList <HttpServiceEndpoint> endpoints, IotHttpClient client)
        {
            IotGenericClient root = new IotGenericClient(client);

            foreach (HttpServiceEndpoint endpoint in endpoints)
            {
                if (string.Equals("HygroThermoSensor", endpoint.Type, StringComparison.OrdinalIgnoreCase))
                {
                    HygroThermoSensorClient device = new HygroThermoSensorClient(endpoint.Path, client, null);
                    root.AddNode(device);
                }
                if (string.Equals("Motor", endpoint.Type, StringComparison.OrdinalIgnoreCase))
                {
                    MotorClient device = new MotorClient(endpoint.Path, client, null);
                    root.AddNode(device);
                }
                if (string.Equals("Servo", endpoint.Type, StringComparison.OrdinalIgnoreCase))
                {
                    ServoClient device = new ServoClient(endpoint.Path, client, null);
                    root.AddNode(device);
                }
                if (string.Equals("RGBLed", endpoint.Type, StringComparison.OrdinalIgnoreCase))
                {
                    RGBLedClient device = new RGBLedClient(endpoint.Path, client, null);
                    root.AddNode(device);
                }
                if (string.Equals("StripLedPattern", endpoint.Type, StringComparison.OrdinalIgnoreCase))
                {
                    StripLedClient device = new StripLedClient(endpoint.Path, client, null);
                    root.AddNode(device);
                }
                if (string.Equals("Ultrasonic", endpoint.Type, StringComparison.OrdinalIgnoreCase))
                {
                    UltrasonicClient device = new UltrasonicClient(endpoint.Path, client, null);
                    root.AddNode(device);
                }
                if (string.Equals("DistanceScan", endpoint.Type, StringComparison.OrdinalIgnoreCase))
                {
                    DistanceScanClient device = new DistanceScanClient(endpoint.Path, client, null);
                    root.AddNode(device);
                }
            }
            if (root.Children.Count > 0)
            {
                return(root);
            }
            return(null);
        }
Exemple #9
0
 /// <summary>
 /// constructor
 /// </summary>
 public GpioPinClient(string id, IotHttpClient client, IotNode parent)
     : base(id, client, parent)
 {
 }
Exemple #10
0
 /// <summary>
 /// constructor with server:port and user:password
 /// </summary>
 public IotGenericClient(string server, string credential) : base(string.Empty, null, null)
 {
     Client = new IotHttpClient(server, credential);
 }
Exemple #11
0
 /// <summary>
 /// constructor with server:port and user:password
 /// </summary>
 public IotGenericClient(IotHttpClient client) : base(string.Empty, client, null)
 {
 }
Exemple #12
0
 /// <summary>
 /// constructor
 /// </summary>
 public MotorClient(string id, IotHttpClient client, IotNode parent)
     : base(id, client, parent)
 {
     MotorData = new MotorData();
 }
Exemple #13
0
        /// <summary>
        /// create client node (and possible subnodes) based on the endpoints
        /// </summary>
        /// <param name="endpoints">the list of endpoints</param>
        /// <returns>returns the root client node that may contain all the child nodes</returns>
        protected override IotClientNode CreateClientNode(IList <HttpServiceEndpoint> endpoints, IotHttpClient client)
        {
            SmartPlugClient      root     = null;
            List <IotClientNode> subnodes = new List <IotClientNode>();

            foreach (HttpServiceEndpoint endpoint in endpoints)
            {
                if (string.Equals("KasaSmartPlug", endpoint.Type, StringComparison.OrdinalIgnoreCase))
                {
                    root = new SmartPlugClient(endpoint.Path, client);
                }
                else if (string.Equals("KasaHS1xx", endpoint.Type, StringComparison.OrdinalIgnoreCase))
                {
                    KasaHs1xxClient sys = new KasaHs1xxClient(endpoint.Path, client);
                    subnodes.Add(sys);
                }
            }
            if (root != null && subnodes.Count > 0)
            {
                foreach (IotClientNode node in subnodes)
                {
                    if (!string.IsNullOrEmpty(root.Id))
                    {
                        node.Id = node.Id.Substring(root.Id.Length + 1);
                    }
                    root.AddNode(node);
                }
            }
            return(root);
        }
Exemple #14
0
 /// <summary>
 /// constructor
 /// </summary>
 public SmartPlugClient(string path, IotHttpClient client) : base(path, client, null)
 {
 }
Exemple #15
0
 /// <summary>
 /// constructor
 /// </summary>
 public KasaHs1xxSystemClient(string path, IotHttpClient client, IotNode parent) : base(path, client, parent)
 {
 }
Exemple #16
0
 /// <summary>
 /// constructor
 /// </summary>
 public HygroThermoSensorClient(string id, IotHttpClient client, IotNode parent)
     : base(id, client, parent)
 {
 }
Exemple #17
0
        /// <summary>
        /// create client node (and possible subnodes) based on the endpoints
        /// </summary>
        /// <param name="endpoints">the list of endpoints</param>
        /// <returns>returns the root client node that may contain all the child nodes</returns>
        protected override IotClientNode CreateClientNode(IList <HttpServiceEndpoint> endpoints, IotHttpClient client)
        {
            IotGenericClient root = new IotGenericClient(client);

            foreach (HttpServiceEndpoint endpoint in endpoints)
            {
                if (string.Equals("PiSystem", endpoint.Type, StringComparison.OrdinalIgnoreCase))
                {
                    SystemClient sys = new SystemClient(endpoint.Path, client, null);
                    root.AddNode(sys);
                }
                else if (string.Equals("PiGpio", endpoint.Type, StringComparison.OrdinalIgnoreCase))
                {
                    GpioClient gpio = new GpioClient(endpoint.Path, client, null);
                    root.AddNode(gpio);
                }
            }
            if (root.Children.Count > 0)
            {
                return(root);
            }
            return(null);
        }
Exemple #18
0
 /// <summary>
 /// constructor
 /// </summary>
 public StripLedClient(string id, IotHttpClient client, IotNode parent)
     : base(id, client, parent)
 {
     StripLedPatternData = new StripLedPatternData();
 }
Exemple #19
0
 /// <summary>
 /// constructor
 /// </summary>
 public MemoryClient(string id, IotHttpClient client, IotNode parent)
     : base(id, client, parent)
 {
 }
Exemple #20
0
        /// <summary>
        /// create client node (and possible subnodes) based on the endpoints
        /// </summary>
        /// <param name="endpoints">the list of endpoints</param>
        /// <returns>returns the root client node that may contain all the child nodes</returns>
        protected override IotClientNode CreateClientNode(IList <HttpServiceEndpoint> endpoints, IotHttpClient client)
        {
            IotGenericClient root = new IotGenericClient(client);

            foreach (HttpServiceEndpoint endpoint in endpoints)
            {
                if (string.Equals("PiCar", endpoint.Type, StringComparison.OrdinalIgnoreCase))
                {
                    PiCar picar = new PiCar(endpoint.Path, client);
                    root.AddNode(picar);
                }
            }
            if (root.Children.Count > 0)
            {
                return(root);
            }
            return(null);
        }
Exemple #21
0
 /// <summary>
 /// constructor
 /// </summary>
 public ServoClient(string id, IotHttpClient client, IotNode parent)
     : base(id, client, parent)
 {
     ServoData = new ServoData();
 }
Exemple #22
0
 /// <summary>
 /// constructor
 /// </summary>
 public UltrasonicClient(string id, IotHttpClient client, IotNode parent)
     : base(id, client, parent)
 {
     UltrasonicData = new UltrasonicData();
 }
Exemple #23
0
 /// <summary>
 /// constructor
 /// </summary>
 public RGBLedClient(string id, IotHttpClient client, IotNode parent)
     : base(id, client, parent)
 {
     RGBLedData = new RGBLedData();
 }