Help sending payload with more decimal places

  • Hey guys,

    Just wondering if someone would be so kind as to help me figure out how to use setters to send a payload with more decimal places than the standard custom variable.

    I saw that perhaps I could construct the msg "on the fly", but I don't know the proper syntax to get that accomplished. Even easier, I would simply like to send a custom variable with two decimal places (or however many one should like). Right now the default is a single decimal place as I gather from the data that is being sent currently.

    In the plainest terms, I would like to send the battery voltage in a format X.XX using a custom variable, but using the standard custom variable constructor the payload is X.X.

    Thanks for your help.

  • multiply your float with 100 or 1000 before sending and divide again on the receiving end.

  • Admin

    the second argument to the MyMessage.set-method is the number of decimals.

  • @hek okay, I guess I was being stupid....

    With this msg constructor...

    MyMessage msgVolt(CHILD_ID_VOLT, V_VAR1);

    With this type def...

     float batteryV  = sensorValue * 0.003363075;

    I had the following thinking that I had turned on auto ack...

      gw.send(msgVolt.set(batteryV, 1));

    but that sets the decimal places to "1". So, if I want to set the decimal places to "2" and enable auto ack it would look like this...?

      gw.send(msgVolt.set(batteryV, 2),1);

    Thanks again.

  • Admin

    @therik said:

    gw.send(msgVolt.set(batteryV, 2),1);

    Yes, this is correct.

Log in to reply

Suggested Topics

  • 1
  • 4
  • 10
  • 97
  • 7
  • 53
  • 182
  • 1