You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

Lorank8v1网关LoRa数据包接入Fiware架构及MQTT适配问询

Hey there, let's walk through how to get your LoRa data flowing into FIWARE Context Broker properly—you're already halfway there with the gateway and MQTT setup, so let's fill in the missing pieces.

整体系统架构调整

First, let's clarify the end-to-end flow you need. The gap right now is handling the encrypted LoRa payload and formatting it for the IoT Agent. Here's the revised architecture:

  • LoRa Nodes → Lorank8v1 Gateway → lora-gateway-bridge (UDP → MQTT) → Mosquitto Broker → Custom Node.js Decryption Service → MQTT/JSON IoT Agent → FIWARE Context Broker

The custom Node.js service is the key addition: it will listen for raw LoRa messages, decrypt/decode them, and reformat the data into a structure the IoT Agent can understand.

Step 1: Extend Your Node.js Code into a MQTT Forwarder

You already have the decryption logic—now wrap it into a MQTT client that subscribes to your raw gateway topic, processes messages, and publishes formatted data to the IoT Agent's target topic.

Here's a simplified example using the mqtt npm package:

const mqtt = require('mqtt');
const crypto = require('crypto');

// Configure your MQTT broker connection
const mqttClient = mqtt.connect('mqtt://localhost:1883');

// Replace with your actual AES-128 credentials
const AES_SECRET_KEY = Buffer.from('your-16-byte-aes-key-here', 'hex');
const AES_IV = Buffer.from('your-16-byte-iv-here', 'hex');

// Subscribe to the raw LoRa gateway topic on connect
mqttClient.on('connect', () => {
  mqttClient.subscribe('gateway/{gatewayid}/rx', (err) => {
    if (!err) console.log('Listening for raw LoRa messages...');
  });
});

// Process incoming messages
mqttClient.on('message', (topic, rawMessage) => {
  try {
    // Parse the raw gateway message (assuming it's JSON with base64 payload)
    const gatewayData = JSON.parse(rawMessage.toString());
    const encryptedPayload = Buffer.from(gatewayData.payload, 'base64');

    // Run your existing AES decryption logic
    const decipher = crypto.createDecipheriv('aes-128-cbc', AES_SECRET_KEY, AES_IV);
    let decryptedBuffer = decipher.update(encryptedPayload);
    decryptedBuffer = Buffer.concat([decryptedBuffer, decipher.final()]);
    const decodedSensorData = JSON.parse(decryptedBuffer.toString()); // Adjust if your decoded data is not JSON

    // Format the data for the MQTT/JSON IoT Agent
    const iotAgentReadyPayload = {
      temperature: decodedSensorData.temp,
      humidity: decodedSensorData.humid,
      // Add other sensor fields here, matching your device's registered attributes
    };

    // Publish to the IoT Agent's listening topic (replace {deviceid} with your actual device ID)
    const targetTopic = `/json/{deviceid}/attrs`;
    mqttClient.publish(targetTopic, JSON.stringify(iotAgentReadyPayload));
    console.log(`Sent formatted data to IoT Agent: ${JSON.stringify(iotAgentReadyPayload)}`);
  } catch (error) {
    console.error('Failed to process message:', error);
  }
});
Step 2: Configure the MQTT/JSON IoT Agent

Make sure your IoT Agent is set up to listen for the formatted messages:

  • Set the mqtt.topic configuration to match the target topic pattern you're using (e.g., /json/+/attrs to listen for all devices)
  • Register your LoRa device with the IoT Agent, mapping the sensor fields (like temperature, humidity) to FIWARE entity attributes
  • Ensure the IoT Agent can reach both the Mosquitto broker and Context Broker

For a Docker-based setup, here's an example of key environment variables for the IoT Agent:

IOTA_MQTT_HOST=localhost
IOTA_MQTT_PORT=1883
IOTA_MQTT_TOPIC=/json/+/attrs
IOTA_CB_HOST=context-broker
IOTA_CB_PORT=1026
IOTA_PROVIDER_URL=http://iot-agent:4041
IOTA_DEVICE_REGISTRY_TYPE=mongodb
Step 3: Verify the Data Flow
  1. Start all services in order: Mosquitto → Node.js decryption service → IoT Agent → Context Broker
  2. Trigger a LoRa message from your node
  3. Check the Node.js service logs to confirm decryption and forwarding worked
  4. Query the Context Broker to confirm the data arrived:
curl http://localhost:1026/v2/entities/{your-device-id}
Answering Your Specific Questions

Do I need to publish JSON for the IoT Agent to recognize data?

Absolutely. The MQTT/JSON IoT Agent expects messages to be valid JSON with key-value pairs matching the device's registered attributes. Raw encrypted payloads or non-JSON formats will be ignored.

How to send encrypted payloads as attributes?

If you want to retain the original encrypted payload as a device attribute, just add it to the IoT-ready JSON:

{
  "temperature": 25.3,
  "encryptedPayload": "base64-encrypted-string-here"
}

Just make sure you register the encryptedPayload attribute with the IoT Agent first.

内容的提问来源于stack exchange,提问作者Kostas Tsakos

火山引擎 最新活动