public decimal ReadValue() { // temp=47.8'C var stringTemp = _shellHelper.ExecuteCommandAsync("/opt/vc/bin/vcgencmd measure_temp").Result; stringTemp = stringTemp.Replace("temp=", string.Empty).Replace("'C", string.Empty); return(Convert.ToDecimal(stringTemp, CultureInfo.GetCultureInfo("en-gb"))); }
public decimal ReadValue() { // 4b 01 4b 46 7f ff 05 10 e1 : crc=e1 YES // 4b 01 4b 46 7f ff 05 10 e1 t=20687 var tempFileContent = _shellHelper.ExecuteCommandAsync($"cat /sys/bus/w1/devices/{_deviceId}/w1_slave").Result; var match = TempRegex.Match(tempFileContent); if (!match.Success) { throw new SensorException($"Unable to find t=XXXXX, sensor DS18B20 ({_deviceId})"); } var stringTemp = match.Value.Replace("t=", string.Empty); if (int.TryParse(stringTemp, out var temp)) { return(Math.Round(temp / 1000m, 1)); } throw new SensorException($"Unable to parse {stringTemp} to int, sensor DS18B20 ({_deviceId})"); }