How to use a c# script to process input XML/MQTT message

Forum Home Forums Communicating with Devices How to use a c# script to process input XML/MQTT message

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #13278
    reha
    Participant

    Hi,
    Im trying to understand.. how to introduce/install a custom (mine) c# to Rapid Scada server? how can I call that script? purpose is the process xml formatted MQTT message to extract certain data field. Will be so happy, if you can share a link/sample or guide/tutorial. many thanks in advance, reha

    #13295
    Mikhail
    Moderator

    Hi,

    1. Add your scripts into the Scripts (v6) or Formulas (v5) table.
    2. Write a DLL in C# using the examples from GitHub.
    3. The MQTT driver support JavaScript.

    Please specify your question.

    #13348
    reha
    Participant

    Hi Michael,
    thank you so much for the guidance.. The thing that I wish to achieve..
    Environment: I use MQTT to collect the sensor data. currently 2 sensors.. Temp & Hum
    Issue: the received MQTT message is in JSON formatted and contains 2 values (temperature & humidity)
    Target: process the MQTT message to extract values and assign to sensors

    I thought, I can use scripts to process that MQTT message and pass to individual sensors.. But I really dont know “where & how to” start..

    by the way, is there any documentation that I can have a look to understand scripts and the way it works. many thanks in advance, reha

    #13353
    Mikhail
    Moderator

    Hi,
    MQTT driver supports simple JavaScripts.
    JS file should be located in the Communicator – Configuration files section.
    See example1 and example2.
    Provide screenshots of your configuration for more details.

    #13354
    Mikhail
    Moderator

    You need to create a communication line in Communicator. Then choose MQTT Client as communication channel type. Then create a device under the line, open its properties and specify subscriptions.

    #13355
    Mikhail
    Moderator

    is there any documentation that I can have a look to understand scripts and the way it works

    Currently, only the forum. The docs should be created, of course.

    #13359
    reha
    Participant

    Hi Michael
    thank you so much for the detailed explain. As now, my app working properly via MQTT, when MQTT message contains only 1 data value (nothing else) . Now it is the phase to include complex MQTT messages as you mentioned above. To respond your request, current config

    here is my working application: http://78.189.224.253:10008/ (default credentials)

    comm line definitions
    line definitions
    device settings
    mQTT topic (just single, simple value as now)

    #13360
    reha
    Participant

    Now, I will try to receive more complicated MQTT message in XML format and extract these value , then pass each value as single/simple value to channel.. many thanks for the guidance and helps.

    #13370
    Mikhail
    Moderator

    Hi,
    If you need to use JS to extract values from JSON, set JavaScript enabled = Yes (in device properties). Create a js file, put it in the Communicator configuration. Specify the file name in the JavaScript file name property.

    #13371
    Mikhail
    Moderator

    Also you need to specify subitems.

    #13372
    Mikhail
    Moderator
    #13583
    joii
    Participant

    Hello,Mikhail
    Can I take a look at how to manipulate and assign attributes in JavaScript,
    And how to display the collected real-time data of JSON on the view

    #13585
    Mikhail
    Moderator

    Hello,
    Please check this post.
    Values extracted from JSON are tags of Communicator. They bound to channels and displayed in a common way.

    #13586
    Mikhail
    Moderator

    I suggest, first, to configure MQTT driver for reading simple numeric values. When it’s done, try using JSON. If you provide screenshots of the configuration and result, I can help more detailed.

    #13589
    Mikhail
    Moderator
Viewing 15 posts - 1 through 15 (of 20 total)
  • You must be logged in to reply to this topic.