I have the OAK-D Pro PoE and use a script node to send messages via MQTT. I'm finding that if the pipeline contains only the script node that does the MQTT publishing, it does not work in standalone mode (but it works fine in host-connected mode).
The following is an MRE.
import depthai as dai
# Change the IP to your MQTT broker
MQTT_BROKER = "192.168.0.5"
MQTT_BROKER_PORT = 1883
MQTT_TOPIC = "stat/camera1"
pipeline = dai.Pipeline()
script = pipeline.create(dai.node.Script)
script.setProcessor(dai.ProcessorType.LEON_CSS)
script_text = f"""
mqttc = Client()
node.warn('Connecting to MQTT broker...')
mqttc.connect("{MQTT_BROKER}", {MQTT_BROKER_PORT}, 60)
node.warn('Successfully connected to MQTT broker!')
mqttc.loop_start()
cnt = 0
while True:
cnt+=1
if cnt > 100000:
node.warn("test_message")
(ok, id) = mqttc.publish("{MQTT_TOPIC}", "test_message", qos=2)
cnt = 0
"""
with open("paho-mqtt.py", "r") as f:
paho_script = f.read()
script.setScript(f"{paho_script}\n{script_text}")
The above pipeline runs fine when run in host-connected mode i.e., I see the message being published continuously, using MQTT Explorer. However, the same pipeline doesn't work in standalone mode (flashing completes successfully and the device restarts with a "clicking" sound); I don't see any message published.
Now, if I modify the script to serve the message via HTTP instead of MQTT, like below, then the pipeline works fine in both host-connected and standalone modes.
script.setScript("""
from socketserver import ThreadingMixIn
from http.server import BaseHTTPRequestHandler, HTTPServer
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
pass
class HTTPHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.send_response(200)
self.end_headers()
self.wfile.write(b'<h1>test_message</h1>')
with ThreadingSimpleServer(("", 8080), HTTPHandler) as httpd:
httpd.serve_forever()
""")
I don't quite understand what might be the issue here. Any help would be appreciated!