Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting to the AWS IoT core MQTT broker #46

Open
Nidhxba opened this issue Feb 18, 2024 · 6 comments
Open

Connecting to the AWS IoT core MQTT broker #46

Nidhxba opened this issue Feb 18, 2024 · 6 comments
Labels
help wanted Extra attention is needed

Comments

@Nidhxba
Copy link

Nidhxba commented Feb 18, 2024

I am trying to connect my SenseCap Indicator to the MQTT broker of AWS. As mentioned in the documentation, I have tried configuring the "ha_config.h" file and it shows an error.

Error message :-
E (11483) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x6C00
I (11484) esp-tls-mbedtls: Certificate verified.
E (11484) esp-tls: Failed to open new connection
E (11495) city: Connection failed...

@Love4yzp
Copy link
Collaborator

Could you share the modifications you've made?
If it's inconvenient, just placeholder it.

@Love4yzp
Copy link
Collaborator

Love4yzp commented Feb 20, 2024

Otherwise you could try the code https://github.com/Seeed-Solution/SenseCAP_Indicator_ESP32/tree/bf7ff29d95cf5591a3f277ff3a930094286a5a4e as you are following the wiki instruction.
If you're using the lastes demo of HA, you could follow here #29.

@Love4yzp
Copy link
Collaborator

if using MQTTS, you'll need to modify the corresponding credentials such as *.pem.
The demo is for MQTT.

@Nidhxba
Copy link
Author

Nidhxba commented Feb 20, 2024

Could you share the modifications you've made? If it's inconvenient, just placeholder it.

I am configuring the "indicator_basis" example and trying to connect that to the AWS MQTT, How can I share the whole file..?
I am following a different configuration file, not the HA one..!

@Love4yzp
Copy link
Collaborator

Could you share the modifications you've made? If it's inconvenient, just placeholder it.

I am configuring the "indicator_basis" example and trying to connect that to the AWS MQTT, How can I share the whole file..? I am following a different configuration file, not the HA one..!

Just share the core function of you application that you think is working.

@Nidhxba
Copy link
Author

Nidhxba commented Feb 21, 2024

Hello, I was able to connect the indicator_basis example to MQTT of AWS. But a default value is being publised and not the actual sensor readings from the "indicator_sensor.c" file, even after successfull connection in the logs it is showing an error -->

I (46805) aws_iot: Subscribe callback Test: test_topic/esp32    co2 : 179.0, tVOC : 180.0
I (46908) aws_iot: Subscribe callback Test: test_topic/esp32    co2 : 179.0, tVOC : 180.0
I (47008) aws_iot: Stack remaining for task 'aws_iot_task' is 3260 bytes
I (47603) city: Get time zone...
E (47613) esp-tls-mbedtls: mbedtls_ssl_setup returned -0x7F00
E (47613) esp-tls: create_ssl_handle failed
E (47613) esp-tls: Failed to open new connection
E (47618) city: Connection failed...

As you can see the default values being publised are 179 and 180. Whereas the actual values are -->
sensecap_indicator

These lines handle the data subscribing to the MQTT->

aws_iot.c

void iot_subscribe_callback_handler(AWS_IoT_Client *pClient, char *topicName, uint16_t topicNameLen,
                                    IoT_Publish_Message_Params *params, void *pData) {
    ESP_LOGI(TAG, "Subscribe callback Test: %.*s\t%.*s", topicNameLen, topicName, (int) params->payloadLen, (char *)params->payload);
}

...............................
.............................
...............................
while((NETWORK_ATTEMPTING_RECONNECT == rc || NETWORK_RECONNECTED == rc || SUCCESS == rc)) {

        //Max time the yield function will wait for read messages
        rc = aws_iot_mqtt_yield(&client, 100);
        if(NETWORK_ATTEMPTING_RECONNECT == rc) {
            // If the client is attempting to reconnect we will skip the rest of the loop.
            continue;
        }

        ESP_LOGI(TAG, "Stack remaining for task '%s' is %d bytes", pcTaskGetName(NULL), uxTaskGetStackHighWaterMark(NULL));
        vTaskDelay(3000 / portTICK_PERIOD_MS);
        // sprintf(cPayload, "%s : %d ", "WiFi RSSI", wifi_app_get_rssi());
        paramsQOS0.payloadLen = strlen(cPayload);
        rc = aws_iot_mqtt_publish(&client, TOPIC, TOPIC_LEN, &paramsQOS0);

        sprintf(cPayload, "%s : %.1f, %s : %.1f", "co2", getco2(), "tVOC", gettvoc());
        // sprintf(cPayload, "%s : %.1f, %s : %.1f", "Temp",  getTemp(), "Hum", getHum());
        paramsQOS1.payloadLen = strlen(cPayload);
        rc = aws_iot_mqtt_publish(&client, TOPIC, TOPIC_LEN, &paramsQOS1);
        if (rc == MQTT_REQUEST_TIMEOUT_ERROR) {
            ESP_LOGW(TAG, "QOS1 publish ack not received.");
            rc = SUCCESS;
        }
    }

END


aws_iot.h

#ifndef MAIN_AWS_IOT_H_
#define MAIN_AWS_IOT_H_

#define CONFIG_AWS_EXAMPLE_CLIENT_ID "CaaX"
/**
 * Starts AWS IoT task.
 */
void aws_iot_start(void);

#endif /* MAIN_AWS_IOT_H_ */

END


Tasks_common.h

#ifndef MAIN_TASKS_COMMON_H_
#define MAIN_TASKS_COMMON_H_


// AWS IoT Task
#define AWS_IOT_TASK_STACK_SIZE				9216
#define AWS_IOT_TASK_PRIORITY				6
#define AWS_IOT_TASK_CORE_ID				0

#endif /* MAIN_TASKS_COMMON_H_ */

END


Please look into the code and check if any errors are there and any corrections to be made in this file or any other file. Thank you

@Love4yzp Love4yzp added the help wanted Extra attention is needed label Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants