mqtt.py 597 Bytes
import paho.mqtt.client as mqtt
import random
import multiprocessing
import signal
import string
import sys
import logging
import time
import unittest

def mqtt_publish_flood(mqtt_server_IP, mqtt_server_PORT, topic):
    client = mqtt.Client("AA")
    client.connect(mqtt_server_IP, mqtt_server_PORT)
    client.loop_start()
    
    for i in range(10000):
        message = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(50))
        client.publish(topic, message, retain=True)
        print(f"Sent message {message}")
    client.loop_stop()
    client.disconnect()