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)); } }
private async void CallButton_Click(object sender, RoutedEventArgs e) { SetEnableState(false); ErrorBorder.Visibility = Visibility.Collapsed; ResultTextBox.Text = ""; var function = (string)FunctionComboBox.SelectedItem; var arg = ArgumentsTextBox.Text; try { var functionValue = await particleDevice.RunFunctionAsync(function, arg); if (functionValue != null) { ResultTextBox.Text = Convert.ToString(functionValue.ReturnValue); } } catch { ResourceLoader resourceLoader = new ResourceLoader(); ErrorText.Text = resourceLoader.GetString("Error"); ErrorBorder.Visibility = Visibility.Visible; } SetEnableState(true); }
/// <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"); } }
private async Task RunFunctionAsync(string function, string arg, int?new_value = null) { RequestError = false; Syncing = true; try { var getValue = await particleDevice.RunFunctionAsync(function, arg); if (getValue == null) { RequestError = true; } else { switch (function) { case "digitalread": Value = getValue.ReturnValue; break; case "digitalwrite": if (getValue.ReturnValue == 1) { Value = new_value.Value; } break; case "analogread": Value = getValue.ReturnValue; break; case "analogwrite": if (getValue.ReturnValue == 1) { Value = new_value.Value; } break; } } } catch { RequestError = true; } Syncing = false; }
public async Task <ActionResult> Index(string txtId) { var success = await ParticleCloud.SharedCloud.LoginAsync("*****@*****.**", "eystbots"); List <ParticleDevice> devices = await ParticleCloud.SharedCloud.GetDevicesAsync(); foreach (ParticleDevice device in devices) { //MessageBox.Show(device.Name.ToString()); myDevice = device; } ViewBag.PhotonMessage = "You device is" + " " + myDevice.Name.ToString(); var functionResponse = await myDevice.RunFunctionAsync("relayOff", "1"); var result = functionResponse.ReturnValue; return(View()); }
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"); } } } } }