Lua Script in data to server section

I want to upload my plc tags coming via modbus tcp to mqtt by data to server section i also want to add some offset in it so i want to use lua script

but by using following script i am not getting data uploaded on mqtt

In data configuration:
Type: Modbus
Format type: Lua Script
script is: local tag1 = tonumber(data[“Temp”])
local sum = tag1 + 5

In collection configuration:
again
Format type: Lua Script
Script is: { “sum”: “%=return sum%” }

but no data is uploaded to by mqtt platform

Hello,

Could you clarify what the tag1 variable represents? It seems the issue might be in your Lua script’s syntax. Lua uses double square brackets ["key"] instead of curly quotes “key”, so, instead of data[“Temp”], try using data["Temp"] and, in sum’s returning script, { "sum": %=sum% }.

Additionally, is the Modbus data being received on your MQTT client in other JSON or custom formats?

Best regards,

Thanks Martynas for reaching out

  1. I have defined tag1 variable to store the value of Temp variable coming from modbus device.
  2. I have tried to replace double quotes with 2 single quotes as per your recommendation but still data is not uploaded
  3. yes data is uploaded to MQTT client in JSON and Custom formats.

Any update for this because this steps aren’t working.