WiFi SSIDとPASSWORDのconst char*宣言でエラーが発生する

ESP32のWiFi接続で今まではSSIDとPASSWORDの設定を以下のようにしていた。

const char* ssid = "MY SSID";
const char* password = "MY PASSWORD";

しかし、以下のようなエラーが突然発生。

[Warning] Output path is not specified. Unable to reuse previously compiled files. Build will be slower. See README.
構成をロード中…
パッケージを初期化中…
ボードを準備中…
検証中…
:121:28: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
  WiFi.begin(ssid, password);
^
C:\Program Files (x86)\Arduino\libraries\WiFi\src/WiFi.h:79:9: note:   initializing argument 1 of 'int WiFiClass::begin(char*, const char*)'
int begin(char* ssid, const char *passphrase);
        ^
exit status 1
IntelliSense configuration already up to date. To manually rebuild your IntelliSense configuration run "Ctrl+Alt+I"

「const char *から char *への無効な変換」と書かれているようだったので以下のようにコードを修正した。

char* ssid = "MY SSID";
const char* password = "MY PASSWORD";み

みたところ、WiFi.hに記載されている宣言にbegin()はあるが、その引数の指定がSSIDは「char*型」でPASSWORDは「const char*型」のようになっていた。

    /* Start Wifi connection with passphrase
    * the most secure supported mode will be automatically selected
    *
    * param ssid: Pointer to the SSID string.
    * param passphrase: Passphrase. Valid characters in a passphrase
    *        must be between ASCII 32-126 (decimal).
    */
   int begin(char* ssid, const char *passphrase);

WiFiのライブラリバージョンによって少し仕様が変わったのかもしれないが、とりあえずSSIDの型宣言を変えたらコンパイルが落ち着いてくれた。


この記事が気に入ったらサポートをしてみませんか?