0

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

Nilton Schumacher F
  • 814
  • 3
  • 13
  • 43

2 Answers2

1

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.

FrancescoAzzola
  • 2,666
  • 2
  • 15
  • 22
  • Hey mate, so I'm doing all the steps but I got into a question. They asked to get the cert from this https://pki.goog/roots.pem, I downloaded it, but there is like 15+ cert, which one should I get? – Nilton Schumacher F May 05 '20 at 20:14
  • You can add the root cert – FrancescoAzzola May 05 '20 at 20:23
  • I updated my question, in the esp32-mqtt connection code, there is 2 connections to wifi made, as I inserted in the question. This made my code keep repeating cheking for wifi, is ok to remove that part? – Nilton Schumacher F May 05 '20 at 20:37
  • I think I got it to work, I'm getting publishing values as reponse, but my graph doesn't send the values I inserted in the main – Nilton Schumacher F May 05 '20 at 20:41
  • @FrancescoAzzolaCould you please have a look at this: https://stackoverflow.com/questions/61627725/google-iot-mqtt-with-esp32-grafic-stay-at-0-after-receiving-value I will be deleting this question later – Nilton Schumacher F May 06 '20 at 05:01
0

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.

Gabe Weiss
  • 3,134
  • 1
  • 12
  • 15