Hello, I’m new user trying to learn about all this topics and I’m using a PixHawk4 and an ESP32 this is connected to the telem2 port and I’m triying to send a heartbeat and watching it in MavProxy but I can’t watch any message I tried with a heartbeat, with a distance sensor and statustext messages but I can’t watch them
this is my code:
#include <Arduino.h>
#include <MAVLink.h>
#include <ESP32Servo.h>
#include <NewPing.h>
#define RX2_PIN 16 // Cambia este valor según tu configuración
#define TX2_PIN 17 // Cambia este valor según tu configuración
HardwareSerial SerialMAV(1); // Usar UART2
void MessageToPixHawk(const char* message);
void sendHeartbeat(void);
float distance = 0;
void setup() {
Serial.begin(57600);
SerialMAV.begin(57600, SERIAL_8N1, RX2, TX2); // Configurar puerto serial para MAVLink
Serial.println("ESP32 inicializado correctamente.");
}
void requestDataStream(uint8_t target_system, uint8_t target_component, uint8_t stream_id, uint16_t frequency, uint8_t start_stop) {
mavlink_message_t msg;
uint8_t buf[MAVLINK_MAX_PACKET_LEN];
mavlink_msg_request_data_stream_pack(1, 200, &msg, target_system, target_component, stream_id, frequency, start_stop);
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
SerialMAV.write(buf, len);
}
void loop() {
static uint32_t lastRequest = 0;
uint32_t now = millis();
// Enviar mensaje cada 5 segundos
if (now - lastRequest > 5000) {
lastRequest = now;
//MessageToPixHawk("WAZAAAAA");
sendHeartbeat();
}
delay(100); // Evitar el "watchdog timer" reset
}
void MessageToPixHawk(const char* message){
mavlink_message_t msg;
uint8_t buffer[ MAVLINK_MAX_PACKET_LEN ];
uint16_t len;
mavlink_msg_statustext_pack( 2, 200, &msg, MAV_SEVERITY_INFO, message, 0, 0 );
len = mavlink_msg_to_send_buffer( buffer, &msg );
SerialMAV.write( buffer, len );
// Depuración
Serial.print("Enviando mensaje a PixHawk: ");
Serial.println(message);
}
void sendHeartbeat(void){
mavlink_message_t msg;
uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
uint16_t len;
mavlink_msg_heartbeat_pack(20, MAV_COMP_ID_PERIPHERAL, &msg, MAV_TYPE_HEXAROTOR, MAV_AUTOPILOT_PX4, MAV_MODE_MANUAL_ARMED, 0, MAV_STATE_STANDBY);
len = mavlink_msg_to_send_buffer(buffer, &msg);
SerialMAV.write(buffer, len);
}
can somebody help me please??