Comments (5)
Hi @ninjas005, the MQTTConfig
object has an .ssl
field that you can enable when filling it.
Using it with ssl=True
+ your secure mqtts host + modified port should work ok. Did you have any problem with it?
from fastapi-mqtt.
it was not able to connect to the broker, but got refused as broker needs the client certificate to pass me through
The .ssl
field is defined as Union[bool, SSLContext]
for that reason. If you need extra data for the TLS/SSL connection, you need to configure the SSLContext
.
As an example, to connect to https://test.mosquitto.org using port 8883 (MQTT, encrypted, unauthenticated), which requires the cert file, the config should look like this:
from ssl import create_default_context
from fastapi_mqtt import FastMQTT, MQTTConfig
# cert file downloaded from https://test.mosquitto.org/ssl/mosquitto.org.crt
ssl = create_default_context(cafile="tests/mosquitto.org.crt")
mqtt_config = MQTTConfig(host="test.mosquitto.org", port=8883, ssl=ssl)
fast_mqtt = FastMQTT(config=mqtt_config)
from fastapi-mqtt.
ok thank you.
from fastapi-mqtt.
I had already did enabling ssl with the .ssl
field and used port 8883. butit was not able to connect to the broker, but got refused as broker needs the client certificate to pass me through.
mqtt_config = MQTTConfig(host=MQTT_CONFIG['host'],
port=MQTT_CONFIG['port'],
username=MQTT_CONFIG['user'],
password=MQTT_CONFIG['pass'],
reconnect_retries=-1,
reconnect_delay=30,
ssl=True
)
fast_mqtt = FastMQTT(config=mqtt_config)
this was my configuration. when i checked the MQTTConfig
Class it says about a SSLContext Object which will have the cafile
but I am confused how to add that SSLContext object.
from fastapi-mqtt.
Closing this as resolved 👍, ok @ninjas005 ?
from fastapi-mqtt.
Related Issues (20)
- Using Pydantic models for messages HOT 4
- How to feed mqtt messages from within a fastapi websocket ? (ie. proxying) HOT 1
- Will message functionality and example broken HOT 1
- Version 1.8 is broken HOT 4
- Version 1.0.8 is broken HOT 1
- Shared Subscription HOT 3
- 🐛 IndexError in topic matching algorithm
- Pydantic v2 HOT 8
- api endpoint for subscribe HOT 1
- How to use this library with another api endpoint that does something else before return the mqtt topic content in the logic? HOT 3
- RuntimeError: no validator found for <class 'ssl.SSLContext'>, see `arbitrary_types_allowed` in Config HOT 2
- init_app doesn't seem to work with lifespans HOT 2
- Python version < 3.10 TypeError: unsupported operand type(s) for |: 'type' and 'NoneType' HOT 1
- FastAPI's on_event is deprecated, use lifespan event handlers instead HOT 1
- 🚨 Fix GH Action for pypi publish HOT 5
- Error found on the example page of the document
- Deprecation Warning HOT 1
- doesn't recognize payload as valid json HOT 1
- Adding reason_code during disconnect
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastapi-mqtt.