<?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>Battery Level measurement of nrf52832 using ADC and sending it over BLE mesh</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/98279/battery-level-measurement-of-nrf52832-using-adc-and-sending-it-over-ble-mesh</link><description>I want to measure battery level of my nrf52832 with internal ADC and send it over BLE Mesh. I am using NCS v2.2.0. 
 
 I&amp;#39;ve used following ADC configuration 
 
 
 and i&amp;#39;ve set sensor type as 
 
 bt_mesh_sensor_present_input_voltage 
 
 
 When i&amp;#39;m printing</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 20 Apr 2023 14:12:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/98279/battery-level-measurement-of-nrf52832-using-adc-and-sending-it-over-ble-mesh" /><item><title>RE: Battery Level measurement of nrf52832 using ADC and sending it over BLE mesh</title><link>https://devzone.nordicsemi.com/thread/421531?ContentTypeID=1</link><pubDate>Thu, 20 Apr 2023 14:12:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e643a53-e5a0-4d09-baeb-6eeff821cdf2</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;HI,&lt;/p&gt;
&lt;p&gt;I do not see anything immediately wrong with any of that, although it does not cover all the details so I cannot say for sure.&lt;/p&gt;
&lt;p&gt;For instance, if the value pointed to by the rsp argument to bat_get_value() resides in a stack frame that gets popped and overwritten before the value is sent, then some bogus data from a different function may be what is actually sent over-the-air.&lt;/p&gt;
&lt;p&gt;You could for instance try printing from within bat_get_value(), after rsp has been filled using sensor_value_from_double() and before returning from that function, and compare that to the value actually getting received in the other end. If it changes in-between, then you may have a dangling pointer.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Battery Level measurement of nrf52832 using ADC and sending it over BLE mesh</title><link>https://devzone.nordicsemi.com/thread/418887?ContentTypeID=1</link><pubDate>Mon, 03 Apr 2023 14:57:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13ef0945-0f9f-4a72-a8f0-60d38818d81b</guid><dc:creator>AdityaN</dc:creator><description>&lt;p&gt;Hey,&lt;/p&gt;
&lt;p&gt;i am using sensor sever model,&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static struct bt_mesh_sensor bat_val = {
	.type = &amp;amp;bt_mesh_sensor_present_input_voltage,
	.get = bat_get,

};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve registered a callback function called as bat_get()&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static int bat_get(struct bt_mesh_sensor_srv *srv,
			 struct bt_mesh_sensor *sensor,
			 struct bt_mesh_msg_ctx *ctx,
			 struct sensor_value *rsp)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;this callback function calls a function which is actually responsible for reading ADC values&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int bat_get_value(struct sensor_value *rsp) {
	int reading = readAnalog_bat();
	double volt = reading/1000.0;
	sensor_value_from_double(rsp,volt);
	return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;the function readAnalog_bat() returns the value in mV.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I also tried publishing values manually by using the following function&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void bat_pub()
{
	int err;

	struct sensor_value val = {
		.val1 = 0,
		.val2 = 0
	};
	bat_get(&amp;amp;sensor_srv, &amp;amp;bat_val, NULL, &amp;amp;val);
	err = bt_mesh_sensor_srv_pub(&amp;amp;sensor_srv, NULL, &amp;amp;bat_val, &amp;amp;val);

	if (err) {
		printk(&amp;quot;Error publishing battery (%d)\n&amp;quot;, err);
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;let me know if you need anything else&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Battery Level measurement of nrf52832 using ADC and sending it over BLE mesh</title><link>https://devzone.nordicsemi.com/thread/418795?ContentTypeID=1</link><pubDate>Mon, 03 Apr 2023 09:20:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57cd457e-bb91-4d60-a5ec-296cbb27d5ec</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Please note that mesh model implementations typically have callback functions that you must write and register, for providing the model with the values. What mesh models are you using for sending the values, and what code do you have for providing the value to the mesh library and/or for sending the messages?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>