[codec javascript] Limited with ascii data in my api

I send an int i = 850 from my node, but the problem is that I get the JSON data in ASCII format in my php page! and so I make a conversion ascii => decimal with this function :

    $data64    = $var['data'];
    $data8 = base64_decode($data64)	;
    $code = str_split($data8);
    $data ="";
    for($i=0; $i< sizeof($code) ; $i++)
      {

         $data = $data . ord($code[$i]);
       

     } 

I can not make a JavaScript program in the integration part.

the ascii format limits me, and I can not send a “float” or “int” that exceeds “256” can you help me to solve this problem so that I can send “int” or “float” without limitation.

If your JSON is like:

“data” = “850”,

then the variable $data8 contains the value 850.

unfortunately the variable $data8 contains a data in ascii format and which does not represent 850

can you show what’s stored in $data8?

$data8 = 4 ! (4 in ascii) there are any relation with 850 ! I will show you my c code of my node

my goal is to send a float from my node, so I use a byte array.
my float is 4 bytes, the stack I’m using " STM32CubeExpansion_LRWAN_V1.2.1 ", is made to send a byte array of int.

C code in my NODE :

           static uint8_t AppDataBuff[64];
           uint32_t humidity_int = 0;
           float humidity = 25.6;
           humidity_int = (humidity * 32) + 1;
           AppData.Buff[i++] =  humidity_int >> 24 ;
           AppData.Buff[i++] =  humidity_int >> 16 ;
           AppData.Buff[i++] =  humidity_int >> 8 ;
           AppData.Buff[i]   =  humidity_int  ;
           AppData.BuffSize  = i; 
           LORA_send( &AppData, LORAWAN_DEFAULT_CONFIRM_MSG_STATE);

so i’m going to multiply in the node and split in my application to get the commaso:

  • first I transform it into “int” with the line :

         humidity_int = (humidity * 32) + 1;  //possible to multiply it just x10 too
    
  • then I introduce my four byte float into the byte array one by one.

unfortunately I do not know what to do in the JavaScript part to decode my information, i try this :

            function Decode(fPort, bytes) {

             var humidity_byte = bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3] ;
             var humidity = humidity_byte / 32;

             return {
                        "humidity ": humidity ,
                       };
              }

I am not a specialist in JavaScript, can you help me to decode my data please.

I obtain this result :slight_smile:

humidity :24, normally I have to get 25.6

I resolve the error, it was an error in my C code, i did not increment the last byte in the byte array :

                  AppData.Buff[i]   =  humidity_int  ;