i4connected Knowledgebase

Using MQTT Adapter to connect Ewon Flexy

Abstract

Open this article and learn how to use the MQTT Adapter to connect an Ewon Flexy device to the i4connected environment.

The Ewon Flexy is an advanced internet data gateway that allows Machine Builders to monitor and collect vital KPIs for analysis and predictive maintenance from multiple types of PLCs. Using an MQTT Adapter the Ewon Flexy device can be connected to the i4connected platform through an MQTT Broker.

Setup of BASIC IDE in Ewon Flexy

The MQTT functionality of the Ewon Flexy devices is available via BASIC and Java programming environment. As it is easier to access the BASIC programming environment, please follow the below described steps:

  1. The first step in preparing the Ewon Flexy devices is uploading the CA certificates.

    Tip

    Depending on the MQTT Broker Certificate type:

    If you are using a self-signed certificate on the MQTT Broker, the CA certificate needs to be uploaded to the Ewon Flexy, using an FTP program (e.g. FileZilla). The CA certificate should be uploaded in the usr directory via a PEM file format.

    On the other hand, if your MQTT Broker uses an official CA certificate, make sure that the name of the MQTT Broker is explicitly assigned in the Alternate Names of the certificate. Wildcard certificates such as *.webfactory-i4.de will NOT work.

  2. Next, you can proceed with installing the BASIC Program on the Ewon Flexy, as follows:

    1. Go to the BASIC IDE menu entry, under the Setup category

      BASIC_IDE_entry.jpg
    2. Upload the SendMQTT.bas file into the Init Section by clicking the Import toolbar button. The SendMQTT.bas file can be download here.

      Import_file.jpg

      Warning

      The upload will be possible only if the script execution is NOT in status Running. To stop the scrip execution, toggle the Script execution button.

      Stop_script.jpg
    3. The Init Section will display the uploaded script. The CONFIG area with the variables is displayed at the top of the script.

      Init_section_script.jpg
    4. Start configuring the variables to fit your needs. To support you, we prepared a configuration example and some explanations:

      Tip

      //############### CONFIG ###############
      ProjectNumber$="Project1"
      MQTTBrokerURL$ = "demo.webfactory-i4.de"
      MQTTPort$ = "1883"
      TLSVersion$ = "tlsv1.2"
      CAFile$ = "/usr/certs/mqtt-ca-root.pem"
      ClientID$ = "webfactory_Ewon_001"
      Username$ = "webfactory"
      Password$ = "Password!"
      TopicToPublishBase$ = "webfactory/" + ProjectNumber$
      Timer1_Group$="60sec"
      Timer2_Group$="15min"
      Timer3_Group$=""
      Timer4_Group$=""
      OnChange_Group$="Alarms"
      Write_Group$="Schreiben"
      Time1_Time%=60
      Time2_Time%=900
      Time3_Time%=900
      Time4_Time%=900
      //############### END CONFIG ###############

      As visible in the above example, the topic tree is started using the variables TopicToPublishBase$ and ProjectNumber$ (in this example: webfactory/Project1).

      The variables MQTTBrokerURL$ and MQTTPort$ are used to configure the MQTT Broker, whereas the Username$ and Password$ can be extracted from the broker. It is mandatory that the user has permission to write to the topic.

      The ClientID$ needs to be unique for each Ewon Flexy device.

      Further on, adapt the CAFile$ to correspond to the filename used at step 1, or simply delete or comment the line out by typing // at the beginning of the line.

      As we shall see in the upcoming steps, the page names are used to group the tags of the Ewon Flexy, as follows:

      • Timer1_Group$ - will send data to the JSON format within a 60 seconds interval

      • Timer2_Group$ - will send data to the JSON format within a 15 minutes interval

      • OnChange_Group$ - will send data to the JSON format each time the value gets changes

      • Time1_Time% to Time4_Time% - define the times to send the tags within the defined interval, seconds wise.

      For all these pages the topic of the MQTT message is extended by the page name. E.g. in the example above the tags of the page "60sec" are sent to the topic webfactory/Project1/60sec.

      The JSON format is defined like this:

      {
      "Signal1": "85.50",
      "Signal2": "10.29",
      "Signal3": "4.80",
      "Signal4": "98.04",
      "Signal5": "91.77",
      "Timestamp": "2019-12-12T16:28:29"
      }

      The Write_Group$ can be written via publishing a MQTT message, in all the tags in the page. These are transmitted via RAW format, which expects a numerical value (e.g. 10.25). The topic is extended with the page name and the tag name.

      For the Write1 tag in the Write page the following topic will be formed: webfactory/Project1/Write/Write1.

    5. As soon as all the needed variables have been changed, toggle the script execution to RUNNING. If the execution test has passed enable the Autorun option.

      Autorun.jpg
  3. Further on, you need to assign the tags to pages. The tags are managed in the menu Tags under the Values entry.

    Values_menu_entry.jpg

    Note

    The tags can be read via the different IO servers or internally (MEM). The exact configuration depends on the used IO server.

    Please consider the Ewon Flexy documentation, because this part if out of the scope of this tutorial.

  4. In order to enter in edit mode, toggle the MODE button to change the state from VIEW to SETUP.

    Values_setup.jpg
  5. By default, the pages Default and System are available. To add further pages, click on the Plus button.

    Add_new_pages.jpg
  6. Proceed with adding the pages as described at step 2d .

    Tip

    Proposal: add the pages "60sec", "15min", "OnChange" and "Write".

    New_pages.jpg
  7. Using the Add toolbar button new Tags can be added.

    Add_tags.jpg
  8. Further on, by selecting a Tag, the options Edit and Delete are enabled.

    Edit_and_Delete_tags.jpg
  9. Click the Edit button to open the Tag configuration panel and proceed with the Tag name assignment, to the corresponding Page.

    Edit_tag.jpg
  10. To preserve the changes click the Update Tag button at the bottom of the Tag configuration panel.

    Update_tag_button.jpg
Setup of i4connected

After the Ewon Flexy have been organised we need to proceed with the i4connected setup. At level of i4connected each MQTT Broker needs one MQTT Adapter for the JSON-Format and one for the RAW-format.

The MQTT JSON-format Adapter
  1. Go to the i4connected Admin page and click on the Devices tile.

  2. In the Device List panel click on the Add toolbar button.

    Add_device_button.jpg
  3. In the Select Device Type panel click on the MQTT tile.

    MQTT_Device_type.jpg
  4. In The Add Device panel start filling in the Device info:

    JSON_Device.jpg
    1. Set the Device Name

    2. Set the Device Site, Area and Organizational Unit.

    3. Add the Topic extracted from the Ewon Flexy device (for the current example we shall set the topic to webfactory/Project1.

    4. Click on the Select Adapter field to define the JSON format MQTT Adapter:

      1. In the Select MQTT Adapter click on the Add toolbar button.

      2. In the Add MQTT Adapter panel start filling in the all the required information and make sure that the Adapter is set to JSON format.

        Add_JSON_Adapter.jpg

        Tip

        More information about the MQTT Adapter can be found in this article.

      3. Click on the Save button to preserve all the changes made.

    5. After saving the new MQTT JSON-format Adapter, it will be visible in the Select MQTT Adapter panel.

    6. Select the new MQTT Adapter and save the Device.

  5. The new MQTT Device with JSON format Adapter is saved and will be opened in detailed view mode.

  6. Click on the Signals tile to proceed with the MQTT Device configuration.

    Signals_for_JSON_Adapter.jpg
  7. The Signal List panel is opened empty. At this step our goal is to add new Signals to the Device and connect them to the Ewon Flexy tags.

    1. Type in the Signal Name.

      Tip

      The i4connected Signal names do not need to be the same as in Ewon Flexy. Any naming can be defined here.

    2. Go to the MQTT Settings and fill in the settings extracting them from Ewon Flexy, as explained at step 2d.

      MQTT_settings.jpg

      Tip

      For more details about the MQTT Signal settings please also visit this article.

      1. Assign the Signal Type as needed.

      2. Topic to the page of the tag in the Ewon Flexy (e.g. 60sec)

      3. Value should be the name of the tag in the Ewon Flexy (e.g. Signal1)

        Value_JSON.jpg
      4. Timestamp should be the Timestamp in the Ewon Flexy (e.g. Timestamp)

        Timestamp_JSON.jpg
    3. Save the Signal and repeat the same steps for all the Ewon Flexy tags, except for the ones in the page Write or the name of the page you set for Write_Group$.

  8. After adding all the needed Signals you can close the MQTT JSON-format Device details panel and proceed with the next steps, described below.

The MQTT RAW-format Adapter

Tip

The RAW format is only necessary if you want to write data back into the Ewon Flexy tags.

  1. Go to the i4connected Admin page and click on the Devices tile.

  2. In the Device List panel click on the Add toolbar button.

    Add_Device.jpg
  3. In the Select Device Type panel click on the MQTT tile.

    MQTT_Device_type.jpg
  4. In The Add Device panel start filling in the Device info:

    RAW_Device.jpg
    1. Set the Device Name

    2. Set the Device Site, Area and Organizational Unit.

    3. Add the Topic extracted from the Ewon Flexy device (for the current example we shall set the topic to webfactory/Project1/Write.

    4. Click on the Select Adapter field to define the JSON format MQTT Adapter:

      1. In the Select MQTT Adapter click on the Add toolbar button.

      2. In the Add MQTT Adapter panel start filling in the all the required information and make sure the Adapter is set to RAW format.

        MQTT_Adpter_Raw_format.jpg

        Tip

        More information about the MQTT Adapter can be found in this article.

      3. Click on the Save button to preserve all the changes made.

    5. After saving the new MQTT RAW-format Adapter, it will be visible in the Select MQTT Adapter panel.

    6. Select the new MQTT Adapter and save the Device.

  5. The new MQTT Device with RAW format Adapter is saved and will be opened in detailed view mode.

  6. Click on the Signals tile to proceed with the MQTT Device configuration.

    Device_with_RAW_detailed_view.jpg
  7. The Signal List panel is opened empty. At this step our goal is to add new Signals to the Device and connect them to the Ewon Flexy tags.

    1. Type in the Signal Name.

      Tip

      The i4connected Signal names do not need to be the same as in Ewon Flexy. Any naming can be defined here.

    2. Go to the MQTT Settings and fill in the settings extracting them from Ewon Flexy, as explained at step 2d.

      Write1_topic.jpg

      Tip

      For more details about the MQTT Signal settings please also visit this article.

      1. Assign the Signal type as needed.

      2. Topic to the name of the tag in the Ewon Flexy (e.g. Write1)

    3. Save the Signal and repeat the same steps for all the remaining Ewon Flexy tags in the Write_Group$ page.

  8. After adding all the needed Signals you can close the MQTT RAW-format Device details panel.

    Important

    In order to write Signal values a SCADA page should be integrated in i4connected.