Page 1 of 1

Rainmaker & WifiLocation

Posted: Sun Nov 20, 2022 5:37 pm
by Quabis
Hello Everybody,

I got Rainmaker Running and i got WifiLocation(https://github.com/gmag11/WifiLocation) running by themselfes, but as soon as i merge the WifiLocation to my working Rainmaker solution i get lot's of errors.

ERROR list
[ 23373][E][esp_crt_bundle.c:184] esp_crt_bundle_attach(): Failed to attach bundle
E (23821) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x7680
E (23822) esp-tls: Failed to open new connection
E (23822) TRANSPORT_BASE: Failed to open a new connection
E (23827) MQTT_CLIENT: Error transport connect
E (23830) esp_mqtt_glue: MQTT_EVENT_ERROR


and Sometimes:
E (3208) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x7680
E (3209) esp-tls: Failed to open new connection
E (3209) TRANSPORT_BASE: Failed to open a new connection
E (3215) HTTP_CLIENT: Connection failed, sock < 0
E (3217) esp_claim: Failed to open connection to https://esp-claiming.rainmaker.espressif.com/claim/initiate
E (3227) esp_claim: Claim Init Request Failed.
E (3231) esp_claim: Claim Init Sequence Failed.
E (3235) esp_rmaker_core: esp_rmaker_self_claim_perform() returned -1. Aborting


I think it mixes up the certificates or sth, since WifiLocation usses the google API....

Did anyone tried something similiar yet?


Thank you and best regards
Quabsi

Re: Rainmaker & WifiLocation

Posted: Sun Dec 25, 2022 1:50 pm
by Quabis
no one?

Re: Rainmaker & WifiLocation

Posted: Tue Dec 27, 2022 10:13 am
by ESP_Piyush
There are high chances that the issue is occurring because of low memory. Can you try disabling local control (CONFIG_ESP_RMAKER_LOCAL_CTRL_ENABLE) to free up some memory and see if this works?

Re: Rainmaker & WifiLocation

Posted: Tue Dec 27, 2022 9:39 pm
by Quabis
Hi ESP_Piyush,

thank you very much for your reply, how and where can i find the config file i need to change?
Also how much Memmory should be available?
I included

Code: Select all

Serial.println("Available Ram: " + String(ESP.getFreeHeap()) + " byte");
before calling

Code: Select all

WifiLocation location (googleApiKey);
loc = location.getGeoFromWiFi();
it looks like i got: 174720 byte Available Ram...



Best regards and thank you for your help!

Re: Rainmaker & WifiLocation

Posted: Wed Dec 28, 2022 3:27 am
by sanketwadekar
Hi,
The error code -0x7680(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) means that no CA chain is set. Secondly, local control is not available for Rainmaker with Arduino.

Alternatively, you can let the device connect to the MQTT broker first and then run your code by creating an event handler like this.

Code: Select all

/* Event handler for catching RainMaker events */
static void event_handler(void* arg, esp_event_base_t event_base,
                          int32_t event_id, void* event_data)
{
    if (event_base == RMAKER_COMMON_EVENT) {
        switch (event_id) {
            case RMAKER_MQTT_EVENT_CONNECTED:
                log_i("MQTT Connected.");
                // Your WiFiLocation code
                break;
            default:
                break;
        }
    }
}
To attach event handler, you need to call the function below after RMaker.initNode() function inside setup()

Code: Select all

void setup()
{
    ....
    esp_event_handler_register(RMAKER_COMMON_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL);
    ....
}

Re: Rainmaker & WifiLocation

Posted: Thu Dec 29, 2022 8:32 pm
by Quabis
Thank you very much for the great idea.

i tried it the following way:

Code: Select all

 /* Event handler for catching RainMaker events */
static void event_handler(void* arg, esp_event_base_t event_base,
                          int32_t event_id, void* event_data)
{
    if (event_base == RMAKER_COMMON_EVENT) {
        switch (event_id) {
            case  RMAKER_MQTT_EVENT_CONNECTED:
                {
                    log_i("MQTT Connected.");
                    // Your WiFiLocation code
                    Serial.println("getting location...");
                    Serial.println("Available Ram: " + String(ESP.getFreeHeap()) + " byte");
                    WiFiClientSecure  client;   // <= as soon as i include this line it fails
                    location_t loc2 = getGeoFromWiFi2(client);
                    Serial.println("Latitude: " + String(loc.lat, 7));
                    Serial.println("Longitude: " + String(loc.lon, 7));
                    Serial.println("Accuracy: " + String(loc.accuracy));
                    break;
                }
            default:
                break;
        }
    }
}
but i still get the same error below.

[247842][E][esp_crt_bundle.c:184] esp_crt_bundle_attach(): Failed to attach bundle
E (248256) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x7680
E (248256) esp-tls: Failed to open new connection
E (248256) TRANSPORT_BASE: Failed to open a new connection
E (248262) MQTT_CLIENT: Error transport connect
E (248265) esp_mqtt_glue: MQTT_EVENT_ERROR


it seems that as soon as i create a new WiFiClientSecure object it fails, even before the MQTT Event is fired...
in fact it never reaches the code above because RMAKER_MQTT_EVENT_CONNECTED is never happening.

Re: Rainmaker & WifiLocation

Posted: Sun Jan 01, 2023 8:36 pm
by Quabis
after more debugging it looks like the error occures because of setCACert(googleCA); in WifiLocation solution. Maybe that's overwritting something from Rainmaker...

Re: Rainmaker & WifiLocation

Posted: Tue Jan 10, 2023 6:36 am
by Quabis
I found the solution => https://github.com/espressif/arduino-esp32/issues/7363

topic can be closed