save, not working
This commit is contained in:
2
Makefile
2
Makefile
@@ -3,7 +3,7 @@
|
||||
# project subdirectory.
|
||||
#
|
||||
|
||||
PROJECT_NAME := aws_iot_subpub
|
||||
PROJECT_NAME := mqtt_iobox
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#/bin/sh
|
||||
|
||||
sudo cp build/aws_iot_subpub.bin /var/www/firmware
|
||||
sudo cp build/mqtt_iobox.bin /var/www/firmware/aws_iot_subpub.bin
|
||||
|
||||
@@ -54,19 +54,9 @@ endchoice
|
||||
config EXAMPLE_FILESYSTEM_CERTS
|
||||
bool
|
||||
|
||||
config EXAMPLE_CERTIFICATE_PATH
|
||||
string "Device Certificate Path"
|
||||
depends on EXAMPLE_FILESYSTEM_CERTS
|
||||
default "/sdcard/certificate.pem.crt"
|
||||
|
||||
config EXAMPLE_PRIVATE_KEY_PATH
|
||||
string "Device Private Key Path"
|
||||
depends on EXAMPLE_FILESYSTEM_CERTS
|
||||
default "/sdcard/private.pem.key"
|
||||
|
||||
config EXAMPLE_ROOT_CA_PATH
|
||||
string "Root CA Certificate Path"
|
||||
depends on EXAMPLE_FILESYSTEM_CERTS
|
||||
default "/sdcard/aws-root-ca.pem"
|
||||
|
||||
endmenu
|
||||
endmenu
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIERDCCAyygAwIBAgIJALuDx/+egdDoMA0GCSqGSIb3DQEBDQUAMGoxFzAVBgNV
|
||||
BAMMDkFuIE1RVFQgYnJva2VyMRYwFAYDVQQKDA1Pd25UcmFja3Mub3JnMRQwEgYD
|
||||
VQQLDAtnZW5lcmF0ZS1DQTEhMB8GCSqGSIb3DQEJARYSbm9ib2R5QGV4YW1wbGUu
|
||||
bmV0MB4XDTE4MDExNTA3NTU0NFoXDTMyMDExMjA3NTU0NFowETEPMA0GA1UEAwwG
|
||||
Y2xpZW50MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtaEQBHBDXiTf
|
||||
noFxx9007a8yaYtvCX+cWk6lNifFRR2p2v7dmtRqNkZbVEh9EIZ3WMZ/Gs7u4Etp
|
||||
rcl8wYgkeBOk+OmSb2C61VR9Tk5jLO3EpbIRhAylDBRUEAE38Y3yHu6ica/OMRiA
|
||||
LJamN58H8AkM8tmZl54wDrj6w7TmlXRfBCGyaImcXuIIOlkAb4bgR1RAFE9HXusV
|
||||
U8GNgJrIBDuA0xSu5wVr06er24KielaTkwB2or4QTIS6r+BKrN5rg5IGlRtLW04z
|
||||
7Nhq211d2TlaA15LtOPjufpWJODVL8SZ1+mUu0iCmzCynrk7D3FZ8FogOxTTVECx
|
||||
DzuKjbIcfQIDAQABo4IBRDCCAUAwDAYDVR0TAQH/BAIwADAJBgNVHREEAjAAMBEG
|
||||
CWCGSAGG+EIBAQQEAwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwQw
|
||||
CwYDVR0PBAQDAgOoMCgGCWCGSAGG+EIBDQQbFhlDbGllbnQgQnJva2VyIENlcnRp
|
||||
ZmljYXRlMB0GA1UdDgQWBBS+6QypdS5NFnuhuDWfNfkJKDZDHjCBnAYDVR0jBIGU
|
||||
MIGRgBQ4LMVPHYHxOkkfhMywqIea0USuf6FupGwwajEXMBUGA1UEAwwOQW4gTVFU
|
||||
VCBicm9rZXIxFjAUBgNVBAoMDU93blRyYWNrcy5vcmcxFDASBgNVBAsMC2dlbmVy
|
||||
YXRlLUNBMSEwHwYJKoZIhvcNAQkBFhJub2JvZHlAZXhhbXBsZS5uZXSCCQCZJ3VY
|
||||
/hIrkjANBgkqhkiG9w0BAQ0FAAOCAQEAXSiiJUr3ZBNjHmUFgQIRSySSa1PIfJWG
|
||||
L/Kuv02857MDktVmmktS238zK5cUGvvO68Y804rrOvUuMigGQthGKwr16W7UBQcU
|
||||
XTJt/4oRS+4W2DgkAWFqbfZ+uYvu0paTDgQyqjA6bvERHkoU2sr+4Le6XDuHUIds
|
||||
eymep8/Ydxn9vo4hq3rM+v9ZyJmRSEAlT5qCBG5x9fHYKe5/3WBoM8CRlJvLPqym
|
||||
8M5g8cIk43/iF1W1qYUZbxbLsHenaK3N2stzN9LsEZg1JycfX6yB4MCSYDfb0oUq
|
||||
vc52B5+2SsdZ/wmBZNxJJjuVEyScNA//thqsHvfmgcqW+jtPiEvZGg==
|
||||
-----END CERTIFICATE-----
|
||||
@@ -1,27 +0,0 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEpQIBAAKCAQEAtaEQBHBDXiTfnoFxx9007a8yaYtvCX+cWk6lNifFRR2p2v7d
|
||||
mtRqNkZbVEh9EIZ3WMZ/Gs7u4Etprcl8wYgkeBOk+OmSb2C61VR9Tk5jLO3EpbIR
|
||||
hAylDBRUEAE38Y3yHu6ica/OMRiALJamN58H8AkM8tmZl54wDrj6w7TmlXRfBCGy
|
||||
aImcXuIIOlkAb4bgR1RAFE9HXusVU8GNgJrIBDuA0xSu5wVr06er24KielaTkwB2
|
||||
or4QTIS6r+BKrN5rg5IGlRtLW04z7Nhq211d2TlaA15LtOPjufpWJODVL8SZ1+mU
|
||||
u0iCmzCynrk7D3FZ8FogOxTTVECxDzuKjbIcfQIDAQABAoIBAQCzdvXQrOyj9WNP
|
||||
xy+aAKTvxhDV4QRSKllfkh4EqL9vT6Qp03M8LW7VOie72/RXg8YhXeDxqE64KUu+
|
||||
gDxZLiB61U5I9OHQU4/IgrddzG6KUlXgM1bDV4stqFh3h/yzHUKD9d9k3gWq1T6w
|
||||
0BplEypQr2CwBPqSqadqpLSC9BhyyuGWhz91hPMyRFFmOwISD6MP2U11ornxVxKW
|
||||
E7ncmgPpmwmUcMb24s/T06CEYHPcovVJby+2+czTMpekz1ef4BzRL81FXv9u5LqF
|
||||
9Vvz6yMFrsp+PafiJg2uOxseoJn5g2P2HUPVxnvjAGABsH+ZITs6FK+2wAmmJ8zt
|
||||
YlbKSXUxAoGBAO0xTMmh6fF3+tp/chqUOvXkHd128IfE1U6FeVEeI9ws59spfqVP
|
||||
arfOWjsPb4FvdgStrk65XcXGOcqu+EBVMHA6qwCopugSziC4N4iU7xFlb9RP3287
|
||||
YtYKn0vkH1hqm3hlJHrIpiV8zVtbnVXAyX8KVdhCyPxxTstwQHU8fYGTAoGBAMQH
|
||||
5cIgF9xmgHEJbcBwN/RyYDjG9Uaph9JcVsCtNsvyh5S2dutf3x3A0VJHFPJXfzBM
|
||||
tK72s1/eU8ADSEsuA0qFBZSR6DtxN/odfoOk0s/DDTfJEG3guZ4zZI3kG3pbsm5P
|
||||
dEW4+FlxtPDhGMJ23YocjotydEm6qbaaikl3ePOvAoGBAJwWADkDwsZzNPHKQlU5
|
||||
TF95oSmW1owRvGjyrrXxxpliN6VidgPk8g5Izdnlu3QK3DgR7w3BL/MxEeDOKXF0
|
||||
Xe7MvLEvSr6XeWvQrkLD91qUTPYDJb617sF5tgAj+3iclviwXkQqfCNZMG45KJ1A
|
||||
w5hFPd6VfFubWMXJdbFwgArfAoGAZ9vPTPR379uWvUzDiytpWeenNy2iEdgMD9XA
|
||||
WMDswU0zrASoKLhYm4jm3fKvFF5rEonxSKmIC4jdUmPqz3oHYFntxPMw2R15DNjH
|
||||
iLOwxUaQIDg0riJb9YdBBTQPotomRO9vqOkBG1J1DRIVbiJP6baLhzISjmWJOSfT
|
||||
kGzt9h0CgYEApsy0fWq0BeWm5Fzi5nSe67m7+Y398RRfZnlQryY56My1XlhzcKve
|
||||
Sg2WB6+80Tp2wSP4cqiIZ8nRT0pdrNyohZbGd9I9DnkgCGgyaVJz4S9oxUZdt3CC
|
||||
HV6vjc7nBKsYSvIUJc5MQbOx4KxEMKGi06N2CsuyMq5xGwxOmfgmc/E=
|
||||
-----END RSA PRIVATE KEY-----
|
||||
6
main/iodef.h
Normal file
6
main/iodef.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef IODEF_H_
|
||||
#define IODEF_H_
|
||||
|
||||
#define LED_BUILTIN 33
|
||||
|
||||
#endif
|
||||
236
main/mqtt.c
Normal file
236
main/mqtt.c
Normal file
@@ -0,0 +1,236 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "driver/sdmmc_host.h"
|
||||
|
||||
//#include "aws_iot_config.h"
|
||||
#include "aws_iot_log.h"
|
||||
#include "aws_iot_version.h"
|
||||
#include "aws_iot_mqtt_client_interface.h"
|
||||
|
||||
#include "wifi.h"
|
||||
|
||||
static const char *TAG = "mqtt";
|
||||
|
||||
//const int CONNECTED_BIT = BIT0;
|
||||
|
||||
#if defined(CONFIG_EXAMPLE_EMBEDDED_CERTS)
|
||||
extern const uint8_t aws_root_ca_pem_start[] asm("_binary_ca_crt_start");
|
||||
extern const uint8_t aws_root_ca_pem_end[] asm("_binary_ca_crt_end");
|
||||
#elif defined(CONFIG_EXAMPLE_FILESYSTEM_CERTS)
|
||||
static const char * ROOT_CA_PATH = CONFIG_EXAMPLE_ROOT_CA_PATH;
|
||||
#else
|
||||
#error "Invalid method for loading certs"
|
||||
#endif
|
||||
|
||||
char HostAddress[255] = AWS_IOT_MQTT_ADDRESS;
|
||||
char HostName[255] = AWS_IOT_MQTT_HOSTNAME;
|
||||
|
||||
uint32_t port = AWS_IOT_MQTT_PORT;
|
||||
|
||||
|
||||
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");
|
||||
ESP_LOGI(TAG, "%.*s\t%.*s", topicNameLen, topicName, (int) params->payloadLen, (char *)params->payload);
|
||||
}
|
||||
|
||||
void disconnectCallbackHandler(AWS_IoT_Client *pClient, void *data) {
|
||||
ESP_LOGW(TAG, "MQTT Disconnect");
|
||||
IoT_Error_t rc = FAILURE;
|
||||
|
||||
if(NULL == pClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(aws_iot_is_autoreconnect_enabled(pClient)) {
|
||||
ESP_LOGI(TAG, "Auto Reconnect is enabled, Reconnecting attempt will start now");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Auto Reconnect not enabled. Starting manual reconnect...");
|
||||
rc = aws_iot_mqtt_attempt_reconnect(pClient);
|
||||
if(NETWORK_RECONNECTED == rc) {
|
||||
ESP_LOGW(TAG, "Manual Reconnect Successful");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Manual Reconnect Failed - %d", rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void show_certificate(void)
|
||||
{
|
||||
FILE* f = fopen("/sdcard/ca.crt", "r");
|
||||
if (f == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to open file for reading");
|
||||
return;
|
||||
}
|
||||
char line[128];
|
||||
while(fgets(line, sizeof(line), f))
|
||||
ESP_LOGI(TAG, "ca.crt: %s", line);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void aws_iot_task(void *param) {
|
||||
char cPayload[100];
|
||||
|
||||
int32_t i = 0;
|
||||
|
||||
IoT_Error_t rc = FAILURE;
|
||||
|
||||
AWS_IoT_Client client;
|
||||
IoT_Client_Init_Params mqttInitParams = iotClientInitParamsDefault;
|
||||
IoT_Client_Connect_Params connectParams = iotClientConnectParamsDefault;
|
||||
|
||||
IoT_Publish_Message_Params paramsQOS0;
|
||||
IoT_Publish_Message_Params paramsQOS1;
|
||||
|
||||
ESP_LOGI(TAG, "AWS IoT SDK Version %d.%d.%d-%s", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_TAG);
|
||||
|
||||
mqttInitParams.enableAutoReconnect = false; // We enable this later below
|
||||
mqttInitParams.pHostURL = HostAddress;
|
||||
mqttInitParams.pHostName = HostName;
|
||||
mqttInitParams.port = port;
|
||||
|
||||
#if defined(CONFIG_EXAMPLE_EMBEDDED_CERTS)
|
||||
mqttInitParams.pRootCALocation = (const char *)aws_root_ca_pem_start;
|
||||
|
||||
#elif defined(CONFIG_EXAMPLE_FILESYSTEM_CERTS)
|
||||
mqttInitParams.pRootCALocation = ROOT_CA_PATH;
|
||||
#endif
|
||||
|
||||
mqttInitParams.mqttCommandTimeout_ms = 20000;
|
||||
mqttInitParams.tlsHandshakeTimeout_ms = 5000;
|
||||
mqttInitParams.isSSLHostnameVerify = true;
|
||||
mqttInitParams.disconnectHandler = disconnectCallbackHandler;
|
||||
mqttInitParams.disconnectHandlerData = NULL;
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_SDCARD_CERTS
|
||||
ESP_LOGI(TAG, "Mounting SD card...");
|
||||
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
||||
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
|
||||
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
.format_if_mount_failed = false,
|
||||
.max_files = 3,
|
||||
};
|
||||
sdmmc_card_t* card;
|
||||
esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to mount SD card VFAT filesystem.");
|
||||
abort();
|
||||
}
|
||||
//show_certificate();
|
||||
|
||||
#endif
|
||||
|
||||
rc = aws_iot_mqtt_init(&client, &mqttInitParams);
|
||||
if(SUCCESS != rc) {
|
||||
ESP_LOGE(TAG, "aws_iot_mqtt_init returned error : %d ", rc);
|
||||
abort();
|
||||
}
|
||||
|
||||
/* Wait for WiFI to show as connected */
|
||||
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, false, true, portMAX_DELAY);
|
||||
|
||||
connectParams.keepAliveIntervalInSec = 10;
|
||||
connectParams.isCleanSession = true;
|
||||
connectParams.MQTTVersion = MQTT_3_1_1;
|
||||
/* Client ID is set in the menuconfig of the example */
|
||||
connectParams.pClientID = CONFIG_AWS_EXAMPLE_CLIENT_ID;
|
||||
connectParams.clientIDLen = (uint16_t) strlen(CONFIG_AWS_EXAMPLE_CLIENT_ID);
|
||||
connectParams.pUsername = CONFIG_AWS_EXAMPLE_USERNAME;
|
||||
connectParams.usernameLen = (uint16_t) strlen(CONFIG_AWS_EXAMPLE_USERNAME);
|
||||
connectParams.pPassword = CONFIG_AWS_EXAMPLE_PASSWORD;
|
||||
connectParams.passwordLen = (uint16_t) strlen(CONFIG_AWS_EXAMPLE_PASSWORD);
|
||||
connectParams.isWillMsgPresent = false;
|
||||
|
||||
ESP_LOGI(TAG, "Connecting to AWS...");
|
||||
do {
|
||||
//ESP_LOGI(TAG, "Username:%s| - password:%s|", connectParams.pUsername, connectParams.pPassword);
|
||||
rc = aws_iot_mqtt_connect(&client, &connectParams);
|
||||
if(SUCCESS != rc) {
|
||||
ESP_LOGI(TAG, "Username:%s| - password:%s|", connectParams.pUsername, connectParams.pPassword);
|
||||
ESP_LOGE(TAG, "Error(%d) connecting to %s:%d", rc, mqttInitParams.pHostURL, mqttInitParams.port);
|
||||
vTaskDelay(3000 / portTICK_RATE_MS);
|
||||
|
||||
ESP_LOGI(TAG, "RAM left %d", esp_get_free_heap_size());
|
||||
ESP_LOGI(TAG, "task stack: %d", uxTaskGetStackHighWaterMark(NULL));
|
||||
}
|
||||
} while(SUCCESS != rc);
|
||||
|
||||
/*
|
||||
* Enable Auto Reconnect functionality. Minimum and Maximum time of Exponential backoff are set in aws_iot_config.h
|
||||
* #AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL
|
||||
* #AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL
|
||||
*/
|
||||
rc = aws_iot_mqtt_autoreconnect_set_status(&client, true);
|
||||
if(SUCCESS != rc) {
|
||||
ESP_LOGE(TAG, "Unable to set Auto Reconnect to true - %d", rc);
|
||||
abort();
|
||||
}
|
||||
|
||||
const char *TOPIC = "test_topic/esp32";
|
||||
const int TOPIC_LEN = strlen(TOPIC);
|
||||
|
||||
ESP_LOGI(TAG, "Subscribing...");
|
||||
rc = aws_iot_mqtt_subscribe(&client, TOPIC, TOPIC_LEN, QOS0, iot_subscribe_callback_handler, NULL);
|
||||
if(SUCCESS != rc) {
|
||||
ESP_LOGE(TAG, "Error subscribing : %d ", rc);
|
||||
abort();
|
||||
}
|
||||
|
||||
sprintf(cPayload, "%s : %d ", "hello from SDK", i);
|
||||
|
||||
paramsQOS0.qos = QOS0;
|
||||
paramsQOS0.payload = (void *) cPayload;
|
||||
paramsQOS0.isRetained = 0;
|
||||
|
||||
paramsQOS1.qos = QOS1;
|
||||
paramsQOS1.payload = (void *) cPayload;
|
||||
paramsQOS1.isRetained = 0;
|
||||
|
||||
sprintf(cPayload, "%s : %d ", "hello from ESP32 (QOS0)", i++);
|
||||
paramsQOS0.payloadLen = strlen(cPayload);
|
||||
rc = aws_iot_mqtt_publish(&client, TOPIC, TOPIC_LEN, ¶msQOS0);
|
||||
|
||||
sprintf(cPayload, "%s : %d ", "hello from ESP32 (QOS1)", i++);
|
||||
paramsQOS1.payloadLen = strlen(cPayload);
|
||||
rc = aws_iot_mqtt_publish(&client, TOPIC, TOPIC_LEN, ¶msQOS1);
|
||||
if (rc == MQTT_REQUEST_TIMEOUT_ERROR) {
|
||||
ESP_LOGW(TAG, "QOS1 publish ack not received.");
|
||||
rc = SUCCESS;
|
||||
}
|
||||
|
||||
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, "-->sleep");
|
||||
//vTaskDelay(5000 / portTICK_RATE_MS);
|
||||
//sprintf(cPayload, "%s : %d ", "hello from ESP32 (QOS0)", i++);
|
||||
//paramsQOS0.payloadLen = strlen(cPayload);
|
||||
//rc = aws_iot_mqtt_publish(&client, TOPIC, TOPIC_LEN, ¶msQOS0);
|
||||
|
||||
//sprintf(cPayload, "%s : %d ", "hello from ESP32 (QOS1)", i++);
|
||||
//paramsQOS1.payloadLen = strlen(cPayload);
|
||||
//rc = aws_iot_mqtt_publish(&client, TOPIC, TOPIC_LEN, ¶msQOS1);
|
||||
//if (rc == MQTT_REQUEST_TIMEOUT_ERROR) {
|
||||
// ESP_LOGW(TAG, "QOS1 publish ack not received.");
|
||||
// rc = SUCCESS;
|
||||
//}
|
||||
}
|
||||
|
||||
ESP_LOGE(TAG, "An error occurred in the main loop.");
|
||||
abort();
|
||||
}
|
||||
6
main/mqtt.h
Normal file
6
main/mqtt.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef MQTT_H_
|
||||
#define MQTT_H_
|
||||
|
||||
void aws_iot_task(void *param);
|
||||
|
||||
#endif
|
||||
229
main/mqtt_iobox.c
Normal file
229
main/mqtt_iobox.c
Normal file
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* Additions Copyright 2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License").
|
||||
* You may not use this file except in compliance with the License.
|
||||
* A copy of the License is located at
|
||||
*
|
||||
* http://aws.amazon.com/apache2.0
|
||||
*
|
||||
* or in the "license" file accompanying this file. This file is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @file subscribe_publish_sample.c
|
||||
* @brief simple MQTT publish and subscribe on the same topic
|
||||
*
|
||||
* This example takes the parameters from the build configuration and establishes a connection to the AWS IoT MQTT Platform.
|
||||
* It subscribes and publishes to the same topic - "test_topic/esp32"
|
||||
*
|
||||
* Some setup is required. See example README for details.
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
//#include <sys/cdefs.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_log.h"
|
||||
//#include "esp_vfs_fat.h"
|
||||
//#include "driver/sdmmc_host.h"
|
||||
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "apps/sntp/sntp.h"
|
||||
|
||||
#include "wifi.h"
|
||||
//#include "mqtt.h"
|
||||
//#include "webserver.h"
|
||||
#include "iodef.h"
|
||||
|
||||
static const char *TAG = "mqtt_iobox";
|
||||
|
||||
/* The examples use simple WiFi configuration that you can set via
|
||||
'make menuconfig'.
|
||||
|
||||
If you'd rather not, just change the below entries to strings with
|
||||
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
|
||||
*/
|
||||
#define EXAMPLE_WIFI_SSID CONFIG_WIFI_SSID
|
||||
#define EXAMPLE_WIFI_PASS CONFIG_WIFI_PASSWORD
|
||||
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected & ready to make a request */
|
||||
//static EventGroupHandle_t wifi_event_group;
|
||||
|
||||
/* The event group allows multiple bits for each event,
|
||||
but we only care about one event - are we connected
|
||||
to the AP with an IP? */
|
||||
const int CONNECTED_BIT = BIT0;
|
||||
//const int CONNECTED_BIT;
|
||||
|
||||
|
||||
static esp_err_t event_handler(void *ctx, system_event_t *event)
|
||||
{
|
||||
switch(event->event_id) {
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
esp_wifi_connect();
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
/* This is a workaround as ESP32 WiFi libs don't currently
|
||||
auto-reassociate. */
|
||||
esp_wifi_connect();
|
||||
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
static void initialise_wifi(void)
|
||||
{
|
||||
tcpip_adapter_init();
|
||||
wifi_event_group = xEventGroupCreate();
|
||||
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
|
||||
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = EXAMPLE_WIFI_SSID,
|
||||
.password = EXAMPLE_WIFI_PASS,
|
||||
},
|
||||
};
|
||||
ESP_LOGI(TAG, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid);
|
||||
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
|
||||
ESP_ERROR_CHECK( esp_wifi_start() );
|
||||
}
|
||||
|
||||
|
||||
void alive_task(void *pvParameters)
|
||||
{
|
||||
ESP_LOGI(TAG, "starting alive task");
|
||||
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, false, true, portMAX_DELAY);
|
||||
|
||||
while(1) {
|
||||
gpio_set_level(LED_BUILTIN, 0);
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
gpio_set_level(LED_BUILTIN, 1);
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void ntp_task(void *pvParameters)
|
||||
{
|
||||
ESP_LOGI(TAG, "Initializing SNTP task");
|
||||
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, false, true, portMAX_DELAY);
|
||||
|
||||
while(1) {
|
||||
//vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
//gpio_set_level(LED_BUILTIN, 0);
|
||||
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
ESP_LOGI(TAG, "SNTP task wakeup");
|
||||
|
||||
//gpio_set_level(LED_BUILTIN, 1);
|
||||
//vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void obtain_time(void)
|
||||
{
|
||||
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, false, true, portMAX_DELAY);
|
||||
|
||||
ESP_LOGI(TAG, "Initializing SNTP");
|
||||
sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
||||
sntp_setservername(0, "nl.pool.ntp.org");
|
||||
sntp_init();
|
||||
|
||||
// wait for time to be set
|
||||
time_t now = 0;
|
||||
struct tm timeinfo = { 0 };
|
||||
int retry = 0;
|
||||
const int retry_count = 10;
|
||||
while(timeinfo.tm_year < (2016 - 1900) && ++retry < retry_count) {
|
||||
ESP_LOGI(TAG, "Waiting for system time to be set... (%d/%d)", retry, retry_count);
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
}
|
||||
char strftime_buf[64];
|
||||
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
|
||||
ESP_LOGI(TAG, "The time is :%s", strftime_buf);
|
||||
}
|
||||
|
||||
|
||||
void app_main()
|
||||
{
|
||||
// Initialize NVS.
|
||||
esp_err_t err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK( err );
|
||||
|
||||
initialise_wifi();
|
||||
|
||||
#ifdef CONFIG_MBEDTLS_DEBUG
|
||||
//const size_t stack_size = 36*1024;
|
||||
const size_t stack_size = 40*1024;
|
||||
#else
|
||||
//const size_t stack_size = 36*1024;
|
||||
const size_t stack_size = 40*1024;
|
||||
#endif
|
||||
|
||||
/*
|
||||
time_t now;
|
||||
struct tm timeinfo;
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
now = tv.tv_sec;
|
||||
localtime_r(&now, &timeinfo);
|
||||
// Is time set? If not, tm_year will be (1970 - 1900).
|
||||
if (timeinfo.tm_year < (2016 - 1900)) {
|
||||
ESP_LOGI(TAG, "Time is not set yet. Connecting to WiFi and getting time over NTP.");
|
||||
obtain_time();
|
||||
// update 'now' variable with current time
|
||||
gettimeofday(&tv, NULL);
|
||||
now = tv.tv_sec;
|
||||
localtime_r(&now, &timeinfo);
|
||||
}
|
||||
char strftime_buf[64];
|
||||
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
|
||||
ESP_LOGI(TAG, "RTC time is :%s", strftime_buf);
|
||||
*/
|
||||
|
||||
gpio_pad_select_gpio(LED_BUILTIN);
|
||||
/* Set the GPIO as a push/pull output */
|
||||
gpio_set_direction(LED_BUILTIN, GPIO_MODE_OUTPUT);
|
||||
|
||||
xTaskCreatePinnedToCore(&ntp_task, "ntp_task", 1024, NULL, 5, NULL, 1);
|
||||
//xTaskCreatePinnedToCore(&aws_iot_task, "mqtt_task", stack_size, NULL, 5, NULL, 1);
|
||||
//xTaskCreatePinnedToCore(&http_server_task, "http_server", 2048, NULL, 5, NULL,1);
|
||||
//xTaskCreate(&http_server_task, "http_server", 2048, NULL, 5, NULL);
|
||||
//xTaskCreatePinnedToCore(&alive_task, "alive_task", 1024, NULL, 5, NULL, 1);
|
||||
}
|
||||
@@ -1,441 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* Additions Copyright 2016 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License").
|
||||
* You may not use this file except in compliance with the License.
|
||||
* A copy of the License is located at
|
||||
*
|
||||
* http://aws.amazon.com/apache2.0
|
||||
*
|
||||
* or in the "license" file accompanying this file. This file is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @file subscribe_publish_sample.c
|
||||
* @brief simple MQTT publish and subscribe on the same topic
|
||||
*
|
||||
* This example takes the parameters from the build configuration and establishes a connection to the AWS IoT MQTT Platform.
|
||||
* It subscribes and publishes to the same topic - "test_topic/esp32"
|
||||
*
|
||||
* Some setup is required. See example README for details.
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
//#include <sys/cdefs.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "driver/sdmmc_host.h"
|
||||
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "aws_iot_config.h"
|
||||
#include "aws_iot_log.h"
|
||||
#include "aws_iot_version.h"
|
||||
#include "aws_iot_mqtt_client_interface.h"
|
||||
#include "apps/sntp/sntp.h"
|
||||
|
||||
#define DISABLE_METRICS true
|
||||
|
||||
static const char *TAG = "subpub";
|
||||
|
||||
/* The examples use simple WiFi configuration that you can set via
|
||||
'make menuconfig'.
|
||||
|
||||
If you'd rather not, just change the below entries to strings with
|
||||
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
|
||||
*/
|
||||
#define EXAMPLE_WIFI_SSID CONFIG_WIFI_SSID
|
||||
#define EXAMPLE_WIFI_PASS CONFIG_WIFI_PASSWORD
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected & ready to make a request */
|
||||
static EventGroupHandle_t wifi_event_group;
|
||||
|
||||
/* The event group allows multiple bits for each event,
|
||||
but we only care about one event - are we connected
|
||||
to the AP with an IP? */
|
||||
const int CONNECTED_BIT = BIT0;
|
||||
|
||||
|
||||
/* CA Root certificate, device ("Thing") certificate and device
|
||||
* ("Thing") key.
|
||||
Example can be configured one of two ways:
|
||||
"Embedded Certs" are loaded from files in "certs/" and embedded into the app binary.
|
||||
"Filesystem Certs" are loaded from the filesystem (SD card, etc.)
|
||||
See example README for more details.
|
||||
*/
|
||||
#if defined(CONFIG_EXAMPLE_EMBEDDED_CERTS)
|
||||
|
||||
extern const uint8_t aws_root_ca_pem_start[] asm("_binary_ca_crt_start");
|
||||
extern const uint8_t aws_root_ca_pem_end[] asm("_binary_ca_crt_end");
|
||||
|
||||
//extern const uint8_t certificate_pem_crt_start[] asm("_binary_client_crt_start");
|
||||
//extern const uint8_t certificate_pem_crt_end[] asm("_binary_client_crt_end");
|
||||
|
||||
//extern const uint8_t private_pem_key_start[] asm("_binary_client_key_start");
|
||||
//extern const uint8_t private_pem_key_end[] asm("_binary_client_key_end");
|
||||
|
||||
#elif defined(CONFIG_EXAMPLE_FILESYSTEM_CERTS)
|
||||
|
||||
//static const char * DEVICE_CERTIFICATE_PATH = CONFIG_EXAMPLE_CERTIFICATE_PATH;
|
||||
//static const char * DEVICE_PRIVATE_KEY_PATH = CONFIG_EXAMPLE_PRIVATE_KEY_PATH;
|
||||
static const char * ROOT_CA_PATH = CONFIG_EXAMPLE_ROOT_CA_PATH;
|
||||
|
||||
#else
|
||||
#error "Invalid method for loading certs"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Default MQTT HOST URL is pulled from the aws_iot_config.h
|
||||
*/
|
||||
char HostAddress[255] = AWS_IOT_MQTT_ADDRESS;
|
||||
char HostName[255] = AWS_IOT_MQTT_HOSTNAME;
|
||||
|
||||
/**
|
||||
* @brief Default MQTT port is pulled from the aws_iot_config.h
|
||||
*/
|
||||
uint32_t port = AWS_IOT_MQTT_PORT;
|
||||
|
||||
|
||||
static esp_err_t event_handler(void *ctx, system_event_t *event)
|
||||
{
|
||||
switch(event->event_id) {
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
esp_wifi_connect();
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
/* This is a workaround as ESP32 WiFi libs don't currently
|
||||
auto-reassociate. */
|
||||
esp_wifi_connect();
|
||||
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
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");
|
||||
ESP_LOGI(TAG, "%.*s\t%.*s", topicNameLen, topicName, (int) params->payloadLen, (char *)params->payload);
|
||||
}
|
||||
|
||||
void disconnectCallbackHandler(AWS_IoT_Client *pClient, void *data) {
|
||||
ESP_LOGW(TAG, "MQTT Disconnect");
|
||||
IoT_Error_t rc = FAILURE;
|
||||
|
||||
if(NULL == pClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(aws_iot_is_autoreconnect_enabled(pClient)) {
|
||||
ESP_LOGI(TAG, "Auto Reconnect is enabled, Reconnecting attempt will start now");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Auto Reconnect not enabled. Starting manual reconnect...");
|
||||
rc = aws_iot_mqtt_attempt_reconnect(pClient);
|
||||
if(NETWORK_RECONNECTED == rc) {
|
||||
ESP_LOGW(TAG, "Manual Reconnect Successful");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Manual Reconnect Failed - %d", rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void show_certificate(void)
|
||||
{
|
||||
FILE* f = fopen("/sdcard/ca.crt", "r");
|
||||
if (f == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to open file for reading");
|
||||
return;
|
||||
}
|
||||
char line[128];
|
||||
while(fgets(line, sizeof(line), f))
|
||||
ESP_LOGI(TAG, "ca.crt: %s", line);
|
||||
fclose(f);
|
||||
|
||||
f = fopen("/sdcard/client.crt", "r");
|
||||
if (f == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to open file for reading");
|
||||
return;
|
||||
}
|
||||
while(fgets(line, sizeof(line), f))
|
||||
ESP_LOGI(TAG, "client.crt: %s", line);
|
||||
fclose(f);
|
||||
|
||||
f = fopen("/sdcard/client.key", "r");
|
||||
if (f == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to open file for reading");
|
||||
return;
|
||||
}
|
||||
while(fgets(line, sizeof(line), f))
|
||||
ESP_LOGI(TAG, "client.key: %s", line);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
||||
void aws_iot_task(void *param) {
|
||||
char cPayload[100];
|
||||
|
||||
int32_t i = 0;
|
||||
|
||||
IoT_Error_t rc = FAILURE;
|
||||
|
||||
AWS_IoT_Client client;
|
||||
IoT_Client_Init_Params mqttInitParams = iotClientInitParamsDefault;
|
||||
IoT_Client_Connect_Params connectParams = iotClientConnectParamsDefault;
|
||||
|
||||
IoT_Publish_Message_Params paramsQOS0;
|
||||
IoT_Publish_Message_Params paramsQOS1;
|
||||
|
||||
ESP_LOGI(TAG, "AWS IoT SDK Version %d.%d.%d-%s", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_TAG);
|
||||
|
||||
mqttInitParams.enableAutoReconnect = false; // We enable this later below
|
||||
mqttInitParams.pHostURL = HostAddress;
|
||||
mqttInitParams.pHostName = HostName;
|
||||
mqttInitParams.port = port;
|
||||
|
||||
#if defined(CONFIG_EXAMPLE_EMBEDDED_CERTS)
|
||||
mqttInitParams.pRootCALocation = (const char *)aws_root_ca_pem_start;
|
||||
//mqttInitParams.pDeviceCertLocation = (const char *)certificate_pem_crt_start;
|
||||
//mqttInitParams.pDevicePrivateKeyLocation = (const char *)private_pem_key_start;
|
||||
|
||||
#elif defined(CONFIG_EXAMPLE_FILESYSTEM_CERTS)
|
||||
mqttInitParams.pRootCALocation = ROOT_CA_PATH;
|
||||
//mqttInitParams.pDeviceCertLocation = DEVICE_CERTIFICATE_PATH;
|
||||
//mqttInitParams.pDeviceCertLocation = NULL;
|
||||
|
||||
//mqttInitParams.pDevicePrivateKeyLocation = DEVICE_PRIVATE_KEY_PATH;
|
||||
//mqttInitParams.pDevicePrivateKeyLocation = NULL;
|
||||
#endif
|
||||
|
||||
mqttInitParams.mqttCommandTimeout_ms = 20000;
|
||||
mqttInitParams.tlsHandshakeTimeout_ms = 5000;
|
||||
//mqttInitParams.isSSLHostnameVerify = false;
|
||||
mqttInitParams.isSSLHostnameVerify = true;
|
||||
mqttInitParams.disconnectHandler = disconnectCallbackHandler;
|
||||
mqttInitParams.disconnectHandlerData = NULL;
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_SDCARD_CERTS
|
||||
ESP_LOGI(TAG, "Mounting SD card...");
|
||||
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
||||
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
|
||||
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
.format_if_mount_failed = false,
|
||||
.max_files = 3,
|
||||
};
|
||||
sdmmc_card_t* card;
|
||||
esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to mount SD card VFAT filesystem.");
|
||||
abort();
|
||||
}
|
||||
|
||||
//debug
|
||||
//show_certificate();
|
||||
|
||||
#endif
|
||||
|
||||
rc = aws_iot_mqtt_init(&client, &mqttInitParams);
|
||||
if(SUCCESS != rc) {
|
||||
ESP_LOGE(TAG, "aws_iot_mqtt_init returned error : %d ", rc);
|
||||
abort();
|
||||
}
|
||||
|
||||
/* Wait for WiFI to show as connected */
|
||||
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
|
||||
false, true, portMAX_DELAY);
|
||||
|
||||
connectParams.keepAliveIntervalInSec = 10;
|
||||
connectParams.isCleanSession = true;
|
||||
connectParams.MQTTVersion = MQTT_3_1_1;
|
||||
/* Client ID is set in the menuconfig of the example */
|
||||
connectParams.pClientID = CONFIG_AWS_EXAMPLE_CLIENT_ID;
|
||||
connectParams.clientIDLen = (uint16_t) strlen(CONFIG_AWS_EXAMPLE_CLIENT_ID);
|
||||
connectParams.pUsername = CONFIG_AWS_EXAMPLE_USERNAME;
|
||||
connectParams.usernameLen = (uint16_t) strlen(CONFIG_AWS_EXAMPLE_USERNAME);
|
||||
connectParams.pPassword = CONFIG_AWS_EXAMPLE_PASSWORD;
|
||||
connectParams.passwordLen = (uint16_t) strlen(CONFIG_AWS_EXAMPLE_PASSWORD);
|
||||
connectParams.isWillMsgPresent = false;
|
||||
|
||||
ESP_LOGI(TAG, "Connecting to AWS...");
|
||||
do {
|
||||
//ESP_LOGI(TAG, "Username:%s| - password:%s|", connectParams.pUsername, connectParams.pPassword);
|
||||
rc = aws_iot_mqtt_connect(&client, &connectParams);
|
||||
if(SUCCESS != rc) {
|
||||
ESP_LOGI(TAG, "Username:%s| - password:%s|", connectParams.pUsername, connectParams.pPassword);
|
||||
ESP_LOGE(TAG, "Error(%d) connecting to %s:%d", rc, mqttInitParams.pHostURL, mqttInitParams.port);
|
||||
vTaskDelay(3000 / portTICK_RATE_MS);
|
||||
|
||||
ESP_LOGI(TAG, "RAM left %d", esp_get_free_heap_size());
|
||||
ESP_LOGI(TAG, "task stack: %d", uxTaskGetStackHighWaterMark(NULL));
|
||||
}
|
||||
} while(SUCCESS != rc);
|
||||
|
||||
/*
|
||||
* Enable Auto Reconnect functionality. Minimum and Maximum time of Exponential backoff are set in aws_iot_config.h
|
||||
* #AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL
|
||||
* #AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL
|
||||
*/
|
||||
rc = aws_iot_mqtt_autoreconnect_set_status(&client, true);
|
||||
if(SUCCESS != rc) {
|
||||
ESP_LOGE(TAG, "Unable to set Auto Reconnect to true - %d", rc);
|
||||
abort();
|
||||
}
|
||||
|
||||
const char *TOPIC = "test_topic/esp32";
|
||||
const int TOPIC_LEN = strlen(TOPIC);
|
||||
|
||||
ESP_LOGI(TAG, "Subscribing...");
|
||||
rc = aws_iot_mqtt_subscribe(&client, TOPIC, TOPIC_LEN, QOS0, iot_subscribe_callback_handler, NULL);
|
||||
if(SUCCESS != rc) {
|
||||
ESP_LOGE(TAG, "Error subscribing : %d ", rc);
|
||||
abort();
|
||||
}
|
||||
|
||||
sprintf(cPayload, "%s : %d ", "hello from SDK", i);
|
||||
|
||||
paramsQOS0.qos = QOS0;
|
||||
paramsQOS0.payload = (void *) cPayload;
|
||||
paramsQOS0.isRetained = 0;
|
||||
|
||||
paramsQOS1.qos = QOS1;
|
||||
paramsQOS1.payload = (void *) cPayload;
|
||||
paramsQOS1.isRetained = 0;
|
||||
|
||||
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, "-->sleep");
|
||||
vTaskDelay(5000 / portTICK_RATE_MS);
|
||||
sprintf(cPayload, "%s : %d ", "hello from ESP32 (QOS0)", i++);
|
||||
paramsQOS0.payloadLen = strlen(cPayload);
|
||||
rc = aws_iot_mqtt_publish(&client, TOPIC, TOPIC_LEN, ¶msQOS0);
|
||||
|
||||
sprintf(cPayload, "%s : %d ", "hello from ESP32 (QOS1)", i++);
|
||||
paramsQOS1.payloadLen = strlen(cPayload);
|
||||
rc = aws_iot_mqtt_publish(&client, TOPIC, TOPIC_LEN, ¶msQOS1);
|
||||
if (rc == MQTT_REQUEST_TIMEOUT_ERROR) {
|
||||
ESP_LOGW(TAG, "QOS1 publish ack not received.");
|
||||
rc = SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
ESP_LOGE(TAG, "An error occurred in the main loop.");
|
||||
abort();
|
||||
}
|
||||
|
||||
static void initialise_wifi(void)
|
||||
{
|
||||
tcpip_adapter_init();
|
||||
wifi_event_group = xEventGroupCreate();
|
||||
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
|
||||
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = EXAMPLE_WIFI_SSID,
|
||||
.password = EXAMPLE_WIFI_PASS,
|
||||
},
|
||||
};
|
||||
ESP_LOGI(TAG, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid);
|
||||
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
|
||||
ESP_ERROR_CHECK( esp_wifi_start() );
|
||||
}
|
||||
|
||||
static void obtain_time(void)
|
||||
{
|
||||
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,false, true, portMAX_DELAY);
|
||||
|
||||
ESP_LOGI(TAG, "Initializing SNTP");
|
||||
sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
||||
sntp_setservername(0, "nl.pool.ntp.org");
|
||||
sntp_init();
|
||||
|
||||
// wait for time to be set
|
||||
time_t now = 0;
|
||||
struct tm timeinfo = { 0 };
|
||||
int retry = 0;
|
||||
const int retry_count = 10;
|
||||
while(timeinfo.tm_year < (2016 - 1900) && ++retry < retry_count) {
|
||||
ESP_LOGI(TAG, "Waiting for system time to be set... (%d/%d)", retry, retry_count);
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
}
|
||||
char strftime_buf[64];
|
||||
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
|
||||
ESP_LOGI(TAG, "The time is :%s", strftime_buf);
|
||||
}
|
||||
|
||||
void app_main()
|
||||
{
|
||||
// Initialize NVS.
|
||||
esp_err_t err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK( err );
|
||||
|
||||
initialise_wifi();
|
||||
|
||||
#ifdef CONFIG_MBEDTLS_DEBUG
|
||||
//const size_t stack_size = 36*1024;
|
||||
const size_t stack_size = 40*1024;
|
||||
#else
|
||||
// const size_t stack_size = 36*1024;
|
||||
const size_t stack_size = 40*1024;
|
||||
#endif
|
||||
|
||||
time_t now;
|
||||
struct tm timeinfo;
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
now = tv.tv_sec;
|
||||
localtime_r(&now, &timeinfo);
|
||||
// Is time set? If not, tm_year will be (1970 - 1900).
|
||||
if (timeinfo.tm_year < (2016 - 1900)) {
|
||||
ESP_LOGI(TAG, "Time is not set yet. Connecting to WiFi and getting time over NTP.");
|
||||
obtain_time();
|
||||
// update 'now' variable with current time
|
||||
gettimeofday(&tv, NULL);
|
||||
now = tv.tv_sec;
|
||||
localtime_r(&now, &timeinfo);
|
||||
}
|
||||
char strftime_buf[64];
|
||||
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
|
||||
ESP_LOGI(TAG, "RTC time is :%s", strftime_buf);
|
||||
|
||||
|
||||
xTaskCreatePinnedToCore(&aws_iot_task, "aws_iot_task", stack_size, NULL, 5, NULL, 1);
|
||||
}
|
||||
19
main/test1_html.h
Normal file
19
main/test1_html.h
Normal file
@@ -0,0 +1,19 @@
|
||||
unsigned char test1_html[] = {
|
||||
0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20, 0x68, 0x74,
|
||||
0x6d, 0x6c, 0x3e, 0x0a, 0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0x0a, 0x20,
|
||||
0x20, 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
||||
0x3c, 0x6d, 0x65, 0x74, 0x61, 0x20, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65,
|
||||
0x74, 0x3d, 0x22, 0x55, 0x54, 0x46, 0x2d, 0x38, 0x22, 0x3e, 0x0a, 0x20,
|
||||
0x20, 0x20, 0x20, 0x3c, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x54, 0x65,
|
||||
0x73, 0x74, 0x20, 0x45, 0x53, 0x50, 0x33, 0x32, 0x20, 0x70, 0x61, 0x67,
|
||||
0x65, 0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x0a, 0x20, 0x20,
|
||||
0x3c, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0a, 0x20, 0x20, 0x3c, 0x62,
|
||||
0x6f, 0x64, 0x79, 0x3e, 0x0a, 0x20, 0x20, 0x09, 0x3c, 0x68, 0x31, 0x3e,
|
||||
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x45,
|
||||
0x53, 0x50, 0x33, 0x32, 0x3c, 0x2f, 0x68, 0x31, 0x3e, 0x0a, 0x20, 0x20,
|
||||
0x09, 0x3c, 0x70, 0x3e, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x45,
|
||||
0x53, 0x50, 0x33, 0x32, 0x20, 0x70, 0x61, 0x67, 0x65, 0x3c, 0x2f, 0x70,
|
||||
0x3e, 0x0a, 0x20, 0x20, 0x3c, 0x2f, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0x0a,
|
||||
0x3c, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x3e
|
||||
};
|
||||
unsigned int test1_html_len = 187;
|
||||
173
main/webserver.c
Normal file
173
main/webserver.c
Normal file
@@ -0,0 +1,173 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/portmacro.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_event_loop.h"
|
||||
|
||||
#include "string.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "tcpip_adapter.h"
|
||||
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/netdb.h"
|
||||
#include "lwip/api.h"
|
||||
#include "lwip/err.h"
|
||||
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#include "iodef.h"
|
||||
#include "wifi.h"
|
||||
|
||||
|
||||
static const char *TAG = "webserver";
|
||||
|
||||
//const int CONNECTED_BIT;
|
||||
|
||||
//#define LED_BUILTIN 33
|
||||
#define delay(ms) (vTaskDelay(ms/portTICK_RATE_MS))
|
||||
char* json_unformatted;
|
||||
|
||||
const static char http_html_hdr[] =
|
||||
"HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n";
|
||||
const static char http_index_hml[] = "<!DOCTYPE html>"
|
||||
"<html>\n"
|
||||
"<head>\n"
|
||||
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
|
||||
" <style type=\"text/css\">\n"
|
||||
" html, body, iframe { margin: 0; padding: 0; height: 100%; }\n"
|
||||
" iframe { display: block; width: 100%; border: none; }\n"
|
||||
" </style>\n"
|
||||
"<title>HELLO ESP32</title>\n"
|
||||
"</head>\n"
|
||||
"<body>\n"
|
||||
"<h1>Hello World, from ESP32!</h1>\n"
|
||||
"</body>\n"
|
||||
"</html>\n";
|
||||
|
||||
|
||||
void http_server_netconn_serve(struct netconn *conn)
|
||||
{
|
||||
struct netbuf *inbuf;
|
||||
char *buf;
|
||||
u16_t buflen;
|
||||
err_t err;
|
||||
|
||||
/* Read the data from the port, blocking if nothing yet there.
|
||||
We assume the request (the part we care about) is in one netbuf */
|
||||
err = netconn_recv(conn, &inbuf);
|
||||
|
||||
if (err == ERR_OK) {
|
||||
netbuf_data(inbuf, (void**)&buf, &buflen);
|
||||
|
||||
// strncpy(_mBuffer, buf, buflen);
|
||||
|
||||
/* Is this an HTTP GET command? (only check the first 5 chars, since
|
||||
there are other formats for GET, and we're keeping it very simple )*/
|
||||
printf("buffer = %s \n", buf);
|
||||
if (buflen>=5 &&
|
||||
buf[0]=='G' &&
|
||||
buf[1]=='E' &&
|
||||
buf[2]=='T' &&
|
||||
buf[3]==' ' &&
|
||||
buf[4]=='/' ) {
|
||||
printf("buf[5] = %c\n", buf[5]);
|
||||
/* Send the HTML header
|
||||
* subtract 1 from the size, since we dont send the \0 in the string
|
||||
* NETCONN_NOCOPY: our data is const static, so no need to copy it
|
||||
*/
|
||||
|
||||
netconn_write(conn, http_html_hdr, sizeof(http_html_hdr)-1, NETCONN_NOCOPY);
|
||||
|
||||
if(buf[5]=='h') {
|
||||
gpio_set_level(LED_BUILTIN, 0);
|
||||
/* Send our HTML page */
|
||||
netconn_write(conn, http_index_hml, sizeof(http_index_hml)-1, NETCONN_NOCOPY);
|
||||
}
|
||||
else if(buf[5]=='l') {
|
||||
gpio_set_level(LED_BUILTIN, 1);
|
||||
/* Send our HTML page */
|
||||
netconn_write(conn, http_index_hml, sizeof(http_index_hml)-1, NETCONN_NOCOPY);
|
||||
}
|
||||
else if(buf[5]=='j') {
|
||||
netconn_write(conn, json_unformatted, strlen(json_unformatted), NETCONN_NOCOPY);
|
||||
}
|
||||
else {
|
||||
netconn_write(conn, http_index_hml, sizeof(http_index_hml)-1, NETCONN_NOCOPY);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* Close the connection (server closes in HTTP) */
|
||||
netconn_close(conn);
|
||||
|
||||
/* Delete the buffer (netconn_recv gives us ownership,
|
||||
so we have to make sure to deallocate the buffer) */
|
||||
netbuf_delete(inbuf);
|
||||
}
|
||||
|
||||
void generate_json() {
|
||||
cJSON *root, *info, *d;
|
||||
|
||||
struct timeval tv;
|
||||
|
||||
root = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddItemToObject(root, "d", d = cJSON_CreateObject());
|
||||
cJSON_AddItemToObject(root, "info", info = cJSON_CreateObject());
|
||||
|
||||
cJSON_AddStringToObject(d, "myName", "CMMC-ESP32-NANO");
|
||||
cJSON_AddNumberToObject(d, "temperature", 30.100);
|
||||
cJSON_AddNumberToObject(d, "humidity", 70.123);
|
||||
|
||||
cJSON_AddStringToObject(info, "ssid", "dummy");
|
||||
cJSON_AddNumberToObject(info, "heap", esp_get_free_heap_size());
|
||||
cJSON_AddStringToObject(info, "sdk", esp_get_idf_version());
|
||||
cJSON_AddNumberToObject(info, "time", gettimeofday(&tv, NULL));
|
||||
|
||||
while (1) {
|
||||
cJSON_ReplaceItemInObject(info, "heap",
|
||||
cJSON_CreateNumber(esp_get_free_heap_size()));
|
||||
cJSON_ReplaceItemInObject(info, "time",
|
||||
cJSON_CreateNumber(gettimeofday(&tv, NULL)));
|
||||
cJSON_ReplaceItemInObject(info, "sdk",
|
||||
cJSON_CreateString(esp_get_idf_version()));
|
||||
|
||||
json_unformatted = cJSON_PrintUnformatted(root);
|
||||
printf("[len = %d] ", strlen(json_unformatted));
|
||||
|
||||
for (int var = 0; var < strlen(json_unformatted); ++var) {
|
||||
putc(json_unformatted[var], stdout);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
delay(2000);
|
||||
free(json_unformatted);
|
||||
}
|
||||
}
|
||||
|
||||
void http_server_task(void *pvParameters)
|
||||
{
|
||||
struct netconn *conn, *newconn;
|
||||
err_t err;
|
||||
|
||||
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, false, true, portMAX_DELAY);
|
||||
ESP_LOGI(TAG, "Initializing Webserver");
|
||||
|
||||
conn = netconn_new(NETCONN_TCP);
|
||||
netconn_bind(conn, NULL, 80);
|
||||
netconn_listen(conn);
|
||||
do {
|
||||
err = netconn_accept(conn, &newconn);
|
||||
if (err == ERR_OK) {
|
||||
http_server_netconn_serve(newconn);
|
||||
netconn_delete(newconn);
|
||||
}
|
||||
} while(err == ERR_OK);
|
||||
netconn_close(conn);
|
||||
netconn_delete(conn);
|
||||
}
|
||||
6
main/webserver.h
Normal file
6
main/webserver.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef WEBSERVER_H_
|
||||
#define WEBSERVER_H_
|
||||
|
||||
void http_server_task(void *pvParameters);
|
||||
|
||||
#endif
|
||||
13
main/wifi.h
Normal file
13
main/wifi.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef WIFI_H_
|
||||
#define WIFI_H_
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected & ready to make a request */
|
||||
static EventGroupHandle_t wifi_event_group;
|
||||
|
||||
/* The event group allows multiple bits for each event,
|
||||
but we only care about one event - are we connected
|
||||
to the AP with an IP? */
|
||||
extern const int CONNECTED_BIT;
|
||||
//static const int CONNECTED_BIT = BIT0;
|
||||
|
||||
#endif
|
||||
33
sdkconfig
33
sdkconfig
@@ -85,8 +85,6 @@ CONFIG_AWS_EXAMPLE_PASSWORD="sdn"
|
||||
CONFIG_EXAMPLE_EMBEDDED_CERTS=
|
||||
CONFIG_EXAMPLE_SDCARD_CERTS=y
|
||||
CONFIG_EXAMPLE_FILESYSTEM_CERTS=y
|
||||
CONFIG_EXAMPLE_CERTIFICATE_PATH="/sdcard/esp32.crt"
|
||||
CONFIG_EXAMPLE_PRIVATE_KEY_PATH="/sdcard/esp32.key"
|
||||
CONFIG_EXAMPLE_ROOT_CA_PATH="/sdcard/ca.crt"
|
||||
|
||||
#
|
||||
@@ -422,11 +420,10 @@ CONFIG_MBEDTLS_HARDWARE_MPI=
|
||||
CONFIG_MBEDTLS_HARDWARE_SHA=
|
||||
CONFIG_MBEDTLS_HAVE_TIME=y
|
||||
CONFIG_MBEDTLS_HAVE_TIME_DATE=
|
||||
CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT=y
|
||||
CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT=
|
||||
CONFIG_MBEDTLS_TLS_SERVER_ONLY=
|
||||
CONFIG_MBEDTLS_TLS_CLIENT_ONLY=
|
||||
CONFIG_MBEDTLS_TLS_CLIENT_ONLY=y
|
||||
CONFIG_MBEDTLS_TLS_DISABLED=
|
||||
CONFIG_MBEDTLS_TLS_SERVER=y
|
||||
CONFIG_MBEDTLS_TLS_CLIENT=y
|
||||
CONFIG_MBEDTLS_TLS_ENABLED=y
|
||||
|
||||
@@ -436,15 +433,10 @@ CONFIG_MBEDTLS_TLS_ENABLED=y
|
||||
CONFIG_MBEDTLS_PSK_MODES=
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_RSA=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA=y
|
||||
CONFIG_MBEDTLS_SSL_RENEGOTIATION=y
|
||||
CONFIG_MBEDTLS_SSL_PROTO_SSL3=
|
||||
CONFIG_MBEDTLS_SSL_PROTO_TLS1=y
|
||||
CONFIG_MBEDTLS_SSL_PROTO_TLS1_1=y
|
||||
CONFIG_MBEDTLS_SSL_PROTO_TLS1=
|
||||
CONFIG_MBEDTLS_SSL_PROTO_TLS1_1=
|
||||
CONFIG_MBEDTLS_SSL_PROTO_TLS1_2=y
|
||||
CONFIG_MBEDTLS_SSL_PROTO_DTLS=
|
||||
CONFIG_MBEDTLS_SSL_ALPN=y
|
||||
@@ -472,22 +464,7 @@ CONFIG_MBEDTLS_PEM_PARSE_C=y
|
||||
CONFIG_MBEDTLS_PEM_WRITE_C=y
|
||||
CONFIG_MBEDTLS_X509_CRL_PARSE_C=y
|
||||
CONFIG_MBEDTLS_X509_CSR_PARSE_C=y
|
||||
CONFIG_MBEDTLS_ECP_C=y
|
||||
CONFIG_MBEDTLS_ECDH_C=y
|
||||
CONFIG_MBEDTLS_ECDSA_C=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_NIST_OPTIM=y
|
||||
CONFIG_MBEDTLS_ECP_C=
|
||||
|
||||
#
|
||||
# OpenSSL
|
||||
|
||||
@@ -85,8 +85,6 @@ CONFIG_AWS_EXAMPLE_PASSWORD="sdn"
|
||||
CONFIG_EXAMPLE_EMBEDDED_CERTS=
|
||||
CONFIG_EXAMPLE_SDCARD_CERTS=y
|
||||
CONFIG_EXAMPLE_FILESYSTEM_CERTS=y
|
||||
CONFIG_EXAMPLE_CERTIFICATE_PATH="/sdcard/esp32.crt"
|
||||
CONFIG_EXAMPLE_PRIVATE_KEY_PATH="/sdcard/esp32.key"
|
||||
CONFIG_EXAMPLE_ROOT_CA_PATH="/sdcard/ca.crt"
|
||||
|
||||
#
|
||||
@@ -131,8 +129,8 @@ CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y
|
||||
# FreeRTOS SystemView Tracing
|
||||
#
|
||||
CONFIG_AWS_IOT_SDK=y
|
||||
CONFIG_AWS_IOT_MQTT_HOSTNAME="VM-Linux"
|
||||
CONFIG_AWS_IOT_MQTT_HOST="192.168.0.126"
|
||||
CONFIG_AWS_IOT_MQTT_HOSTNAME="192.168.0.126"
|
||||
CONFIG_AWS_IOT_MQTT_ADDRESS="VM-Linux"
|
||||
CONFIG_AWS_IOT_MQTT_PORT=8883
|
||||
CONFIG_AWS_IOT_MQTT_TX_BUF_LEN=512
|
||||
CONFIG_AWS_IOT_MQTT_RX_BUF_LEN=512
|
||||
@@ -422,11 +420,10 @@ CONFIG_MBEDTLS_HARDWARE_MPI=
|
||||
CONFIG_MBEDTLS_HARDWARE_SHA=
|
||||
CONFIG_MBEDTLS_HAVE_TIME=y
|
||||
CONFIG_MBEDTLS_HAVE_TIME_DATE=
|
||||
CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT=y
|
||||
CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT=
|
||||
CONFIG_MBEDTLS_TLS_SERVER_ONLY=
|
||||
CONFIG_MBEDTLS_TLS_CLIENT_ONLY=
|
||||
CONFIG_MBEDTLS_TLS_CLIENT_ONLY=y
|
||||
CONFIG_MBEDTLS_TLS_DISABLED=
|
||||
CONFIG_MBEDTLS_TLS_SERVER=y
|
||||
CONFIG_MBEDTLS_TLS_CLIENT=y
|
||||
CONFIG_MBEDTLS_TLS_ENABLED=y
|
||||
|
||||
@@ -436,15 +433,10 @@ CONFIG_MBEDTLS_TLS_ENABLED=y
|
||||
CONFIG_MBEDTLS_PSK_MODES=
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_RSA=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA=y
|
||||
CONFIG_MBEDTLS_SSL_RENEGOTIATION=y
|
||||
CONFIG_MBEDTLS_SSL_PROTO_SSL3=
|
||||
CONFIG_MBEDTLS_SSL_PROTO_TLS1=y
|
||||
CONFIG_MBEDTLS_SSL_PROTO_TLS1_1=y
|
||||
CONFIG_MBEDTLS_SSL_PROTO_TLS1=
|
||||
CONFIG_MBEDTLS_SSL_PROTO_TLS1_1=
|
||||
CONFIG_MBEDTLS_SSL_PROTO_TLS1_2=y
|
||||
CONFIG_MBEDTLS_SSL_PROTO_DTLS=
|
||||
CONFIG_MBEDTLS_SSL_ALPN=y
|
||||
@@ -472,22 +464,7 @@ CONFIG_MBEDTLS_PEM_PARSE_C=y
|
||||
CONFIG_MBEDTLS_PEM_WRITE_C=y
|
||||
CONFIG_MBEDTLS_X509_CRL_PARSE_C=y
|
||||
CONFIG_MBEDTLS_X509_CSR_PARSE_C=y
|
||||
CONFIG_MBEDTLS_ECP_C=y
|
||||
CONFIG_MBEDTLS_ECDH_C=y
|
||||
CONFIG_MBEDTLS_ECDSA_C=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_NIST_OPTIM=y
|
||||
CONFIG_MBEDTLS_ECP_C=
|
||||
|
||||
#
|
||||
# OpenSSL
|
||||
|
||||
Reference in New Issue
Block a user