OTAとは、IoTデバイスの組み込みソフトウェアを、無線通信を介してアップデートすることです。
当然IoTデバイスには、テスラ社のEVも含まれます。
OTAの身近な例には、スマートフォンや携帯電話のソフトウェアのアップデートがあります。
また日本ではあまり流行りませんでしたが、BlackBerryというPDAを開発した会社(カナダのブラックベリー社)は、その組み込みOS(ブラックベリーOS、QNX)技術の強みを生かして、カーエレクトロニクスの分野でも業績を上げているそうです。
怖い話ですが、IoTデバイスの組み込みソフトウェアの品質の課題と合わせて、その制御系が乗っ取られるというかつてのSFの世界の話が、現実になっているわけです。なので、セキュリティーとか堅牢性といった言葉に代表される運用、管理が重要になります。
さっそくサンプルコードを掲載します。
https://github.com/ayushsharma82/AsyncElegantOTA で公開されているライブラリを使うと簡単に、
ESP32 ESPDuino-32でもESP8266 ESP-12FでもOTA(Pull型)が可能になります。
/*
Rui Santos
Complete project details at
https://RandomNerdTutorials.com/esp8266-nodemcu-ota-over-the-air-arduino/
https://randomnerdtutorials.com/esp32-ota-over-the-air-arduino/
This sketch shows a Basic example from the AsyncElegantOTA library: ESP8266_Async_Demo & ESP32_Async_Demo
https://github.com/ayushsharma82/AsyncElegantOTA
--------------------------------------------------------------------
Modified for waves ESP32 ESPDuino-32 w/Prototype Shield → ESP32 Dev Module
HiLetgo ESP8266 ESP-12F w/Prototype Shield → WeMos R1 D1
by jk1brk
Last update 2021/3/22
*/
// Import required libraries
#include <Arduino.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
String id = "Hi! I am ESP32.";
#else
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
String id = "Hi! I am ESP8266.";
#endif
// Replace with your network credentials
const char* ssid = "SSID";
const char* password = "PASSWORD";
AsyncWebServer server(80);
void setup(void) {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
///////////////////////////////////////////////////////
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", id);
});
///////////////////////////////////////////////////////
AsyncElegantOTA.begin(&server); // Start ElegantOTA
server.begin();
Serial.println("HTTP server started");
}
void loop(void) {
AsyncElegantOTA.loop();
}
向かって左:ESPDuino-32 w/BME280 on Prototype Shiled、向かって右:ESP-12F w/LEDs on Prototype Shiled
BME280というセンサーチップは、ボッシュ社製であったことを思い出してください。
余談ですが、wifeは外資系自動車部品メーカー(ボッシュ社ではありません。)でヒューマン・リソースの仕事をしています。なので案外私よりも詳しかったりします。
ESP-12F w/LEDs on Prototype Shiledの回路図です。 取扱いに関しては、各自の責任でお願い致します。
【参照記事】
【参考記事】