Petoi Doc Center
🇹🇭 Thai
🇹🇭 Thai
  • ยินดีต้อนรับสู่ Petoi Doc Center
  • Infrared Remote
    • รีโมทคอนโทรล
  • Mobile App
    • คาลิเบเตอร์และคอนโทรลเลอร์
  • Desktop APP
    • การแนะนำเบื้องต้น
    • ตัวอัปโหลดเฟิร์มแวร์
    • การคาลิเบรทข้อต่อ
    • สกิลคอมโพสเซอร์
  • Arduino IDE
    • อัปโหลด Sketch สำหรับ NyBoard
    • อัปโหลด Sketch สำหรับ BiBoard
    • การคาลิเบรทด้วย Arduino IDE
    • ซีเรียลมอนิเตอร์
  • API
    • 🖇️ซีเรียลโปรโตคอล
    • 🐍คู่มือผู้ใช้ Python SerialMaster
    • 🐛MicroPython คอนโทรลเลอร์
      • การเรียกใช้ MicroPython บน ESP8266
      • ติดตั้ง WebREPL
      • การใช้โปรโตคอล ESP-NOW
    • 🍓การสื่อสารผ่านพอร์ตซีเรียลของ Raspberry Pi
    • 🤖ROS
  • Nyboard
    • NyBoard V1_0
    • NyBoard V1_1
  • BIBOARD
    • คู่มือเริ่มต้นใช้งาน BiBoard ฉบับรวบลัด
    • Demo Applications
      • 1.GPIO port
      • 2.Serial port
      • 3.Analog-digital converter
      • 4.Digital-Analog Converter
      • 5.EEPROM (Electrically Erasable Programmable read only memory)
      • 6.Gyro IMU(MPU6050)
      • 7.Infrared remote control
      • 8.PWM(Pulse Width Modulation)
      • 9.Servo(under construction)
      • 10.Classic Bluetooth serial port SPP
      • 11.Bluetooth low energy (BLE) serial port pass-through
      • 12.File system SPIFFS
      • 13.Add hardware partition configuration option in Arduino IDE
      • 14.Play MP3
      • 15.The usage of Wi-Fi OTA(Over-The-Air)
  • Communication Modules
    • Introduction
    • USB Uploader (CH340C or CH343G)
    • Dual Mode Bluetooth
    • WiFi ESP8266
      • ESP8266 + Python Scripts Implement wireless crowd control
  • Extensible Modules
    • Introduction
    • MU Camera
    • Ultrasonic Sensor
    • Light Sensor
    • Touch Sensor
    • Gesture Sensor
    • PIR Motion Sensor
  • Applications
    • Skill Creation
    • OpenCat Imitation Tutorial
    • Programmable Puppet Character
  • History
    • Upload Sketch For NyBoard (software 1.0)
  • Technical Support
    • 🛠️Supporting Application and Software
    • 🙋‍♂️FAQ(Frequently Asked Questions)
  • Useful Links 🕸
    • 🔭Official Site of Petoi
    • 💿GitHub of OpenCat
    • 🎪PetoiCamp (Forum)
Powered by GitBook
On this page
  • 1. What is OTA?
  • OTA operation in Arduino program

Was this helpful?

Export as PDF
  1. BIBOARD
  2. Demo Applications

15.The usage of Wi-Fi OTA(Over-The-Air)

The Arduino demo of ESP32 provides the function of OTA (updating/uploading a new program to ESP32 using Wi-Fi)

Previous14.Play MP3NextIntroduction

Last updated 2 years ago

Was this helpful?

1. What is OTA?

การกำหนดค่าของ BiBoard ของเราคือ 16MB Flash และพาร์ติชันเฉพาะมีดังนี้:

OTA ดำเนินการพื้นที่ข้อมูล OTA เป็นหลัก ได้แก่ พื้นที่ APP1 และ APP2 หลักการคือ:

  • BiBoard เรียกใช้เฟิร์มแวร์ด้วยฟังก์ชัน OTA ในขณะนี้ การบูตชี้ไปที่พื้นที่ APP1

  • คำสั่ง OTA ถูกส่งไปยัง ESP32 ผ่าน Wi-Fi และไฟล์ไบนารีของโปรแกรมอัปเกรดจะถูกถ่ายโอนไปยังพื้นที่ APP2

  • หากการส่ง APP2 เสร็จสิ้นและการตรวจสอบยืนยันสำเร็จ ข้อมูล OTA จะชี้ไปที่พื้นที่ APP2 และครั้งต่อไปที่เริ่มต้นจากพื้นที่เฟิร์มแวร์ที่อัปเดตแล้ว (APP2) ข้อมูล APP1 จะถูกเก็บไว้ ครั้งต่อไป OTA จะเขียนไปยังพื้นที่ APP1 เพื่อเขียนทับเฟิร์มแวร์เก่า

  • หากการส่ง APP2 ไม่เสร็จสมบูรณ์เนื่องจากข้อผิดพลาดในการส่งเครือข่าย เนื่องจาก APP2 ไม่ผ่านการตรวจสอบ ข้อมูล OTA จะไม่ชี้ไปที่พื้นที่ APP2 โปรแกรมในพื้นที่ APP1 จะยังคงทำงานหลังจากเริ่มต้นการรีเซ็ต และพื้นที่ APP2 ที่เสียหายจะถูกลบและเขียนทับอย่างสมบูรณ์ระหว่าง OTA ถัดไป

OTA operation in Arduino program

ในการสาธิต ก่อนอื่นให้กำหนดค่า WiFi และกำหนดค่าโหมด WiFi เป็น STA (สถานี โหมดสถานีฐาน) เปิดใช้งานฟังก์ชัน WiFi และป้อนรหัสผ่านบัญชี "WiFi.begin(ssid, password);"

  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();

เมื่อเชื่อมต่อ Wi-Fi สำเร็จ ที่อยู่ IP จะถูกพิมพ์ผ่านพอร์ตอนุกรม หากการเชื่อมต่อผิดพลาด ESP32 จะรีสตาร์ท

ในการสาธิต คุณสามารถกำหนดค่าหมายเลขพอร์ต คีย์ OTA หรือแฮชของคีย์ และพื้นที่และประเภทของ OTA (ระบุโดยค่าเริ่มต้น)

  // Port defaults to 3232
  // ArduinoOTA.setPort(3232);

  // Hostname defaults to esp3232-[MAC]
  // ArduinoOTA.setHostname("myesp32");

  // No authentication by default
  // ArduinoOTA.setPassword("admin");

  // Password can be set with it's md5 value as well
  // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
  // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");

ต่อไปนี้เป็นข้อมูลโค้ดบางส่วนที่คล้ายกับฟังก์ชันการโทรกลับ ซึ่งใช้ในการตัดสินสถานะของแต่ละขั้นตอนของ OTA

  ArduinoOTA
    .onStart([]() {
      String type;
      if (ArduinoOTA.getCommand() == U_FLASH)
        type = "sketch";
      else // U_SPIFFS
        type = "filesystem";

      // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
      Serial.println("Start updating " + type);
    })
    .onEnd([]() {
      Serial.println("\nEnd");
    })
    .onProgress([](unsigned int progress, unsigned int total) {
      Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
    })
    .onError([](ota_error_t error) {
      Serial.printf("Error[%u]: ", error);
      if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
      else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
      else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
      else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
      else if (error == OTA_END_ERROR) Serial.println("End Failed");
    });

  ArduinoOTA.begin();

หลังจากกำหนดค่าตามการสาธิต ให้เรียก "ArduinoOTA.handle();" ในฟังก์ชันลูป ฟังก์ชัน analogWrite ต่อไปนี้ใช้เพื่อแยกแยะผลกระทบของการอัพเดตเฟิร์มแวร์ต่างๆ (โดยการเปลี่ยนค่า)

void loop() {
  ArduinoOTA.handle();
  analogWrite(2, 127);    // test OTA firmware
}

ครั้งแรกที่คุณใช้พอร์ตอนุกรมเพื่อดาวน์โหลด เครื่องมือไพธอน "esptool" จะถูกเรียก คุณสามารถใช้ OTA ได้หลังจากการดาวน์โหลดเสร็จสิ้น ในตัวเลือกพอร์ต คุณจะพบพอร์ตพิเศษตามที่อยู่ IP ซึ่งเป็นที่อยู่ OTA

เลือกที่อยู่นี้ มุมขวาล่างคือที่อยู่ IP ของ ESP32 Dev Module บน BiBoard ของคุณ (192.168.1.178)

ในเวลาเดียวกัน คำเตือนจะปรากฏขึ้น: "ไม่รองรับการมอนิเตอร์แบบอนุกรมบนพอร์ตเครือข่าย เช่น 192.168.1.178 สำหรับโมดูล ESP32 Dev ในล่าสุดนี้"

ESP32 OTA ของ Arduino เหมาะสำหรับการอัปเดตโปรแกรมเท่านั้น และไม่สามารถทำงานดีบักพอร์ตอนุกรมได้ หากคุณต้องการดีบัก BiBoard โปรดเชื่อมต่ออินเทอร์เฟซ USB-C

ดาวน์โหลดโปรแกรม ดังรูป