Advertisement
aspsda

main

May 20th, 2022
1,145
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "mavlink.h"
  2. #include <WiFi.h>
  3. #include <WiFiUdp.h>
  4. #include <esp_task_wdt.h>
  5.  
  6. const char * ssid = "i-121"; //  your network SSID (name)
  7. const char * pwd = "87654321";    // your network password (use for WPA, or use as key for WEP)
  8. const char * udpAddr = "192.168.137.1"; // target ip MissionPlanner/UDP server
  9. const int udpPort = 14022;      // local port to listen on
  10. uint8_t mp[300]; // buffer data dari mission planner
  11.  
  12. WiFiUDP udp;
  13.  
  14. void setup() {
  15.   Serial2.begin(57600); //RXTX from Pixhawk (Port 19,18 Arduino Mega)
  16.   Serial.begin(57600);
  17.   WiFi.begin(ssid, pwd);
  18.   while (WiFi.status() != WL_CONNECTED) {
  19.     delay(500);
  20.   }
  21.   udp.begin(udpPort);
  22. }
  23.  
  24. void loop() {
  25.   px_to_mp();
  26. }
  27.  
  28. void send_it(char* _data, uint8_t frameSize, char* plaint) {
  29.   udp.beginPacket(udpAddr, udpPort);                    // gabungkan arr1 (header) dengan arr2 (payload+checksum)
  30.   udp.write((const uint8_t *)_data, frameSize); // kirim data mavlink dari PX ke MP menggunakan UDP
  31.   udp.endPacket();
  32.  
  33.   uint8_t packetSize = udp.parsePacket();
  34.   if(packetSize) {
  35.     if(udp.read(mp, packetSize)) {
  36.       Serial2.write((const uint8_t *)mp, packetSize);
  37.     }
  38.   }
  39. }
Advertisement
RAW Paste Data Copied
Advertisement