# Problems with mavlink\_msg\_interval\_pack

**URL:** <https://discuss.px4.io/t/problems-with-mavlink-msg-interval-pack/10037>\
**Category:** MAVLink\
**Created:** [March 18, 2019, 3:06pm UTC](https://discuss.px4.io/t/problems-with-mavlink-msg-interval-pack/10037 "2019-03-18T15:06:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![plin](https://discuss.px4.io/letter_avatar_proxy/v4/letter/p/43a26b/32.png) [@plin](https://discuss.px4.io/u/plin)\
**Post date:** [March 18, 2019, 3:06pm UTC](https://discuss.px4.io/t/problems-with-mavlink-msg-interval-pack/10037/1 "2019-03-18T15:06:28Z")

</div>

Hello,

I’m trying to use the Arduino to request a specific message from the Pixhawk (Attitude #30), but it’s not working. I’ve tried mavlink\_msg\_interval\_pack, mav\_cmd\_set\_message\_interval, and even mavlink\_msg\_data\_stream\_pack which is supposed to be deprecated. I’ve read the thread “Unable to read data on arduino serial monitor” on here but I’m still stuck.

I’m not sure what I’m doing wrong, but I can only see the messages that are sent automatically by Pixhawk (Heartbeat, Timesync, Param\_value, and statustext). Any help would be appreciated. Thanks! Sorry about the format for the code - I tried editing it, but I’m not sure why it’s publishing like this.

This is what I have to request data from the Pixhawk.

void request\_data()  
{  
mavlink\_message\_t msg;  
uint8\_t buf[MAVLINK\_MAX\_PACKET\_LEN];

// Default UART header for Arduino  
int sysid = QUADROTOR;  
int compid = MAV\_COMP\_ID\_ALL;

// To be setup according to the needed information to be requested from the Pixhawk  
int32\_t interval\_us = 1000000; //interval between two messages, in microseconds  
uint16\_t message\_id = 30; // ID of the requested MAVLink message;

```
mavlink_msg_message_interval_pack(sysid, compid, &msg, message_id, interval_us);
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
Serial1.write(buf, len);

```

}

This is what I have to read data from the Pixhawk.

void comm\_receive()  
{

```
mavlink_message_t msg;
mavlink_status_t status;

while (Serial1.available() > 0) {
  uint8_t c = Serial1.read();

// Try to get a new message
if (mavlink_parse_char(MAVLINK_COMM_0, c, &msg, &status)) {
  
  // Handle message
  switch (msg.msgid) {

    case MAVLINK_MSG_ID_HEARTBEAT: // #0: HEARTBEAT
      {
        mavlink_heartbeat_t hb;
        mavlink_msg_heartbeat_decode(&msg, &hb);
        Serial.print("Heartbeat");
      }
      break;   
      
    case MAVLINK_MSG_ID_ATTITUDE: // #30: ATTITUDE
      {
        mavlink_attitude_t att;
        mavlink_msg_attitude_decode(&msg, &att);

        Serial.print("time: "); Serial.println(att.time_boot_ms);
        Serial.print("roll: "); Serial.println(att.roll);
      }
      break;      

    default:
      break;
  }
}

```

}  
}

---

<div class="post-metadata">

**Author:** ![JulianOes](https://discuss.px4.io/user_avatar/discuss.px4.io/julianoes/32/30_2.png) [@JulianOes](https://discuss.px4.io/u/JulianOes)\
**Post date:** [March 19, 2019, 8:30am UTC](https://discuss.px4.io/t/problems-with-mavlink-msg-interval-pack/10037/2 "2019-03-19T08:30:55Z")

</div>

Have you seen this?

> [@Unable to read data on arduino serial monitor](http://discuss.px4.io/t/unable-to-read-data-on-arduino-serial-monitor/8639):
>
> Hello, I am new to this and am trying to read data on the serial monitor. I have installed mavlink V1 and have tried different variations of this code. My teensyduino is connected to the PX4 cube through the telem2 port and then the teensyduino is connected to my laptop through the USB connection. My code is below. #include \<mavlink.h\> void setup() { Serial.begin(57600); Serial1.begin(57600); } void reqStreams() { int i; mavlink\_message\_t message; mavlink\_request\_data\_stream\_t …

---

<div class="post-metadata">

**Author:** ![plin](https://discuss.px4.io/letter_avatar_proxy/v4/letter/p/43a26b/32.png) [@plin](https://discuss.px4.io/u/plin)\
**Post date:** [March 19, 2019, 12:05pm UTC](https://discuss.px4.io/t/problems-with-mavlink-msg-interval-pack/10037/3 "2019-03-19T12:05:46Z")

</div>

Hello! Yes, I have. It doesn’t seem like they were able to resolve the issue. At least, I tried running the programs they wrote and they didn’t work on my end.

---

<div class="post-metadata">

**Author:** ![JulianOes](https://discuss.px4.io/user_avatar/discuss.px4.io/julianoes/32/30_2.png) [@JulianOes](https://discuss.px4.io/u/JulianOes)\
**Post date:** [March 19, 2019, 3:45pm UTC](https://discuss.px4.io/t/problems-with-mavlink-msg-interval-pack/10037/4 "2019-03-19T15:45:53Z")

</div>

> [@plin](#):
>
> int sysid = QUADROTOR;

What’s this? You should use 1 if your drone’s system ID is 1.

---

<div class="post-metadata">

**Author:** ![plin](https://discuss.px4.io/letter_avatar_proxy/v4/letter/p/43a26b/32.png) [@plin](https://discuss.px4.io/u/plin)\
**Post date:** [March 19, 2019, 6:14pm UTC](https://discuss.px4.io/t/problems-with-mavlink-msg-interval-pack/10037/5 "2019-03-19T18:14:02Z")

</div>

Whoops sorry. That was supposed to be a comment, but it is set to ‘1’ on my end. I was able to get request\_data\_stream to work, but I thought it was no longer supported? I’m still not sure how to get message\_interval\_pack to work. Do you have any ideas?

---

<div class="post-metadata">

**Author:** ![isb](https://discuss.px4.io/letter_avatar_proxy/v4/letter/i/9dc877/32.png) [@isb](https://discuss.px4.io/u/isb)\
**Post date:** [March 20, 2019, 3:55am UTC](https://discuss.px4.io/t/problems-with-mavlink-msg-interval-pack/10037/6 "2019-03-20T03:55:02Z")

</div>

I updated [this thread](https://discuss.px4.io/t/unable-to-read-data-on-arduino-serial-monitor/8639/15) with the code I currently use that works for me. Hope it helps.

---

<div class="post-metadata">

**Author:** ![plin](https://discuss.px4.io/letter_avatar_proxy/v4/letter/p/43a26b/32.png) [@plin](https://discuss.px4.io/u/plin)\
**Post date:** [March 20, 2019, 1:11pm UTC](https://discuss.px4.io/t/problems-with-mavlink-msg-interval-pack/10037/7 "2019-03-20T13:11:24Z")

</div>

Thank you! I took a look, but it doesn’t seem to be working for me. All I see on the Serial monitor are the “Command Sent” lines you printed in the loop. I made it so the default in the switch statements printed the message ID’s and it looks like there are heartbeat, timesync, statustext, param\_value, and command\_ack messages being sent. I’ll keep playing around with it though.

Does it matter what I set for the first argument of mavlink\_parse\_char? How did you decide it should be MAVLINK\_COMM\_0?
