Open benwinston opened 6 years ago
I face the same issue, exactly same line. @benwinston Have you found any solution to this problem?
@srinivastinku No I was unable to resolve.
@benwinston Okay thank you. @odelot Can you please help here.
hi guys, are you using it with arduinoWebSockets v.2.1.0, arduino/esp sdk 2.4.1 and pubsubclient version v2.6?
are you having problem with the example? or have you customize the code already?
This line creates a circular buffer with 1000 bytes that will be used between the websocket layer and the mqtt layer. Maybe try to decrease this number? AWSWebSocketClient awsWSclient(1000);
I've tested with Wemos flash size 4M (1M SPIFFS). I do not have a NodeMCU to test if it is a problem with the board. The example is working here.
On Thu, Apr 11, 2019 at 3:01 AM srinivastinku notifications@github.com wrote:
@benwinston https://github.com/benwinston Okay thank you. @odelot https://github.com/odelot Can you please help here.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/odelot/aws-mqtt-websockets/issues/42#issuecomment-481977151, or mute the thread https://github.com/notifications/unsubscribe-auth/AE34DoiE-l_TUvcuLFJ7OwRyBV9q6i1kks5vfs-pgaJpZM4VKqUk .
Hi, I have stuck with the same problem and finally can make it work now. My code is based on this sketch https://github.com/HarringayMakerSpace/awsiot/blob/master/Esp8266AWSIoTExample/Esp8266AWSIoTExample.ino
which is a bit different from the OP's, but maybe it might shares some characteristics, so I think it might be useful to share my discovery.
I found 3 pitfalls that can cause the problem.
pubsubClient.connect(clientId)
inside the setup()
phase, doing so will cause the error WDT reset
as in the OP. If you look at the example sketch, it has the function pubSubCheckConnect()
which is called inside loop()
to handle all the connection. I don't know the reason but I believe it has some.void pubSubCheckConnect() {
if ( ! pubSubClient.connected()) {
Serial.print("PubSubClient connecting to: "); Serial.print(awsEndpoint);
while ( ! pubSubClient.connected()) {
Serial.print(".");
pubSubClient.connect("ESPthing");
}
Serial.println(" connected");
pubSubClient.subscribe("inTopic");
}
pubSubClient.loop();
}
WiFiClient
and all the certificate variables inside a function, you have to make it global. For exampleThis does not work.
PubSubClient* pubSubClient;
void handleMessageReceived(char* topic, byte* payload, unsigned int len);
void setup() {
WiFiClientSecure wiFiClient;
const char* awsIotEndpoint = ...
const String certificatePemCrt =...
const String privatePemKey =...
const String caPemCrt =...
const unsigned int awsIotPort =...
uint8_t binaryCert[certificatePemCrt.length() * 3 / 4];
int len = b64decode(certificatePemCrt, binaryCert);
wiFiClient.setCertificate(binaryCert, len);
uint8_t binaryPrivate[privatePemKey.length() * 3 / 4];
len = b64decode(privatePemKey, binaryPrivate);
wiFiClient.setPrivateKey(binaryPrivate, len);
uint8_t binaryCA[caPemCrt.length() * 3 / 4];
len = b64decode(caPemCrt, binaryCA);
wiFiClient.setCACert(binaryCA, len);
pubSubClient = new PubSubClient(awsIotEndpoint, 8883, handleMessageReceived, wiFiClient);
}
void loop() {
pubSubCheckConnect();
}
But this works.
PubSubClient* pubSubClient;
void handleMessageReceived(char* topic, byte* payload, unsigned int len);
WiFiClientSecure wiFiClient;
const char* awsIotEndpoint = ...
const String certificatePemCrt =...
const String privatePemKey =...
const String caPemCrt =...
const unsigned int awsIotPort =...
void setup() {
uint8_t binaryCert[certificatePemCrt.length() * 3 / 4];
int len = b64decode(certificatePemCrt, binaryCert);
wiFiClient.setCertificate(binaryCert, len);
uint8_t binaryPrivate[privatePemKey.length() * 3 / 4];
len = b64decode(privatePemKey, binaryPrivate);
wiFiClient.setPrivateKey(binaryPrivate, len);
uint8_t binaryCA[caPemCrt.length() * 3 / 4];
len = b64decode(caPemCrt, binaryCA);
wiFiClient.setCACert(binaryCA, len);
pubSubClient = new PubSubClient(awsIotEndpoint, 8883, handleMessageReceived, wiFiClient);
}
void loop() {
pubSubCheckConnect();
}
Becareful about NTP
sync logic. The example sketch has the following method to handle NTP stuff which works fine.
void setCurrentTime() {
configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
Serial.print("Waiting for NTP time sync: ");
time_t now = time(nullptr);
while (now < 8 * 3600 * 2) {
delay(500);
Serial.print(".");
now = time(nullptr);
}
Serial.println("");
struct tm timeinfo;
gmtime_r(&now, &timeinfo);
Serial.print("Current time: "); Serial.print(asctime(&timeinfo));
}
I do not fully understand it but I found that using other NTP solutions such as what described in this tutorial does not work with AWS IOT.
If you cannot make it work yet, I suggest that you start over with the example sketch that works. Try changing it a little bit by bit and test if it works before going further.
Hope this helps anyone who stuck with this problem.
Hi All,
I am trying to connect to AWS IoT / use MQTT running one of the examples from this project on a NodeMCU. While the sketch runs, an error occurs and the serial monitor shows a WDT Soft Reset.
From using the ESPExceptionDecoder, there appears to be an issue with AWSWebSocketClient. I get the following trace from the Decoder:
The error occurred on line this line from my sketch:
client.connect(clientID)
And the line that caused the error in AWSWebSocketClient.cpp is the call to "getsize" in the available() method:
The code for my sketch follows:
Any suggestions are appreciated.