Code Monkey home page Code Monkey logo

Comments (5)

maakbaas avatar maakbaas commented on August 23, 2024

This is not a bug, but is to be expected. A 32-bit floating point datatype can not store exact representations of all numbers, and therefore it will be stored as the closest binary representation.

See this calculator to play around with this effect:
https://www.binaryconvert.com/convert_float.html

One way to resolve this is to add a new option into the JSON that specifies the number of decimals that should be shown in the interface, and to which the numbers should be rounded. I think that could be a nice addition, so for that reason I will leave this issue open. If anyone wants to create a pull request for this functionality that would be more than welcome.

from esp8266-iot-framework.

clabnet avatar clabnet commented on August 23, 2024

I learning a lot of things from you.

from esp8266-iot-framework.

FSCSoft avatar FSCSoft commented on August 23, 2024

Hello friend, it's me again and I think what the solution would be instead of converting to pass a string in websoket and maybe in api dash set of json format with only the name and value of each object { name: dumyFloat, value: 2.1},{...} etc. example or maybe to reduce characters {dumy: {value: 2.2}, input {value: true}, etc}. to pass the data in real values ​​and not go through the conversion and it is already an ArduinoJSON dependency of some libs of the project. sorry for my bad English

from esp8266-iot-framework.

maakbaas avatar maakbaas commented on August 23, 2024

Thanks for your input. I can agree that this makes sense from a front-end and web point of view, but it does not make sense from the embedded side of things. Parsing JSON on the ESP8266 is much more expensive than converting JSON to binary in the front-end. In the second case, which is how it is implemented now, the conversion to binary is done by your computer or smartphone, which has more than enough resources to do this simple conversion from JavaScript object to binary format.

If we would choose to send JSON data over the Websocket, the ESP8266 would need to parse this JSON data and store it in a C structure. This will cost more memory and computational power on the ESP8266, where it is much more limited. With the current implementation, all that the ESP8266 needs to do is a single memory copy action.

from esp8266-iot-framework.

maakbaas avatar maakbaas commented on August 23, 2024

Added this functionality in 13988ca :)

from esp8266-iot-framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.