Exemple #1
0
        public async Task StartPhotonAndNotify()
        {
            await LoginToCloudAndGetDevice();

            if (deviceSuccessfullyInitiated)
            {
                string myFunction = myDevice.Functions[0];
                ParticleFunctionResponse functionResponse = await myDevice.RunFunctionAsync(myFunction, string.Format("on,{0}", Environment.UserName));
            }
        }
        /// <summary>
        /// Starts the watering process
        /// </summary>
        /// <param name="wateringLocation"></param>
        /// <returns>Convention: -1 Failure</returns>
        public async void StartWatering(DeviceConfiguration deviceConfig, WateringLocation wateringLocation)
        {
            ParticleDevice device = await LoginAndGetParticleDevice(deviceConfig);

            ParticleFunctionResponse functionResponse = await device.RunFunctionAsync(SPARKFUNCTION_ACTION_STARTWATERING, Enum.GetName(typeof(WateringLocation), wateringLocation));


            if (functionResponse.ReturnValue < 0)
            {
                throw new Exception("Error occurred while starting the watering process");
            }
        }
Exemple #3
0
        public async Task EndNotifier(bool clearHosts = false)
        {
            string myFunction = myDevice.Functions[0];
            ParticleFunctionResponse functionResponse = await myDevice.RunFunctionAsync(myFunction, string.Format("off,{0}", Environment.UserName));

            if (clearHosts)
            {
                string clearHostFunction = myDevice.Functions[1];
                await myDevice.RunFunctionAsync(clearHostFunction, string.Empty);
            }
            ParticleCloud.SharedCloud.Logout();
        }
        public async void SaveDeviceConfiguration(DeviceConfiguration deviceConfig)
        {
            if (deviceConfig != null)
            {
                string setupString = CreateDeviceConfigurationString(deviceConfig);

                ParticleDevice device = await LoginAndGetParticleDevice(deviceConfig);

                //send each config param separately to minimize problems with the size restriction (63 char)
                foreach (string configParameter in setupString.Split(';'))
                {
                    if (!string.IsNullOrWhiteSpace(configParameter))
                    {
                        ParticleFunctionResponse functionResponse = await device.RunFunctionAsync(SPARKFUNCTION_ACTION_SAVECONFIG, configParameter);

                        if (functionResponse.ReturnValue < 0)
                        {
                            throw new Exception("Error occurred while saving the confguration params");
                        }
                    }
                }
            }
        }