Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Help converting IEEE-754 Floating Point to decimal


jwi

Question

I would like to read values from my solar storage tank and process them further in the HC3.

Unfortunately, I get the values back in this notation. Example : fl_42C80000. How to convert that to decimal in LUA?

thanks for help

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Please login or register to see this code.

 

Prints "100"

 

Basen on: 

Please login or register to see this link.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

  • 0

For people struggling with converting foreign values... <

Please login or register to see this link.

>
 

Please login or register to see this code.

 

Edited by jgab
  • Like 2
  • Thanks 2
Link to comment
Share on other sites

  • 0
  • Inquirer
  • Hello @petergebruers and @jgabthanks for the solution, but I need your support again.

    For some values, string.unpack returns (integer overflow). E.g. fl_C44B5A3D, the decimal value should be around 4000.00

    What can I do? Is that a a LUA restriction?

    Thanks very much

    Link to comment
    Share on other sites

    • 0

    Try

    Please login or register to see this code.

    -813.40997314453

    is that correct?

    Edited by jgab
    • Thanks 1
    Link to comment
    Share on other sites

    • 0

    Here is an improved version, using "unsigned int" instead of "signed int" for intermediate representation. Unsigned int can represent bigger numbers than unsigned int.

     

    Please login or register to see this code.

     

    4 minutes ago, jgab said:

    -813.40997314453

    is that correct?

    Based on the "gregstoll" converter that is indeed correct. Depends on your worldview if you consider that to be "around 4000".

    • Like 1
    Link to comment
    Share on other sites

    • 0

    hmm, my post was I4, but it become i4 somehow...

    5 minutes ago, petergebruers said:

    Based on the "gregstoll" converter that is indeed correct. Depends on your worldview if you consider that to be "around 4000".

    yes, give or take... ;-)

    • Like 1
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 17 hours ago, jgab said:

    hmm, my post was I4, but it become i4 somehow...

    yes, give or take... ;-)

    @jgab, @petergebruers Thanks again to both of you and indeed I have a Senec system.

    But now all the data I read from the API is correct. The trick was actually "I4" instead of "i4".

    The value of the variable with about 4000 was my mistake. Of course -813.4099... was correct. 

    You saved my weekend 🙂

    • Like 1
    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...