デジタルピン入力の状態(ON/OFF)を定期的にLINE通知したいのですが、数百回に一回程度の確率で稀にエラーになってフリーズし、その後動作しなくなってしまいます。
対策を教えてください。
開発環境等
・spresense本体+spresense lte拡張ボード
・Arduino IDE
コード(一部)
void send(String message) {
const char* host = "notify-api.line.me";
const char* token = "XXX";
LTETLSClient tlsClient;
// SDカードから証明書ファイルを読み込む
File rootCertsFile = theSD.open(ROOTCA_FILE, FILE_READ);
tlsClient.setCACert(rootCertsFile, rootCertsFile.available());
rootCertsFile.close();
HttpClient client = HttpClient(tlsClient, server, port);
LTE lteAccess;
// LTE接続開始
while (true) {
if (lteAccess.begin() == LTE_SEARCHING) {
if (lteAccess.attach(LTE_APN, LTE_USER_NAME, LTE_PASSWORD) == LTE_READY) {
Serial.println("attach succeeded.");
break;
}
Serial.println("An error occurred, shutdown and try again.");
lteAccess.shutdown();
sleep(1);
}
}
//LineのAPIサーバに接続
if (!client.connect(host, 443)) {
Serial.println("Connection failed");
client.stop();
lteAccess.shutdown();
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);
client.stop();
lteAccess.shutdown();
}
実行時のシリアルコンソール表示
上記コードの
String line = client.readStringUntil('\n');
Serial.println(line);
個所にて
HTTP/1.1 200
Server: nginx
Date: Tue, 16 Jun 2020 18:36:04 GMT
Content-Type: application/json;charset=UTF-8
up_assert: Assertion failed at file:altcom/gw/apicmdgw.c line: 381 task: apicmdgw_main
up_dumpstate: sp: 0d04f26c
up_dumpstate: IRQ stack:
up_dumpstate: base: 0d035a00
up_dumpstate: size: 00000800
up_dumpstate: used: 000000f0
up_dumpstate: User stack:
up_dumpstate: base: 0d04f2f0
up_dumpstate: size: 00000fd4
up_dumpstate: used: 00000238
up_stackdump: 0d04f260: 00000003 0d034d94 00000001 00000003 00000000 0d0101a9 00000000 000007d6
up_stackdump: 0d04f280: 000007d8 0d048260 000007e8 0d01036b 00000010 000007d8 00000001 0d048260
up_stackdump: 0d04f2a0: 0d036d28 c5baedfe 0d0471c0 0d04b280 0d010201 0d0471c0 00000000 00000000
up_stackdump: 0d04f2c0: 00000000 00000000 00000000 0d01051b 00000002 0d04f316 00000101 00000000
up_stackdump: 0d04f2e0: 00000000 0d003b4f 00000000 00000000 deadbeef 0d04f300 0d04f30e 00000000
up_taskdump: Idle Task: PID=0 Stack Used=0 of 0
up_taskdump: hpwork: PID=1 Stack Used=584 of 2028
up_taskdump: lpwork: PID=2 Stack Used=352 of 2028
up_taskdump: lpwork: PID=3 Stack Used=352 of 2028
up_taskdump: lpwork: PID=4 Stack Used=352 of 2028
up_taskdump: init: PID=5 Stack Used=1448 of 8172
up_taskdump: cxd56_pm_task: PID=6 Stack Used=320 of 996
up_taskdump: <pthread>: PID=7 Stack Used=320 of 1020
up_taskdump: thrdpool_no841: PID=2804 Stack Used=396 of 2004
up_taskdump: thrdpool_no842: PID=2805 Stack Used=496 of 980
up_taskdump: altmdm_pm_task: PID=2806 Stack Used=432 of 996
up_taskdump: altmdm_xfer_task: PID=2807 Stack Used=568 of 1500
up_taskdump: apicmdgw_main: PID=2808 Stack Used=648 of 4052