2024-09-17 11:27:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- |
							 
						 
					
						
							
								
									
										
										
										
											2022-05-20 17:50:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-07-24 16:59:03 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# ESP-MQTT SSL Sample application
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								(See the README.md file in the upper level 'examples' directory for more information about examples.)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-23 15:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This example connects to the broker mqtt.eclipseprojects.io using ssl transport and as a demonstration subscribes/unsubscribes and send a message on certain topic.
							 
						 
					
						
							
								
									
										
										
										
											2019-06-12 14:55:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								(Please note that the public broker is maintained by the community so may not be always available, for details please see this [disclaimer ](https://iot.eclipse.org/getting-started/#sandboxes ))
							 
						 
					
						
							
								
									
										
										
										
											2018-07-24 16:59:03 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								It uses ESP-MQTT library which implements mqtt client to connect to mqtt broker.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## How to use example
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Hardware Required
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This example can be executed on any ESP32 board, the only required interface is WiFi and connection to internet.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Configure the project
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-23 11:54:31 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								*  Open the project configuration menu (`idf.py menuconfig` ) 
						 
					
						
							
								
									
										
										
										
											2018-11-21 00:42:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								*  Configure Wi-Fi or Ethernet under "Example Connection Configuration" menu. See "Establishing Wi-Fi or Ethernet Connection" section in [examples/protocols/README.md ](../../README.md ) for more details. 
						 
					
						
							
								
									
										
										
										
											2018-07-24 16:59:03 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-23 15:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								PEM certificate for this example could be extracted from an openssl `s_client`  command connecting to mqtt.eclipseprojects.io.
							 
						 
					
						
							
								
									
										
										
										
											2019-06-12 14:55:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								In case a host operating system has `openssl`  and `sed`  packages installed, one could execute the following command to download and save the root certificate to a file (Note for Windows users: Both Linux like environment or Windows native packages may be used).
							 
						 
					
						
							
								
									
										
										
										
											2018-07-24 16:59:03 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2021-02-23 15:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								echo "" | openssl s_client -showcerts -connect mqtt.eclipseprojects.io:8883 | sed -n "1,/Root/d; /BEGIN/,/END/p" | openssl x509 -outform PEM >mqtt_eclipse_org.pem
							 
						 
					
						
							
								
									
										
										
										
											2018-07-24 16:59:03 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2019-06-12 14:55:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Please note that this is not a general command for downloading a root certificate for an arbitrary host;
							 
						 
					
						
							
								
									
										
										
										
											2021-02-23 15:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								this command works with mqtt.eclipseprojects.io as the site provides root certificate in the chain, which then could be extracted
							 
						 
					
						
							
								
									
										
										
										
											2019-06-12 14:55:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								with text operation.
							 
						 
					
						
							
								
									
										
										
										
											2018-07-24 16:59:03 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Build and Flash
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Build the project and flash it to the board, then run monitor tool to view serial output:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2019-08-02 09:01:20 +05:30 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								idf.py -p PORT flash monitor
							 
						 
					
						
							
								
									
										
										
										
											2018-07-24 16:59:03 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								(To exit the serial monitor, type ``Ctrl-]` `.)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Example Output
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (3714) event: sta ip: 192.168.0.139, mask: 255.255.255.0, gw: 192.168.0.2
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (3714) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (3964) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (4164) MQTTS_EXAMPLE: MQTT_EVENT_CONNECTED
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (4174) MQTTS_EXAMPLE: sent publish successful, msg_id=41464
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (4174) MQTTS_EXAMPLE: sent subscribe successful, msg_id=17886
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (4174) MQTTS_EXAMPLE: sent subscribe successful, msg_id=42970
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (4184) MQTTS_EXAMPLE: sent unsubscribe successful, msg_id=50241
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (4314) MQTTS_EXAMPLE: MQTT_EVENT_PUBLISHED, msg_id=41464
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (4484) MQTTS_EXAMPLE: MQTT_EVENT_SUBSCRIBED, msg_id=17886
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (4484) MQTTS_EXAMPLE: sent publish successful, msg_id=0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (4684) MQTTS_EXAMPLE: MQTT_EVENT_SUBSCRIBED, msg_id=42970
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (4684) MQTTS_EXAMPLE: sent publish successful, msg_id=0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (4884) MQTT_CLIENT: deliver_publish, message_length_read=19, message_length=19
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (4884) MQTTS_EXAMPLE: MQTT_EVENT_DATA
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								TOPIC=/topic/qos0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								DATA=data
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (5194) MQTT_CLIENT: deliver_publish, message_length_read=19, message_length=19
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								I (5194) MQTTS_EXAMPLE: MQTT_EVENT_DATA
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								TOPIC=/topic/qos0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								DATA=data
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```