Hi guys. I have huge problem with my code. Try to publish data by paho-mqtt (localhost, port=1883).
Blender is not frozen but I don’t receive anything on:
mosquitto_sub -v -t ‘#’ -h localhost -p 1883.
My code looks like that:
import threading import weakref import paho.mqtt.client as mqtt import time from bge import logic def main(): thread = Worker() thread.start() class Worker(threading.Thread): def __init__(self, *args): weakref.finalize(logic, self.kill) threading.Thread.__init__(self) scene = bge.logic.getCurrentScene() cube = scene.objects['Cube'] def kill(self): self.alive = False def on_message(client, userdata, message): print(message.topic) def run(self): client = mqtt.Client("relayr") client.on_message = self.on_message client.connect("localhost", 1883) client.loop_start() while self.alive: client.publish("devices/position/x", cube.position.x) client.publish("devices/position/y", cube.position.y) client.publish("devices/position/z", cube.position.z) time.sleep(5) client.disconnect() client.loop_stop() if __name__ == "__main__": main()
And logic game is like that:
I would be grateful for any help.
Common loop (while, or loop_forever) caused blender freezing.