importpaho.mqtt.clientasmqttimportmathimportjsonfromtimeimportsleepimportnumpyasnp# MQTT Broker detailsBROKER="localhost"# Change to your MQTT broker addressPORT=1883# Default MQTT portTOPIC="sensor/data"# MQTT topic to publish data# Create MQTT clientclient=mqtt.Client()client.connect(BROKER,PORT,60)time_counter=0.0whileTrue:sleep(0.05)# 50 ms sleep for 10 Hztime_counter+=0.05# Increment time# Create data payloaddata={"timestamp":time_counter,"test_data":{"cos":math.cos(time_counter),"sin":math.sin(time_counter),"floor":np.floor(np.cos(time_counter)),"ceil":np.ceil(np.cos(time_counter))}}# Convert to JSON and publishclient.publish(TOPIC,json.dumps(data))print(f"Published: {data}")