Add files via upload

This commit is contained in:
SIMS IOT Devices 2023-06-30 09:48:27 +03:00 committed by GitHub
commit 732c2f424f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 285 additions and 0 deletions

2
CMakeLists.txt Normal file
View File

@ -0,0 +1,2 @@
idf_component_register(SRCS "proj1.c"
INCLUDE_DIRS ".")

4
certs/MQTTS.txt Normal file
View File

@ -0,0 +1,4 @@
Commands:
mosquitto_sub -h test.mosquitto.org -t "my_topic" -p 8883 --cafile mosquitto.org.crt --key client.key --cert client.crt -d
mosquitto_pub --cafile mosquitto.org.crt --key client.key --cert client.crt -h test.mosquitto.org -m "Hello World ......." -t "my_topic" -p 8883 -d

20
certs/client.crt Normal file
View File

@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDVTCCAj2gAwIBAgIBADANBgkqhkiG9w0BAQsFADCBkDELMAkGA1UEBhMCR0Ix
FzAVBgNVBAgMDlVuaXRlZCBLaW5nZG9tMQ4wDAYDVQQHDAVEZXJieTESMBAGA1UE
CgwJTW9zcXVpdHRvMQswCQYDVQQLDAJDQTEWMBQGA1UEAwwNbW9zcXVpdHRvLm9y
ZzEfMB0GCSqGSIb3DQEJARYQcm9nZXJAYXRjaG9vLm9yZzAeFw0yMTEwMDIxMDM0
MTVaFw0yMTEyMzExMDM0MTVaMC8xCzAJBgNVBAYTAklTMREwDwYDVQQKDAhTSU1T
IElPVDENMAsGA1UEAwwEU0lNUzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
ggEBAKcw9QX2q9YYg2ndexlVPSUR5zSjQLuW6bcrNBaZDvns3qcUNWtf6dYVRpuI
dPgvlSSXJKq9pHQyVGs/TBz4Uc52kGBQuxHYquiF0jzr933jccGd0WCU6MhWUroc
xabCfNbecr9XPtBg5NuHCC1TdfiRk5bKR00jCaTxUAQAMHfXvUj2xh5NLa8NsnoH
UnJzde/K0zJm7cLsfXS922oRdmIZ579aCMNyAidqXd0sW7q0h9q1wFKqmyu2TCRr
CgXf+y/sWW5WtKGv5dMEVnTaGGA/ZT7yS2HPe2r1zCxhyFA5v8xwTWefNQ9r0aR/
omd7MWzYhdndh2jN3ULHe7i5cikCAwEAAaMaMBgwCQYDVR0TBAIwADALBgNVHQ8E
BAMCBeAwDQYJKoZIhvcNAQELBQADggEBAMAN2MH8ji8trGfLC4Ig+12gvldWiilC
CVHnlzlcXw146p9yZSKYTjhB9mKvmEfwqrTaFzeIVNyLnLjyie502tQ6BhN1RRaM
scq4KDnmyZK5aQNVNo2mL5RtBEumpMzqpFFePwcUMiLhQcvpiYS1Z08vglcwNWZx
CSu98gkU3VJex+FLzpodmN6w/rYj6xJLq2EAZ5kxm9/xgP2pF3fpI0u6vxKS/kQq
RwPhCi525OZ4OiKXuaBDPtTtRWnfVNlaTS9BCdYwaR6/omscFCCnqVKS6XvV2Uod
oz+4OxMk6529siOvGwH/iyOa4563/JC4GvfgptxEJDIknCW1SN62qoI=
-----END CERTIFICATE-----

28
certs/client.key Normal file
View File

@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCnMPUF9qvWGINp
3XsZVT0lEec0o0C7lum3KzQWmQ757N6nFDVrX+nWFUabiHT4L5UklySqvaR0MlRr
P0wc+FHOdpBgULsR2KrohdI86/d943HBndFglOjIVlK6HMWmwnzW3nK/Vz7QYOTb
hwgtU3X4kZOWykdNIwmk8VAEADB3171I9sYeTS2vDbJ6B1Jyc3XvytMyZu3C7H10
vdtqEXZiGee/WgjDcgInal3dLFu6tIfatcBSqpsrtkwkawoF3/sv7FluVrShr+XT
BFZ02hhgP2U+8kthz3tq9cwsYchQOb/McE1nnzUPa9Gkf6JnezFs2IXZ3Ydozd1C
x3u4uXIpAgMBAAECggEAANYE0sRMv3kLiYaUOJOWl6acaIp79hvTJs/QAQdm4U1K
DqRoehrPiHg41LISaEUUNL3cm16GMnCA0F28CpmyA3XQNIv1O1Y2ExdAp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PVV6xBUFPiGKDyo5V3+Hbh4N9YSMB8GA1UdIwQYMBaAFPVV
6xBUFPiGKDyo5V3+Hbh4N9YSMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEL
BQADggEBAGa9kS21N70ThM6/Hj9D7mbVxKLBjVWe2TPsGfbl3rEDfZ+OKRZ2j6AC
6r7jb4TZO3dzF2p6dgbrlU71Y/4K0TdzIjRj3cQ3KSm41JvUQ0hZ/c04iGDg/xWf
+pp58nfPAYwuerruPNWmlStWAXf0UTqRtg4hQDWBuUFDJTuWuuBvEXudz74eh/wK
sMwfu1HFvjy5Z0iMDU8PUDepjVolOCue9ashlS4EB5IECdSR2TItnAIiIwimx839
LdUdRudafMu5T5Xma182OC0/u/xRlEm+tvKGGmfFcN0piqVl8OrSPBgIlb+1IKJE
m/XriWr/Cq4h/JfB7NTsezVslgkBaoU=
-----END CERTIFICATE-----

1
component.mk Normal file
View File

@ -0,0 +1 @@
COMPONENT_EMBED_TXTFILES := mqtt_eclipseprojects_io.pem

View File

@ -0,0 +1,72 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCnMPUF9qvWGINp
3XsZVT0lEec0o0C7lum3KzQWmQ757N6nFDVrX+nWFUabiHT4L5UklySqvaR0MlRr
P0wc+FHOdpBgULsR2KrohdI86/d943HBndFglOjIVlK6HMWmwnzW3nK/Vz7QYOTb
hwgtU3X4kZOWykdNIwmk8VAEADB3171I9sYeTS2vDbJ6B1Jyc3XvytMyZu3C7H10
vdtqEXZiGee/WgjDcgInal3dLFu6tIfatcBSqpsrtkwkawoF3/sv7FluVrShr+XT
BFZ02hhgP2U+8kthz3tq9cwsYchQOb/McE1nnzUPa9Gkf6JnezFs2IXZ3Ydozd1C
x3u4uXIpAgMBAAECggEAANYE0sRMv3kLiYaUOJOWl6acaIp79hvTJs/QAQdm4U1K
DqRoehrPiHg41LISaEUUNL3cm16GMnCA0F28CpmyA3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PFhrCUcRHSSxo
E6yjGOdnz7f6PveLIB574kQORwt8ePn0yidrTC1ictikED3nHYhMUOUCAwEAAaNT
MFEwHQYDVR0OBBYEFPVV6xBUFPiGKDyo5V3+Hbh4N9YSMB8GA1UdIwQYMBaAFPVV
6xBUFPiGKDyo5V3+Hbh4N9YSMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEL
BQADggEBAGa9kS21N70ThM6/Hj9D7mbVxKLBjVWe2TPsGfbl3rEDfZ+OKRZ2j6AC
6r7jb4TZO3dzF2p6dgbrlU71Y/4K0TdzIjRj3cQ3KSm41JvUQ0hZ/c04iGDg/xWf
+pp58nfPAYwuerruPNWmlStWAXf0UTqRtg4hQDWBuUFDJTuWuuBvEXudz74eh/wK
sMwfu1HFvjy5Z0iMDU8PUDepjVolOCue9ashlS4EB5IECdSR2TItnAIiIwimx839
LdUdRudafMu5T5Xma182OC0/u/xRlEm+tvKGGmfFcN0piqVl8OrSPBgIlb+1IKJE
m/XriWr/Cq4h/JfB7NTsezVslgkBaoU=
-----END CERTIFICATE-----

7
my_data1.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef MY_DATA
#define MY_DATA
#define SSID "your ssid"
#define PASS "your pasword"
#endif

127
proj1.c Normal file
View File

@ -0,0 +1,127 @@
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "esp_wifi.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "esp_log.h"
#include "mqtt_client.h"
#include "esp_tls.h"
#include "esp_ota_ops.h"
#include "my_data.h"
static const char *TAG = "MQTT_TCP";
extern const uint8_t mqtt_eclipseprojects_io_pem_start[] asm("_binary_mqtt_eclipseprojects_io_pem_start");
extern const uint8_t mqtt_eclipseprojects_io_pem_end[] asm("_binary_mqtt_eclipseprojects_io_pem_end");
static void wifi_event_handler(void *event_handler_arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
switch (event_id)
{
case WIFI_EVENT_STA_START:
printf("WiFi connecting ... \n");
break;
case WIFI_EVENT_STA_CONNECTED:
printf("WiFi connected ... \n");
break;
case WIFI_EVENT_STA_DISCONNECTED:
printf("WiFi lost connection ... \n");
break;
case IP_EVENT_STA_GOT_IP:
printf("WiFi got IP ... \n\n");
break;
default:
break;
}
}
void wifi_connection()
{
// 1 - Wi-Fi/LwIP Init Phase
esp_netif_init(); // TCP/IP initiation s1.1
esp_event_loop_create_default(); // event loop s1.2
esp_netif_create_default_wifi_sta(); // WiFi station s1.3
wifi_init_config_t wifi_initiation = WIFI_INIT_CONFIG_DEFAULT();
esp_wifi_init(&wifi_initiation); // s1.4
// 2 - Wi-Fi Configuration Phase
esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, wifi_event_handler, NULL);
esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, wifi_event_handler, NULL);
wifi_config_t wifi_configuration = {
.sta = {
.ssid = SSID,
.password = PASS}};
esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_configuration);
// 3 - Wi-Fi Start Phase
esp_wifi_start();
// 4- Wi-Fi Connect Phase
esp_wifi_connect();
}
static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
{
esp_mqtt_client_handle_t client = event->client;
switch (event->event_id)
{
case MQTT_EVENT_CONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
esp_mqtt_client_subscribe(client, "my_topic", 0);
esp_mqtt_client_publish(client, "my_topic", "Hi to all from ESP32 .........", 0, 1, 0);
break;
case MQTT_EVENT_DISCONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
break;
case MQTT_EVENT_SUBSCRIBED:
ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_UNSUBSCRIBED:
ESP_LOGI(TAG, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_PUBLISHED:
ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_DATA:
ESP_LOGI(TAG, "MQTT_EVENT_DATA");
printf("\nTOPIC=%.*s\r\n", event->topic_len, event->topic);
printf("DATA=%.*s\r\n", event->data_len, event->data);
break;
case MQTT_EVENT_ERROR:
ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
break;
default:
ESP_LOGI(TAG, "Other event id:%d", event->event_id);
break;
}
return ESP_OK;
}
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
{
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id);
mqtt_event_handler_cb(event_data);
}
static void mqtt_app_start(void)
{
esp_mqtt_client_config_t mqtt_cfg = {
.uri = "mqtts://test.mosquitto.org:8883",
.cert_pem = (const char *)mqtt_eclipseprojects_io_pem_start,
};
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, client);
esp_mqtt_client_start(client);
}
void app_main(void)
{
nvs_flash_init();
wifi_connection();
vTaskDelay(2000 / portTICK_PERIOD_MS);
printf("WIFI was initiated ...........\n");
mqtt_app_start();
}