Пример #1
0
        /// <summary>
        /// Gets a list of all users devices
        /// </summary>
        /// <returns>Returns a List of ParticleDevices</returns>
        public async Task <List <ParticleDevice> > GetDevicesAsync()
        {
            try
            {
                var jsonSerializer = new JsonSerializer();
                jsonSerializer.DateTimeZoneHandling = DateTimeZoneHandling.Local;

                var responseContent = await GetDataAsync($"{ParticleApiVersion}/{ParticleApiPathDevices}");

                var result = JToken.Parse(responseContent);

                List <ParticleDevice> devices = new List <ParticleDevice>();
                foreach (JObject device in (JArray)result)
                {
                    ParticleDeviceResponse deviceState    = device.ToObject <ParticleDeviceResponse>(jsonSerializer);
                    ParticleDevice         particleDevice = new ParticleDevice(deviceState, this);
                    devices.Add(particleDevice);
                }

                foreach (ParticleDevice device in devices)
                {
                    if (device.Connected)
                    {
                        await device.RefreshAsync();
                    }
                }

                return(new List <ParticleDevice>(devices));
            }
            catch
            {
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// Gets a device
        /// </summary>
        /// <param name="deviceId">Device ID</param>
        /// <returns>Returns a ParticleDevice</returns>
        public async Task <ParticleDevice> GetDeviceAsync(string deviceId)
        {
            try
            {
                ParticleDevice device = new ParticleDevice(deviceId, this);
                await device.RefreshAsync();

                return(device);
            }
            catch
            {
                return(null);
            }
        }
Пример #3
0
 /// <summary>
 /// Creates a new long running task to listen for events on a specific users device
 /// </summary>
 /// <param name="eventHandler">ParticleEventHandler to call when new event arrives</param>
 /// <param name="device">ParticleDevice to limit event stream to</param>
 /// <param name="eventNamePrefix">Prefix to monitor on event stream</param>
 /// <returns>Returns GUID reference to long running event task</returns>
 public async Task <Guid> SubscribeToDeviceEventsWithPrefixAsync(ParticleEventHandler eventHandler, ParticleDevice device, string eventNamePrefix = "")
 {
     return(await SubscribeToDeviceEventsWithPrefixAsync(eventHandler, device.Id, eventNamePrefix));
 }
Пример #4
0
 /// <summary>
 /// Flash a compiled firmware to a device
 /// A return of true only means it was sent to the device, not that flash is successful
 /// </summary>
 /// <param name="particeDevice">ParticleDevice</param>
 /// <param name="firmwareStream">Stream of compiled binary</param>
 /// <param name="filename">Filename of compiled binary</param>
 /// <returns>Returns true if binary is sent to device</returns>
 public async Task <bool> DeviceFlashBinaryAsync(ParticleDevice particeDevice, Stream firmwareStream, string filename)
 {
     return(await DeviceFlashBinaryAsync(particeDevice.Id, firmwareStream, filename));
 }