/// <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"); } }
public async Task <double> RequestCurrentSoilMoisturePercentage(DeviceConfiguration deviceConfig, WateringLocation wateringLocation) { string variableName = wateringLocation == WateringLocation.First ? SPARKVARIABLE_ZONEONE_SOILHUMIDITY : SPARKVARIABLE_ZONETWO_SOILHUMIDITY; ParticleDevice device = await LoginAndGetParticleDevice(deviceConfig); ParticleVariableResponse response = await device.GetVariableAsync(variableName); return(double.Parse(response.Result)); }
private async Task <SoilHumidityLogEntry> RetrieveSoilHumidityLogEntryFromDevice(DeviceConfiguration deviceConfig, WateringLocation wateringLocation) { bool success; double soilHumidityWateringArea = 0; try { soilHumidityWateringArea = await _greenHouseSparkDeviceService.RequestCurrentSoilMoisturePercentage(deviceConfig, wateringLocation); success = true; } catch (Exception e) { success = false; //Todo: log this error } if (success) { var soilHumidityLogEntry = new SoilHumidityLogEntry { LogDateUtc = DateTime.UtcNow, WateringLocation = wateringLocation, PercentageOfHumidity = soilHumidityWateringArea }; return(soilHumidityLogEntry); } else { return(null); } }