前提・実現したいこと
Wifiチップ(ESP8266)とAWS IoTでMQTT通信を行うアプリケーションを作成しております。
発生している不具合はESP8266からAWS IoTのWebSocketを張るところで失敗しています。
5/30までは複数の端末から正常にAWS IoTにMQTT通信を行えておりました。
6/2から急にMQTT通信が行えなくなってしましました。AWSのサポートにも連絡し、現在返信待ちです。
発生している問題・エラーメッセージ
ESP8266上のログ
Transmit NTP Request sendNTPpacket : ntp.nict.jp Receive NTP Response ntp begin 3784 - conn: 1 - (27032) pm open,type:2 0 0 error connection to the websocket server connected 14941 - conn: 2 - (9312) 0 error connection to the websocket server 25458 - conn: 3 - (7912) 0 error connection to the websocket server 35592 - conn: 4 - (6344) 0 error connection to the websocket server 60673 - conn: 5 - (19736) 0 error connection to the websocket server 81935 - conn: 6 - (19512)
該当のソースコード
C言語
1bool connect () { 2 3 if (client == NULL) { 4 client = new MQTT::Client<IPStack, Countdown, maxMQTTpackageSize, maxMQTTMessageHandlers>(ipstack); 5 } else { 6 7 if (client->isConnected ()) { 8 client->disconnect (); 9 } 10 delete client; 11 client = new MQTT::Client<IPStack, Countdown, maxMQTTpackageSize, maxMQTTMessageHandlers>(ipstack); 12 } 13 14 //delay is not necessary... it just help us to get a "trustful" heap space value 15 delay (100); 16 Serial.print (millis ()); 17 Serial.print (" - conn: "); 18 Serial.print (++connection); 19 Serial.print (" - ("); 20 Serial.print (ESP.getFreeHeap ()); 21 Serial.println (")"); 22 23 int rc = ipstack.connect(aws_endpoint, port); 24 if (rc != 1) 25 { 26 Serial.println("error connection to the websocket server"); 27 return false; 28 } else { 29 Serial.println("websocket layer connected"); 30 } 31 32 Serial.println("MQTT connecting"); 33 MQTTPacket_connectData data = MQTTPacket_connectData_initializer; 34 data.MQTTVersion = 3; 35 char* clientID = generateClientID (); 36 data.clientID.cstring = clientID; 37 rc = client->connect(data); 38 delete[] clientID; 39 if (rc != 0) 40 { 41 Serial.print("error connection to MQTT server"); 42 Serial.println(rc); 43 return false; 44 } 45 Serial.println("MQTT connected"); 46 return true; 47} 48
試したこと
・IPStackライブラリーのconnect関数を使ってAWS IoTにweb socketを貼ろうとしてる。
・IPStackのconnectはhttps://www.arduino.cc/en/Reference/ClientConnectをラッパーしたもの。
・ClientConnectの返り値を確認したところ0を返していた。
・チップからAWS IoTにWebSocketを張る箇所で失敗している
・wifiチップは複数あり、1台のみAWS IoTに接続できる。
・ClientIdが重複している可能性を考えて、接続可能な1台をオフラインにして、接続できない端末で接続を試みたが失敗
補足情報(FW/ツールのバージョンなど)
あなたの回答
tips
プレビュー