最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

type conversion - How to properly convert zenohbytes stored in InfluxDB to usable numeric values? - Stack Overflow

programmeradmin6浏览0评论

I'm publishing sensor data using Zenoh, and my backend storage is InfluxDB via the Zenoh Router.

Currently, I publish a float value like this in C++:

void ControllerPublisher::publishSpeed(float speed)
{
    throttle_pub->put(std::to_string(speed));  // Publishing as a string
}

However, when the data is stored in InfluxDB, the _value column appears as zenoh/bytes, I can visualize it as a table but once I try to visualize it in InfluxDB graphs or Grafana I can't. In the beginning I thought it was simple strings and I tried using different approaches like (toInt(), select cast() in sql) but all of them failed. This led me to realize that the Zenoh Router is storing the values as raw bytes instead of numbers or strings.As you can see in the image the _value is 0 in the graphs part.

  • How can I properly convert zenoh/bytes stored in InfluxDB back into a float/int?
  • Is there a way to force Zenoh Router to store numeric values correctly in InfluxDB? Should I modify my Zenoh publisher to ensure it sends data in a format that avoids zenoh/bytes issues?

As you can see in the images, the value is written as "string" type and it appears in a table but not in a graph.

influxDB table - column _value appears
InfluxDB graphs - _value is always 0

At first, I thought the _value column stored simple strings, so I tried common conversions in Flux, SQL, and other environments, but none worked.

  • In Flux (InfluxDB Query Language):

    |> map(fn: (r) => ({ r with _value: int(v: r._value) })) 
    |> map(fn: (r) => ({ r with _value: float(v: string(v: r._value)) }))  
    
    • Expected: The _value column should be cast to an integer or float.
    • Result: Error due to zenoh/bytes format.
  • In SQL:

    SELECT CAST(_value AS SIGNED) FROM my_table;
    SELECT CONVERT(_value, SIGNED) FROM my_table;
    SELECT _value + 0 FROM my_table; 
    
    • Expected: MySQL should convert _value to an integer.
    • Result: If _value were a string, it would work—but since it’s zenoh/bytes, conversion fails.
发布评论

评论列表(0)

  1. 暂无评论