diff --git a/examples/native_networking/minimqtt_adafruitio_native_networking.py b/examples/native_networking/minimqtt_adafruitio_native_networking.py index 21661d31..75720b31 100644 --- a/examples/native_networking/minimqtt_adafruitio_native_networking.py +++ b/examples/native_networking/minimqtt_adafruitio_native_networking.py @@ -36,6 +36,7 @@ ### Code ### + # Define callback methods which are called when events occur # pylint: disable=unused-argument, redefined-outer-name def connected(client, userdata, flags, rc): @@ -59,6 +60,16 @@ def message(client, topic, message): # Create a socket pool pool = socketpool.SocketPool(wifi.radio) +ssl_context = ssl.create_default_context() + +# If you need to use certificate/key pair authentication (e.g. X.509), you can load them in the +# ssl context by uncommenting the lines below and adding the following keys to the "secrets" +# dictionary in your secrets.py file: +# "device_cert_path" - Path to the Device Certificate +# "device_key_path" - Path to the RSA Private Key +# ssl_context.load_cert_chain( +# certfile=secrets["device_cert_path"], keyfile=secrets["device_key_path"] +# ) # Set up a MiniMQTT Client mqtt_client = MQTT.MQTT( @@ -67,7 +78,7 @@ def message(client, topic, message): username=secrets["aio_username"], password=secrets["aio_key"], socket_pool=pool, - ssl_context=ssl.create_default_context(), + ssl_context=ssl_context, ) # Setup the callback methods above diff --git a/examples/native_networking/minimqtt_pub_sub_blocking_native_networking.py b/examples/native_networking/minimqtt_pub_sub_blocking_native_networking.py index 58dbc7f7..b296eacc 100644 --- a/examples/native_networking/minimqtt_pub_sub_blocking_native_networking.py +++ b/examples/native_networking/minimqtt_pub_sub_blocking_native_networking.py @@ -32,6 +32,7 @@ # Setup a feed named `testfeed` for publishing. default_topic = secrets["aio_username"] + "/feeds/testfeed" + ### Code ### # Define callback methods which are called when events occur # pylint: disable=unused-argument, redefined-outer-name @@ -59,6 +60,16 @@ def message(client, topic, message): # Create a socket pool pool = socketpool.SocketPool(wifi.radio) +ssl_context = ssl.create_default_context() + +# If you need to use certificate/key pair authentication (e.g. X.509), you can load them in the +# ssl context by uncommenting the lines below and adding the following keys to the "secrets" +# dictionary in your secrets.py file: +# "device_cert_path" - Path to the Device Certificate +# "device_key_path" - Path to the RSA Private Key +# ssl_context.load_cert_chain( +# certfile=secrets["device_cert_path"], keyfile=secrets["device_key_path"] +# ) # Set up a MiniMQTT Client mqtt_client = MQTT.MQTT( @@ -67,7 +78,7 @@ def message(client, topic, message): username=secrets["aio_username"], password=secrets["aio_key"], socket_pool=pool, - ssl_context=ssl.create_default_context(), + ssl_context=ssl_context, ) # Setup the callback methods above diff --git a/examples/native_networking/minimqtt_pub_sub_blocking_topic_callbacks_native_networking.py b/examples/native_networking/minimqtt_pub_sub_blocking_topic_callbacks_native_networking.py index 2a2eddf3..f38b627d 100644 --- a/examples/native_networking/minimqtt_pub_sub_blocking_topic_callbacks_native_networking.py +++ b/examples/native_networking/minimqtt_pub_sub_blocking_topic_callbacks_native_networking.py @@ -29,6 +29,7 @@ ### Code ### + # Define callback methods which are called when events occur # pylint: disable=unused-argument, redefined-outer-name def connected(client, userdata, flags, rc): @@ -66,6 +67,16 @@ def on_message(client, topic, message): # Create a socket pool pool = socketpool.SocketPool(wifi.radio) +ssl_context = ssl.create_default_context() + +# If you need to use certificate/key pair authentication (e.g. X.509), you can load them in the +# ssl context by uncommenting the lines below and adding the following keys to the "secrets" +# dictionary in your secrets.py file: +# "device_cert_path" - Path to the Device Certificate +# "device_key_path" - Path to the RSA Private Key +# ssl_context.load_cert_chain( +# certfile=secrets["device_cert_path"], keyfile=secrets["device_key_path"] +# ) # Set up a MiniMQTT Client client = MQTT.MQTT( @@ -74,7 +85,7 @@ def on_message(client, topic, message): username=secrets["aio_username"], password=secrets["aio_key"], socket_pool=pool, - ssl_context=ssl.create_default_context(), + ssl_context=ssl_context, ) # Setup the callback methods above