<?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>Mesh sensor Model, data type</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/27690/mesh-sensor-model-data-type</link><description>I&amp;#39;m setting up the message structure for usage in a sensor Model. The sensor readings may be represented by different data types (e.g. float, integer). How is this best handled in the Model? I&amp;#39;ve been thinking about these strategies: 
 
 Use a data</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 29 Nov 2017 13:35:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/27690/mesh-sensor-model-data-type" /><item><title>RE: Mesh sensor Model, data type</title><link>https://devzone.nordicsemi.com/thread/109305?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 13:35:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4465fc10-4694-446a-9c42-f7db74c23d34</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Yes, it should be good with the union. You can save some memory by using the union instead of 3 different variables to store data and to convert it back on the other side.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mesh sensor Model, data type</title><link>https://devzone.nordicsemi.com/thread/109304?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 12:30:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d9b01cf4-20e2-49d6-88e5-c3995705a2b3</guid><dc:creator>meshs</dc:creator><description>&lt;p&gt;Thank you for the answer, Hung. Would a Union then be an appropriate method for declaring the value member in the message structure? Something like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;struct message_sensor_reading_t {
    uint32_t sensor_id;
    uint32_t timestamp;
    union Value {
        uint32_t i;
        uint8_t c;
        float f;
    };
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then, as you suggested, access the union correctly based on the opcode.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mesh sensor Model, data type</title><link>https://devzone.nordicsemi.com/thread/109303?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 11:54:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a942eb4-98af-4141-a484-8798eb127bdd</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Meshs,&lt;/p&gt;
&lt;p&gt;All data sent over the radio is converted to a byte array. It&amp;#39;s doesn&amp;#39;t mater if it&amp;#39;s float, integer or any type of data.
My suggestion is to use only one type of message but use different opcode for each type of data. For example currently in on off model we have  SIMPLE_ON_OFF_OPCODE_SET, SIMPLE_ON_OFF_OPCODE_GET. You can define SIMPLE_ON_OFF_OPCODE_GET_ADC, SIMPLE_ON_OFF_OPCODE_GET_TEMP to get each type of data.&lt;/p&gt;
&lt;p&gt;Then on the receiver side (client) you base on the opcode to convert the data back to the original type.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>