I'm using IoT Edge to connect Modbus devices to IoT Hub and I'm trying to implement protocol + identity translation modules.
I started with the example here
I have two modules:
ModbusClient, for the protocol translation, in C#
IdentityTranslation, in NodeJS
Here is how routes are defined in the deployment file:
"ModbusClientToIdentityTranslation": "FROM /messages/modules/ModbusClient/outputs/modbusOutput INTO BrokeredEndpoint(\"/modules/IdentityTranslation/inputs/input1\")",
"IdentityTranslationToIoTHub": "FROM /messages/modules/IdentityTranslation/outputs/* INTO $upstream"
I would like to add a property with the deviceId value in the message transformed by the ModbusClient and read this property in the IdentityTranslation module.
Here are the snippets of the code in the two modules:
- ModbusClient
Message message = new Message(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(out_message))); message.Properties.Add("content-type", "application/edge-modbus-json"); message.Properties.Add("deviceId", deviceId); Console.WriteLine("deviceId " + message.Properties["deviceId"]); await ioTHubModuleClient.SendEventAsync("modbusOutput", message);
- IdentityTranslation
moduleClient.on('inputMessage', function (inputName, msg) { console.log("new message received", msg); if (modbusClient) { // Identity Translation configured, wrap message for IoT device const message = msg.getBytes().toString('utf8'); const sensorMsg = new Message(message); console.log("sensorMsg ", sensorMsg); if(sensorMsg.Keys.Contains("deviceId")){ console.log("deviceId ", sensorMsg.Properties["deviceId"]); } modbusClient.sendEvent(sensorMsg); }
When the message arrives at the IdentityTranslation module, Properties are empty and I cannot get the deviceId value.
This is the content of the recevived message
new message received Message { data: <Buffer 7b 22 50 75 62 6c 69 73 68 54 69 6d 65 73 74 61 6d 70 22 3a 22 32 30 32 33 2d 30 36 2d 32 37 20 31 34 3a 34 39 3a 33 30 22 2c 22 43 6f 6e 74 65 6e 74 ... >, properties: Properties { propertyList: [ [Object], [Object], [Object] ] }, messageId: '', to: '', expiryTimeUtc: undefined, lockToken: '', correlationId: '', userId: '', contentEncoding: 'utf-8', contentType: 'application/json' }
Can you please help me to undertsand where I'm wrong?
Thanks a lot in advance