Skip to main content



      Home
Home » Eclipse Projects » Mosquitto » Using MQTT with HTTP serving stream(using both MQTT with HTTP causing MQTT messages to be lost (Python))
Using MQTT with HTTP serving stream [message #1832239] Sun, 13 September 2020 22:15
Eclipse UserFriend
I am trying to use MQTT to receive messages while using a Streaming HTTP server to stream my picamera onto my 5000 port within the same file. This is causing my MQTT to be rather unstable and it cannot receive messages at time. May I know anyone has a solution to this? Thank you.

MQTT code
```
def on_connect(client,rc):
if rc == 0:
global Connected
Connected = True
client.subscribe("picam/show")

def on_message(client, userdata, message):
global capture_image
data = message.payload.decode("utf-8").replace("'", '"')
d = json.loads(data)

if d["action"] == "take pic":
try:
capture_image()
except Exception as e:
print(e)

client = mqttClient.Client("picam")
client.on_connect= on_connect
client.connect(broker_address, port=1884)

# edited here to change loop_forever to loop_start
client.loop_start()
```

Streaming HTTP Code
```
output = StreamingOutput()
camera.start_recording(output, format='mjpeg')
try:
address = ('', 5000)
server = StreamingServer(address, StreamingHandler)
server.serve_forever()
finally:
camera.stop_recording()
```
Previous Topic:Project not reconnecting
Next Topic:How to make sure client connects with TLS?
Goto Forum:
  


Current Time: Wed Jul 09 21:58:10 EDT 2025

Powered by FUDForum. Page generated in 0.04356 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top