<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Zigbee CLI example and float type</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/65376/zigbee-cli-example-and-float-type</link><description>I&amp;#39;m testing the Zigbee CLI Agent example and try to read info from my Titan wall sensor. I can read almost all info, but not values, that are using float type. 
 How I can add support for Type 0x39 ( for example, CO2 measurement cluster: Cluster 4: [0x040D</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 02 Sep 2020 09:05:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/65376/zigbee-cli-example-and-float-type" /><item><title>RE: Zigbee CLI example and float type</title><link>https://devzone.nordicsemi.com/thread/267568?ContentTypeID=1</link><pubDate>Wed, 02 Sep 2020 09:05:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:316d8968-4b51-4820-8dc0-2a7cc1c9fc32</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;So you found the list in zb_zcl_common.h.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The error that is printed, &amp;quot;&lt;span&gt;Value type 0x39 unsupported&amp;quot; is, as you probably found out, coming from the&amp;nbsp;zcl_attr_to_str() function in zigbee_cli_utils.c, switch (attr_type) -&amp;gt; case&amp;nbsp;ZB_ZCL_ATTR_TYPE_SINGLE, which was not implemented, and hence, the default handler prints this error.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;That being said, it is not that straight forward to print this float value. Floats are not supported in snprintf. The reason for this is that the floats library takes up alot of space. See this discussion that I found on the &lt;a href="https://www.silabs.com/community/software/simplicity-studio/forum.topic.html/snprintf_does_notwo-KYaK" rel="noopener noreferrer" target="_blank"&gt;silbas support forum&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;However, you can work around this.&amp;nbsp;Perhaps you can try something like:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;        case ZB_ZCL_ATTR_TYPE_SINGLE:
            my_raw_value = (uint8_t)p_attr[0]&amp;lt;&amp;lt;0 | (uint8_t)p_attr[1]&amp;lt;&amp;lt;8 | (uint8_t)p_attr[2]&amp;lt;&amp;lt;16 | (uint8_t)p_attr[3]&amp;lt;&amp;lt;24 ;
            my_float_pointer = (float*)&amp;amp;my_raw_value;
            my_float_value = *my_float_pointer;
            a = (zb_uint8_t)my_float_value;
            b = (zb_uint8_t)((my_float_value*100)-a*100);
            
            bytes_written = snprintf(p_str_buf, buf_len, &amp;quot;%d.%d&amp;quot;, a, b);
            break;
            
// The following declarations are done near the top of zcl_attr_to_str(), after int i:

    float * my_float_pointer;
    zb_float_t my_float_value;
    zb_uint32_t my_raw_value;
    zb_uint8_t a = 0;
    zb_uint8_t b = 0;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The reason I use all the casting is that I had some hardfaults when I set the float value directly from the p_attr like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;my_float_pointer = (float*)p_attr;&lt;/p&gt;
&lt;p&gt;my_float_value = *my_float_pointer;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am not sure why.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvim&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zigbee CLI example and float type</title><link>https://devzone.nordicsemi.com/thread/267077?ContentTypeID=1</link><pubDate>Sat, 29 Aug 2020 23:06:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aae8bebe-f560-4cf8-9bf4-f6545c2d412d</guid><dc:creator>Tiit</dc:creator><description>&lt;p&gt;I see, that zb_zcl_common.h&amp;nbsp; has&amp;nbsp;&lt;/p&gt;
&lt;p&gt;ZB_ZCL_ATTR_TYPE_SINGLE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;= 0x39, /*!&amp;lt; 4 byte floating point */&lt;/p&gt;
&lt;p&gt;and tried to add&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;case ZB_ZCL_ATTR_TYPE_SINGLE:&lt;br /&gt; bytes_written = snprintf(p_str_buf, buf_len, &amp;quot;%g&amp;quot;, *((zb_float_t *)p_attr));&lt;br /&gt; break;&lt;/p&gt;
&lt;p&gt;to zigbee_cli_utils.c and&amp;nbsp;&lt;/p&gt;
&lt;p&gt;typedef float&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; zb_float_t;&lt;/p&gt;
&lt;p&gt;to zb_types.h&lt;/p&gt;
&lt;p&gt;but that seems to be not the right way (i got no error anymore, but get an empty value).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>