Nilton Schumacher F
Nilton Schumacher F

Reputation: 1180

Google cloud MQTT with Esp32 Reusing JWT error

I am trying to send fake temperature data from an ESP32 to Google Cloud with Arduino IDE and using this library https://github.com/GoogleCloudPlatform/google-cloud-iot-arduino. I created a registry and a device on google iot core. On my side I manually put the csa certificate on the ESP32 and correctly set all parameters and private key string in 'ciotc_config.h'. When I try to connect I get in the Serial Monitor the following output repeting itself:

ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
Setup.....
Starting wifi
Connecting to WiFi
Connected
Waiting on time sync...

Esp32-mqtt:

void setupWifi() {
Serial.println("Starting wifi");

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(100);
}
Serial.println("Connected");
configTime(0, 0, ntp_primary, ntp_secondary);
Serial.println("Waiting on time sync...");
while (time(nullptr) < 1510644967) {
delay(10);
}
}

void connectWifi() {
Serial.print("checking wifi...");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}
} 

I made a change in the main.cpp just because I will not be working with those sensors:

unsigned long lastMillis = 0;

void loop() {
mqtt->loop();
delay(10);  // <- fixes some issues with WiFi stability

if (!mqttClient->connected()) {
connect();
}

if (millis() - lastMillis > 60000) {
Serial.println("Publishing value");
lastMillis = millis();
float temp = 33;
float hum = 50;
StaticJsonDocument<100> doc;
doc["temp"] = temp;
doc["humidity"] = hum;
serializeJson(doc, buffer);
//publishTelemetry(mqttClient, "/sensors", getDefaultSensor());
publishTelemetry( buffer);
}
}

Image from PUB: Pub image

Upvotes: 0

Views: 813

Answers (2)

Gabe Weiss
Gabe Weiss

Reputation: 3342

It doesn't look like you're ever successfully connecting.

In your output, I see connecting... so it's in the mqttConnect() call, but it never outputs connected! so it's stuck in the while loop where it's calling getJwt()

Now, why it's not outputting the mqtt errors may mean your errors are related to something else, and the mqtt client is totally fine, which is why you aren't seeing any other output. As a debugging check, I'd put a Serial.println("fubar") in the mqttConnect() call above the delay(1000) and see if you get other output there, pointing at some other connection error other than an mqtt connection problem.

Upvotes: 0

FrancescoAzzola
FrancescoAzzola

Reputation: 2654

I guess it is just a debug information. It could be in the line where you write the JWT tag information.

I wrote a tutorial about how to connect the ESP32 to Google Cloud IoT with full source code that is very similar to your code but It didn't repeat that info. You can give a look https://www.survivingwithandroid.com/cloud-iot-core-esp32/ and you can reuse the code. Let me know if I can help you somehow.

Upvotes: 1

Related Questions