tinycodinglm / sys /sys-0022.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 19)
034ba67 verified
|
Raw History Blame
1.97 kB
deepseek-harness trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

User

How does MQTT work and when should I use it?

Assistant
markdown
MQTT (Message Queuing Telemetry Transport):
- Lightweight pub/sub protocol for IoT
- Uses TCP port 1883 (8883 for TLS)
- QoS levels: 0 (at most once), 1 (at least once), 2 (exactly once)
- Retained messages and last will testament

Broker options:
- Mosquitto (lightweight, self-hosted)
- EMQX (high performance, clustering)
- AWS IoT Core (managed)
- HiveMQ (enterprise)

Topic hierarchy:
sensors/temperature/living-room
sensors/humidity/bedroom
devices/+/status  (+ = single level wildcard)
sensors/#          (# = multi-level wildcard)

Example (Python with paho-mqtt):
```python
import paho.mqtt.client as mqtt

def on_connect(client, userdata, flags, rc):
    client.subscribe("sensors/#")
    client.publish("devices/status", "online", retain=True)

def on_message(client, userdata, msg):
    print(f"{msg.topic}: {msg.payload.decode()}")

client = mqtt.Client()
client.will_set("devices/status", "offline", retain=True)
client.on_connect = on_connect
client.on_message = on_message
client.connect("broker.example.com", 1883)
client.loop_forever()

Use cases:

  • Sensor data collection
  • Device control/commands
  • Remote monitoring
  • Smart home automation
  • Fleet management
markdown