# EMQX Rule Engine Configuration # Objectif: Forward MQTT messages from all brokers to Fiware brokers ## Architecture cible - Simulator → MQTT → EMQX, Mosquitto, BunkerM - EMQX Rule Engine → HTTP POST → Orion-LD, Stellio, FROST-Server - Mosquitto Bridge → EMQX (qui fait le forwarding) - BunkerM Bridge → EMQX (qui fait le forwarding) ## Configuration EMQX (via Dashboard: http://localhost:18081) ### 1. Créer une Règle (Rule) pour forwarder vers Orion-LD - **SQL**: `SELECT * FROM "city/sensors/#"` - **Action**: HTTP Server (Webhook) - **URL**: `http://localhost:2026/ngsi-ld/v1/entities` - **Headers**: - `Content-Type: application/ld+json` - `NGSILD-Tenant: smartcity` - **Body**: Transformez le payload MQTT en NGSI-LD ### 2. Créer une Règle pour forwarder vers Stellio - **SQL**: `SELECT * FROM "city/sensors/#"` - **Action**: HTTP Server - **URL**: `http://localhost:8080/ngsi-ld/v1/entities` - **Headers**: Similar to Orion-LD ### 3. Créer une Règle pour forwarder vers FROST-Server - **SQL**: `SELECT * FROM "city/sensors/#"` - **Action**: HTTP Server - **URL**: `http://localhost:8086/FROST-Server/v1.1/...` - **Body**: Format SensorThings API ## Alternative: Utiliser Mosquitto Bridge Dans `/mosquitto/config/mosquitto.conf`: ```conf # Bridge vers EMQX (déjà configuré) connection emqx_bridge address emqx_emqx_1:1883 topic city/sensors/# out 2 # Forward vers HTTP (nécessite un plugin ou script externe) # Mosquitto ne supporte pas nativement MQTT-to-HTTP ``` ## Solution recommandée 1. **Configurer EMQX Rule Engine** via Dashboard (http://localhost:18081) 2. **Mosquitto** et **BunkerM** : Bridge vers EMQX (qui fait le forwarding) 3. **Vérifier** que Orion-LD, Stellio, FROST reçoivent les données ## Test manuel ```bash # Publier un message sur EMQX mosquitto_pub -h localhost -p 11883 -t "city/sensors/test" -m '{"id":"test"}' # Vérifier Orion-LD curl http://localhost:2026/ngsi-ld/v1/entities/test ```