インターネット老人おぢさん

MacBookPro(BigSur)でVSCode(PlatformIO)からM5StickCのビルドアップロードをしたかった

最終更新:2021年04月20日 03時58分60秒(初公開:2021年04月20日 03時58分60秒

MacBookPro(BigSur)でVSCode(PlatformIO)からM5StickCのビルドアップロードをしたかった

結論から書いてますが、うまく行かなかった話です。
同様の設定でWindowsからはうまく行ったので、ライブラリ側でなんかあるんじゃないかと疑ってます…
ソースを見ても分からなかったので諦めました。

ソースコード解説

main.cpp

*ssid と *password を適宜設定してください。
必要なライブラリ群のインストールあるいはパスの設定に問題がなければビルドは通るはず。

#include <ssl_client.h>
	#include <WiFiClientSecure.h>
	#include <HTTPClient.h>
	#include <WiFi.h>
	#include <WiFiMulti.h>
	#include "M5StickC.h"
	#include "M5Display.h"
	

	const char *ssid = "(your SSID)";
	const char *password = "(your PASSWORD)";
	

	void view(String message)
	{
	    Serial.println(message);
	    M5.Lcd.println(message);
	}
	void Wifi_connect()
	{
	    int cnt = 0;
	    M5.Lcd.printf("Connecting to %s\n", ssid);
	    WiFi.begin(ssid, password);
	    while (WiFi.status() != WL_CONNECTED)
	    {
	        cnt++;
	        delay(500);
	        M5.Lcd.print(".");
	        if (cnt % 10 == 0)
	        {
	            WiFi.disconnect();
	            WiFi.begin(ssid, password);
	            M5.Lcd.println("");
	        }
	        if (cnt >= 30)
	        {
	            ESP.restart();
	        }
	    }
	    M5.Lcd.printf("\nWiFi connected\n");
	}
	void send(String message)
	{
	    const char *host = "notify-api.line.me";
	    const char *token = "ZryKC3jzul3cCI9ycEaAm3RvXZHamCLZeReDzCmuWFn";
	    WiFiClientSecure client;
	    Serial.println("Try");
	    //LineのAPIサーバに接続
	    if (!client.connect(host, 443))
	    {
	        Serial.println("Connection failed");
	        return;
	    }
	    Serial.println("Connected");
	    //リクエストを送信
	    String query = String("message=") + message;
	    String request = String("") +
	                     "POST /api/notify HTTP/1.1\r\n" +
	                     "Host: " + host + "\r\n" +
	                     "Authorization: Bearer " + token + "\r\n" +
	                     "Content-Length: " + String(query.length()) + "\r\n" +
	                     "Content-Type: application/x-www-form-urlencoded\r\n\r\n" +
	                     query + "\r\n";
	    client.print(request);
	    //受信終了まで待つ
	    while (client.connected())
	    {
	        String line = client.readStringUntil('\n');
	        Serial.println(line);
	        if (line == "\r")
	        {
	            break;
	        }
	    }
	    String line = client.readStringUntil('\n');
	    Serial.println(line);
	}
	void clean()
	{
	    M5.Lcd.fillScreen(BLACK);
	    M5.Lcd.setCursor(0, 0);
	    M5.Lcd.println("push [M5] button: call\nright side button: gohan(eatting)");
	}
	void reset(String message, String display)
	{
	    clean();
	    M5.Lcd.println("sending " + display + " message...");
	    send(message);
	    M5.Lcd.println("OK");
	    delay(5000);
	    clean();
	}
	void setup()
	{
	    M5.begin();
	    M5.Axp.ScreenBreath(9);
	    setCpuFrequencyMhz(80);
	    M5.Lcd.setRotation(3);
	    M5.Lcd.fillScreen(BLACK);
	    Wifi_connect();
	    M5.Lcd.setTextSize(2);
	    clean();
	}
	void loop()
	{
	    M5.update();
	    M5.Lcd.setCursor(0, 40);
	    if (M5.BtnA.wasPressed())
	    {
	        reset("ちょっと来て", "help");
	    }
	    else if (M5.BtnB.wasPressed())
	    {
	        reset("ご飯できたよ", "gohan");
	    }
	}


参考ページ:https://github.com/shimajima-eiji/Hosting_sample_codes/blob/main/JAMStack_nomuraya/tech/m5stickc/source.cpp

platformio.ini

問題はシリアルポートを使っての通信。
接続には成功しているけど、通信がうまくいかないのでボーレート: 115200とかポート設定辺りが怪しいんでしょうが、実行してもエラーメッセージが表示されるので、これを解読して対応しなければならないのですが、朝の1時間で解決できなかったので保留中です。

[env:m5stick-c]
platform = espressif32
board = m5stick-c
framework = arduino
lib_deps = M5StickC
monitor_speed = 115200


参考ページ:https://github.com/shimajima-eiji/Hosting_sample_codes/blob/main/JAMStack_nomuraya/tech/m5stickc/platformio.ini

© 2020-2021のむらやごろう(@elder_uncle)

当サイトの全てのコンテンツを転載・無断での引用もお断りしています。