arduino esp8266 ota 資料

http://www.yfrobot.com/thread-11979-1-1.html

https://www.jianshu.com/p/fd9033750b1f

https://www.cnblogs.com/kekeoutlook/p/10618063.html

https://www.wandianshenme.com/play/arduino-ota-arduino-ide-ota-upgrade-esp8266-application/
上個的原文是下面的
https://www.bakke.online/index.php/2017/06/02/self-updating-ota-firmware-for-esp8266/

https://blog.csdn.net/xh870189248/article/details/80095139

ota
發佈固件鏡像
在所有的函數外,將一個版本號常量變量添加到您的程序。每當您準備發佈時,請按您選擇的任何約定來增加此版本號,例如每次簡單增加一個,或基於當前日期和增加的內部版本號等更復雜的規則。

const int FW_VERSION = 1244;

編譯程序(Ctrl + R),然後導出二進制文件。(Ctrl + Alt + S)導出二進制文件,將生成一個鏡像文件到您的程序所在的相同文件夾中。實際名稱將取決於您正在編譯的特定電路板

void checkForUpdates() {
  String mac = getMAC();
  String fwURL = String( fwUrlBase );
  fwURL.concat( mac );
  String fwVersionURL = fwURL;
  fwVersionURL.concat( ".version" );

  Serial.println( "Checking for firmware updates." );
  Serial.print( "MAC address: " );
  Serial.println( mac );
  Serial.print( "Firmware version URL: " );
  Serial.println( fwVersionURL );

  HTTPClient httpClient;
  httpClient.begin( fwVersionURL );
  int httpCode = httpClient.GET();
  if( httpCode == 200 ) {
    String newFWVersion = httpClient.getString();

    Serial.print( "Current firmware version: " );
    Serial.println( FW_VERSION );
    Serial.print( "Available firmware version: " );
    Serial.println( newFWVersion );

    int newVersion = newFWVersion.toInt();

    if( newVersion > FW_VERSION ) {
      Serial.println( "Preparing to update" );

      String fwImageURL = fwURL;
      fwImageURL.concat( ".bin" );
      t_httpUpdate_return ret = ESPhttpUpdate.update( fwImageURL );

      switch(ret) {
        case HTTP_UPDATE_FAILED:
          Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
          break;

        case HTTP_UPDATE_NO_UPDATES:
          Serial.println("HTTP_UPDATE_NO_UPDATES");
          break;
      }
    }
    else {
      Serial.println( "Already on latest version" );
    }
  }
  else {
    Serial.print( "Firmware version check failed, got HTTP response code " );
    Serial.println( httpCode );
  }
  httpClient.end();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章