Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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] Mon, 14 September 2020 02:15
ball chu is currently offline ball chuFriend
Messages: 1
Registered: September 2020
Junior Member
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: Mon Sep 21 19:52:42 GMT 2020

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

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

Back to the top