You are reading a single comment by @furuskog and its replies. Click here to read the full conversation.
  • //In python 
    temperature, sunlight, moisture, fertility = unpack('<hxIBHxxxxxx',data)
    

    Format C Type Python type Standard size
    h short integer 2
    x pad byte no value
    I unsigned int integer 4
    B unsigned char integer 1
    H unsigned short integer 2

    How can I do this with the ArrayBuffer in JavaScript?

    var data = 
    new ArrayBuffer([215, 0, 0, 208, 13, 0, 0, 20, 53, 1, 2, 60, 0, 251, 52, 155]);
    
    // 21.5 C, type h
    var temp = data[0]/10;
    // ~ 3500 lux, data[2],data[3],data[4], 0,208,13, type I
    //var sunlight =  ?
    // 20 %, data[7], type B
    var moister = data[7];
    // 315,  data[8], data[9], type H
    //var fertility = ?
    

    I wonder if there is an easy solution to this?

About

Avatar for furuskog @furuskog started