BMP280有气压和温度想把数值分开,ldx16是BMP280设置text,已经有读数,17和18是分开的虚拟传感器,气温已经分出来了但气压一直没有分出来,大神帮忙看看代码哪里有不对吗?
if devicechanged['BMP280'] then
local device = otherdevices_svalues["BMP280"]
print(device)
local Temperature, Pressure
_,_,Temperature, Pressure = string.find(device, "(.+);(.+)")
print(Temperature) --show temp in LOG
print(Pressure) --show Pressure in LOG,
commandArray[1] = {['UpdateDevice'] = 17 .. '|0|' .. Temperature}
commandArray[2] = {['UpdateDevice'] = 18 .. '|0|' .. Pressure}
end
return commandArray
commandArray = {}求助 BMP280用Custom Sensor把气温和气压数值分开但读不到气压值
Re: 求助 BMP280用Custom Sensor把气温和气压数值分开但读不到气压值
代码: 全选
_,_,Temperature,Pressure = string.find(txt, "(%d+.-%d+);(%d+.-%d+)")
Re: 求助 BMP280用Custom Sensor把气温和气压数值分开但读不到气压值
我是学文科做平面设计的,多代码一窍不通!!
可能跟读数格式有关系,文本读数是17.62;1015.40;0;0,后面多了两位0;0
_,_,Temperature, Pressure,_,_ = string.find(device, "(.+);(.+);(.+);(.+)")
改成这样就正常了,分出来的两个虚拟设备气温和气压值都有了,可能是我歪打正着