| 
 | 
 
 
发表于 2020-7-21 12:45:49
|
显示全部楼层
 
 
 
 本帖最后由 tjsyk 于 2020-7-22 09:18 编辑  
 
我从海尔开发平台的api接口上获取了一下,看着pm2.5返回的是一个相对值30w001,应该是会在001-004之间变化,再根据抓包结果看,数据包的97号位置,会从0-3之间变化,感觉这两个可以对的上,再根据ios客户端代码里面看的公式,应该可以计算出一个相对的数值。 
 
if([code isEqualToString "30w001"]) 
    { 
        str = @"25"; 
    } 
    else if([code isEqualToString "30w002"]) 
    { 
        str =  @"75"; 
    } 
    else if([code isEqualToString "30w003"]) 
    { 
        str =  @"125"; 
    } 
    else if([code isEqualToString "30w004"]) 
    { 
        str =  @"325"; 
    } 
    else if([code intValue] > 0 && [code intValue] <= 500) 
    { 
        return code; 
    } 
    else if([code intValue] > 500) 
    { 
        return @"500"; 
    } 
    else 
    { 
        return @"--"; 
    } 
     
    NSArray *arrPm25 = [MainDelegate.pm25FloatRange objectForKey:mac]; 
    float xNum = 70.0f ; 
    float yNum = 30.0f; 
    float zNum = 4.0f; 
    float aNum = 0.0f; 
    if(arrPm25 && arrPm25.count >= 3) 
    { 
        xNum =[[arrPm25 objectAtIndex:0] floatValue]; 
        yNum=[[arrPm25 objectAtIndex:1] floatValue]; 
        zNum=[[arrPm25 objectAtIndex:2] floatValue]; 
        if(arrPm25.count >= 4) 
        { 
            aNum = [[arrPm25 objectAtIndex:3] floatValue]; 
        } 
    } 
     
    float totalFloat=xNum/ 100 *[ str floatValue] +(yNum / 100) * aNum + zNum; 
 
pm25FloatRange  这个根据安卓客户端的抓包结果看是这个格式[70,30,0],其中最后一位看见过最大的是5 
 
我在你的代码的基础上写了下面这个函数 
 
def getRealPM25(self, level): 
        #realHumi = round((humi / 10), 1) 
        if level == 0: 
            return round(70.0 / 100.0 * 25.0, 1) + random.randint(0,5) 
        elif level == 1: 
            return round(70.0 / 100.0 * 75.0, 1) + random.randint(0,5) 
        elif level == 2: 
            return round(70.0 / 100.0 * 125.0, 1) + random.randint(0,5) 
        elif level == 3: 
            return round(70.0 / 100.0 * 325.0, 1) + random.randint(0,5) 
        else: 
            return 0.0 
 
具体还得再验证,也不知道对不对---------------------------------------------------------------------------------------- 
 
试了一下,确实是可以,和手机APP上的数值也能对的上,但是就是这玩意灵敏度太低了,只有离着很近往上面吐烟,才会有变化。 
 |   
 
 
 
 |