1---2name: iot3description: Assist with IoT device setup, protocols, security hardening, and home automation integration.4---56## Protocol Selection7- MQTT for lightweight messaging — pub/sub, low bandwidth, ideal for sensors8- CoAP for constrained devices — UDP-based, REST-like, very low power9- HTTP/REST for capable devices — familiar but heavier, use when bandwidth allows10- WebSocket for real-time bidirectional — dashboards, live updates11- Zigbee/Z-Wave for mesh networks — no WiFi needed, battery-friendly1213## MQTT Essentials14- Broker is the central hub — Mosquitto most common self-hosted15- Topics are hierarchical — home/livingroom/temperature16- QoS levels: 0 (fire-forget), 1 (at least once), 2 (exactly once)17- Retain flag keeps last message — new subscribers get current state18- Will message announces disconnection — device offline detection1920## Security (Critical)21- Never expose MQTT broker to internet without auth — bots scan constantly22- TLS mandatory for any external access — encrypt all traffic23- Unique credentials per device — revoke one without affecting others24- Firmware updates must be signed — prevent malicious updates25- Segment IoT on separate VLAN — isolate from main network2627## Common Vulnerabilities28- Default credentials left unchanged — first thing attackers try29- Unencrypted protocols on network — credentials sniffable30- No firmware update mechanism — stuck with known vulnerabilities31- Cloud dependency without fallback — device useless when server down32- Debug ports left enabled — UART, JTAG exposed3334## Home Assistant Integration35- MQTT discovery auto-configures devices — follow HA format36- ESPHome for custom ESP devices — YAML config, OTA updates37- Zigbee2MQTT bridges Zigbee to MQTT — hundreds of devices supported38- Tasmota for off-the-shelf flashing — many WiFi devices supported3940## ESP32/ESP8266 Development41- Arduino framework most accessible — huge library ecosystem42- ESP-IDF for production — FreeRTOS, more control, steeper curve43- PlatformIO over Arduino IDE — better dependency management44- Deep sleep for battery life — microamps when sleeping45- OTA updates essential — don't require physical access4647## Power Management48- Battery devices need deep sleep — wake on timer or interrupt49- Calculate power budget — mAh capacity vs average consumption50- Solar charging viable — small panel can sustain low-power sensors51- Supercapacitors for burst power — supplement weak batteries52- Monitor battery voltage — alert before device dies5354## Connectivity Patterns55- WiFi: high bandwidth, high power — plugged devices56- Zigbee/Z-Wave: mesh, low power — battery sensors57- LoRa: long range, low bandwidth — outdoor, agricultural58- BLE: short range, low power — wearables, beacons59- Thread/Matter: new standard — Apple/Google/Amazon unified6061## Reliability62- Watchdog timer prevents freezes — reset if loop stalls63- Persistent storage for state — survive power cycles64- Heartbeat/ping monitoring — detect silent failures65- Graceful degradation — work offline when cloud unavailable66- Redundant sensors for critical systems — don't trust single point6768## Data Considerations69- Sample rate vs storage — don't over-collect70- Local processing when possible — reduce bandwidth, latency71- Time synchronization critical — NTP for timestamps72- Aggregate before sending — reduce message count73- Retain important data locally — survive connectivity loss7475## Debugging76- Serial output for development — remove in production77- MQTT debug topics — publish diagnostics78- LED status indicators — quick visual feedback79- Remote logging carefully — don't flood network80- Simulate sensors for testing — don't wait for real conditions8182## Vendor Lock-in83- Prefer local API devices — Tuya local, Shelly, Tasmota-compatible84- Cloud-only devices risky — company shutdowns brick devices85- Open protocols over proprietary — MQTT, Zigbee over custom86- Check if flashable — many devices accept custom firmware87- Matter promises interoperability — but still maturing