# Subscribing sensor data issues

**URL:** <https://discuss.px4.io/t/subscribing-sensor-data-issues/3311>\
**Category:** Uncategorized\
**Created:** [May 16, 2017, 7:24pm UTC](https://discuss.px4.io/t/subscribing-sensor-data-issues/3311 "2017-05-16T19:24:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gesem\_Gudino\_Mejia](https://discuss.px4.io/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@Gesem\_Gudino\_Mejia](https://discuss.px4.io/u/Gesem_Gudino_Mejia)\
**Post date:** [May 16, 2017, 7:24pm UTC](https://discuss.px4.io/t/subscribing-sensor-data-issues/3311/1 "2017-05-16T19:24:28Z")

</div>

Hi there!  
Well, i’m following the PX4 Dev Guide and i’m trying to complete the step 5 of the writing an application tutorial, which is subscribing my sensor data, the problem is that when i want to compile my code using make it gives me this error:

> – Build files have been written to: /home/gesem/Firmware/build\_posix\_sitl\_default  
> [503/520] Building C object src/examples/px4\_s…xamples\_\_px4\_simple\_app.dir/px4\_simple\_app.c.o  
> FAILED: /usr/bin/cc -DBUILD\_URI=localhost -DCONFIG\_ARCH\_BOARD\_SITL -DMODULE\_NAME="px4\_simple\_app" -DPX4\_MAIN=px4\_simple\_app\_app\_main -D\_\_DF\_LINUX -D\_\_PX4\_LINUX -D\_\_PX4\_POSIX -D\_\_STDC\_FORMAT\_MACROS -Dnoreturn\_function=“ **attribute** ((noreturn))” -I. -Isrc -Isrc/modules -Isrc/modules/px4\_messages -I…/mavlink/include/mavlink -I…/src -I…/src/drivers/boards/sitl -I…/src/include -I…/src/lib -I…/src/lib/DriverFramework/framework/include -I…/src/modules -I…/src/platforms -I…/src/lib/matrix -I…/src/modules/systemlib -I…/src/platforms/posix/include -Iexternal/Install/include -g -std=gnu99 -fno-common -Wall -Werror -Wextra -Wno-sign-compare -Wshadow -Wfloat-equal -Wpointer-arith -Wmissing-declarations -Wno-unused-parameter -Werror=format-security -Werror=array-bounds -Wfatal-errors -Werror=unused-variable -Werror=reorder -Werror=uninitialized -Werror=init-self -Werror=unused-but-set-variable -Wformat=1 -Wdouble-promotion -Werror=double-promotion -Wbad-function-cast -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -fvisibility=hidden -include visibility.h -O2 -fno-strict-aliasing -fomit-frame-pointer -funsafe-math-optimizations -ffunction-sections -fdata-sections -fno-strength-reduce -fno-builtin-printf -O2 -fno-strict-aliasing -fomit-frame-pointer -funsafe-math-optimizations -ffunction-sections -fdata-sections -fno-strength-reduce -fno-builtin-printf -std=gnu99 -MMD -MT src/examples/px4\_simple\_app/CMakeFiles/examples\_\_px4\_simple\_app.dir/px4\_simple\_app.c.o -MF src/examples/px4\_simple\_app/CMakeFiles/examples\_\_px4\_simple\_app.dir/px4\_simple\_app.c.o.d -o src/examples/px4\_simple\_app/CMakeFiles/examples\_\_px4\_simple\_app.dir/px4\_simple\_app.c.o -c …/src/examples/px4\_simple\_app/px4\_simple\_app.c  
> …/src/examples/px4\_simple\_app/px4\_simple\_app.c: In function ‘px4\_simple\_app\_main’:  
> …/src/examples/px4\_simple\_app/px4\_simple\_app.c:65:11: error: unused variable ‘poll\_ret’ [-Werror=unused-variable]  
> int poll\_ret = px4\_poll(fds, 1, 1000);  
> ^  
> compilation terminated due to -Wfatal-errors.  
> cc1: all warnings being treated as errors  
> [503/520] Building CXX object src/modules/bott…les/modules\_\_bottle\_drop.dir/bottle\_drop.cpp.o  
> ninja: build stopped: subcommand failed.  
> Makefile:155: recipe for target ‘posix\_sitl\_default’ failed  
> make: \*\*\* [posix\_sitl\_default] Error 1

the code that now i have in my px4\_simple\_app.c is this:

> \_\_EXPORT int px4\_simple\_app\_main(int argc, char \*argv);

> int px4\_simple\_app\_main(int argc, char \*argv){  
> PX4\_INFO(“HOLA MUNDO”);
> 
> int sensor\_sub\_fd = orb\_subscribe(ORB\_ID(sensor\_combined));
> 
> px4\_pollfd\_struct\_t fds = {  
> { .fd = sensor\_sub\_fd, .events = POLLIN },  
> };

> while (true) {  
> /\* wait for sensor update of 1 file descriptor for 1000 ms (1 second) _/  
> int poll\_ret = px4\_poll(fds, 1, 1000);  
> if (fds[0].revents & POLLIN) {  
> /_ obtained data for the first file descriptor _/  
> struct sensor\_combined\_s raw;  
> /_ copy sensors raw data into local buffer \*/  
> orb\_copy(ORB\_ID(sensor\_combined), sensor\_sub\_fd, &raw);  
> PX4\_INFO(“Accelerometer:\t%8.4f\t%8.4f\t%8.4f”,  
> (double)raw.accelerometer\_m\_s2[0],  
> (double)raw.accelerometer\_m\_s2[1],  
> (double)raw.accelerometer\_m\_s2[2]);  
> }  
> }  
> return 0;  
> }

I’m really new at this, so will really appreciate if anyone can explain me what do i’m doing wrong, and how can i solve it, also if anyone can help me to understand in better way how does it work the uORB publish() / subscribe() messaging it will be fantastic!  
I’ve already read the [uORB Messaging · PX4 Developer Guide](https://dev.px4.io/en/middleware/uorb.html) and for the error I’ve already tried to erase the unused variable int poll\_ret = px4\_poll(fds, 1, 1000); but when i try to test the uORB subscription it tells me: px4\_simple\_app: command not found .

Thank you !

---

<div class="post-metadata">

**Author:** ![dagar](https://discuss.px4.io/user_avatar/discuss.px4.io/dagar/32/22_2.png) [@dagar](https://discuss.px4.io/u/dagar)\
**Post date:** [May 16, 2017, 9:26pm UTC](https://discuss.px4.io/t/subscribing-sensor-data-issues/3311/2 "2017-05-16T21:26:53Z")

</div>

Hi @Gesem_Gudino_Mejia, Do you know which version of the PX4 source this is? Try updating to the latest master and rebuilding.

---

<div class="post-metadata">

**Author:** ![Gesem\_Gudino\_Mejia](https://discuss.px4.io/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@Gesem\_Gudino\_Mejia](https://discuss.px4.io/u/Gesem_Gudino_Mejia)\
**Post date:** [May 16, 2017, 9:36pm UTC](https://discuss.px4.io/t/subscribing-sensor-data-issues/3311/3 "2017-05-16T21:36:37Z")

</div>

@dagar srry, what do you mean with version of the source ? when i build the original code that was in the px4\_simple\_app.c it builds correctly and when i test the uORB subscription as the dev guide, it works fine, but when i try to do the same with the code that’s up (without the int poll\_ret = px4\_poll(fds, 1, 1000); line) doesn’t work at all.

---

<div class="post-metadata">

**Author:** ![dagar](https://discuss.px4.io/user_avatar/discuss.px4.io/dagar/32/22_2.png) [@dagar](https://discuss.px4.io/u/dagar)\
**Post date:** [May 16, 2017, 10:34pm UTC](https://discuss.px4.io/t/subscribing-sensor-data-issues/3311/4 "2017-05-16T22:34:11Z")

</div>

When did you checkout PX4? Try a fresh checkout from github to make sure you’re using the latest version.  
Also make sure your compiler versions match what’s in the dev guide. [https://dev.px4.io/en/setup/dev\_env.html](https://dev.px4.io/en/setup/dev_env.html)

---

<div class="post-metadata">

**Author:** ![Gesem\_Gudino\_Mejia](https://discuss.px4.io/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@Gesem\_Gudino\_Mejia](https://discuss.px4.io/u/Gesem_Gudino_Mejia)\
**Post date:** [May 16, 2017, 11:33pm UTC](https://discuss.px4.io/t/subscribing-sensor-data-issues/3311/5 "2017-05-16T23:33:35Z")

</div>

yes, i followed the instructions from the dev guide as far, i began to follow the guide last week, i also have the GCC 5.4, I’ve already realized that it was a missing part in my code, now i’m just trying to understand how the publishing and subscribing code work’s or for what can use it.  
my code end up like this, and its working well.  
Thanks.

> \_\_EXPORT int px4\_simple\_app\_main(int argc, char \*argv);

> int px4\_simple\_app\_main(int argc, char \*argv)  
> {  
> PX4\_INFO(“Hello Sky!”);

> /\* subscribe to sensor\_combined topic _/  
> int sensor\_sub\_fd = orb\_subscribe(ORB\_ID(sensor\_combined));  
> /_ limit the update rate to 5 Hz \*/  
> orb\_set\_interval(sensor\_sub\_fd, 200);

> /\* advertise attitude topic \*/  
> struct vehicle\_attitude\_s att;  
> memset(&att, 0, sizeof(att));  
> orb\_advert\_t att\_pub = orb\_advertise(ORB\_ID(vehicle\_attitude), &att);

> /\* one could wait for multiple topics with this technique, just using one here _/  
> px4\_pollfd\_struct\_t fds[] = {  
> { .fd = sensor\_sub\_fd, .events = POLLIN },  
> /_ there could be more file descriptors here, in the form like:  
> \* { .fd = other\_sub\_fd, .events = POLLIN },  
> \*/  
> };

> int error\_counter = 0;

> while (true) {  
> /\* wait for sensor update of 1 file descriptor for 1000 ms (1 second) \*/  
> int poll\_ret = px4\_poll(fds, 1, 1000);

> ```
> /* handle the poll result */
> if (poll_ret == 0) {
> /* this means none of our providers is giving us data */
> PX4_ERR("Got no data within a second");
> 
> ```

> ```
> } else if (poll_ret < 0) {
> /* this is seriously bad - should be an emergency */
> if (error_counter < 10 || error_counter % 50 == 0) {
> /* use a counter to prevent flooding (and slowing us down) */
> PX4_ERR("ERROR return value from poll(): %d", poll_ret);
> }
> 
> ```

> ```
> error_counter++;
> 
> ```

> ```
> } else {
> 
> ```

> ```
> if (fds[0].revents & POLLIN) {
> /* obtained data for the first file descriptor */
> struct sensor_combined_s raw;
> /* copy sensors raw data into local buffer */
> orb_copy(ORB_ID(sensor_combined), sensor_sub_fd, &raw);
> PX4_INFO("Accelerometer:\t%8.4f\t%8.4f\t%8.4f",
> (double)raw.accelerometer_m_s2[0],
> (double)raw.accelerometer_m_s2[1],
> (double)raw.accelerometer_m_s2[2]);
> 
> ```

> ```
> /* set att and publish this information for other apps*/
> att.q[0] = raw.accelerometer_m_s2[0];
> att.q[1] = raw.accelerometer_m_s2[1];
> att.q[2] = raw.accelerometer_m_s2[2];
> 
> ```

> ```
> orb_publish(ORB_ID(vehicle_attitude), att_pub, &att);
> }
> 
> ```

> ```
> /* there could be more file descriptors here, in the form like:
> * if (fds[1..n].revents & POLLIN) {}
> */
> }
> 
> ```
> 
> }

> return 0;  
> }
