Hi @zepman
I think I figured out the issue. The way you are running your MQTT server likely only allows local connections.
I used mosquitto and set allow_anonymous to true
.
full config file:
# Place this configuration in /usr/local/etc/mosquitto/mosquitto.conf or the relevant config path for your installation.
# Configures the port Mosquitto will listen on. The default MQTT port is 1883.
port 1883
# By default, Mosquitto listens on all network interfaces (0.0.0.0).
# If you want to specify this explicitly, uncomment the following line.
bind_address 0.0.0.0
# Optional: Specify which IP addresses or ranges are allowed to connect.
# By default, all addresses are allowed.
allow_anonymous true
# Optional: Configure listener settings to listen on multiple ports or bind to specific addresses.
# Example for TLS/SSL:
# listener 8883
# cafile /path/to/ca.crt
# certfile /path/to/server.crt
# keyfile /path/to/server.key
# Enable logging for debugging purposes.
log_type all
log_dest file /usr/local/var/log/mosquitto/mosquitto.log
# Optional: Set the persistence file path to store messages and client information.
persistence true
persistence_location /usr/local/var/lib/mosquitto/
full oak file:
import depthai as dai
# Change the IP to your MQTT broker
MQTT_BROKER = "10.12.118.151"
MQTT_BROKER_PORT = 1883
MQTT_TOPIC = "test/topic"
pipeline = dai.Pipeline()
script = pipeline.create(dai.node.Script)
script.setProcessor(dai.ProcessorType.LEON_CSS)
script_text = f"""
import time
time.sleep(10)
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}")
(f, bl) = dai.DeviceBootloader.getFirstAvailableDevice()
bootloader = dai.DeviceBootloader(bl)
progress = lambda p : print(f'Flashing progress: {p*100:.1f}%')
(r, errmsg) = bootloader.flash(progress, pipeline)
if r: print("Flash OK")
else: print("Flash ERROR:", errmsg)
Thanks,
Jaka