{"id":1469,"date":"2024-11-04T18:03:44","date_gmt":"2024-11-04T16:03:44","guid":{"rendered":"https:\/\/www.rocworks.at\/wordpress\/?p=1469"},"modified":"2024-11-04T20:16:45","modified_gmt":"2024-11-04T18:16:45","slug":"data-from-opc-ua-mqtt-sparkplugb-to-snowflake-database-with-frankenstein-automation-gatewayy","status":"publish","type":"post","link":"https:\/\/www.rocworks.at\/wordpress\/?p=1469","title":{"rendered":"From OPC UA &amp; MQTT\/SparkplugB to Snowflake with Frankenstein Automation-Gateway"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In that example we take SparkplugB messages from a MQTT Broker, decode it and write it to Snowflake. And we take some OPC UA nodes and write it also to the same table.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a database and a schema for your destination table.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE OR REPLACE SCHEMA scada;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create the table for the incoming data:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE IF NOT EXISTS scada.gateway (\n  system character varying(1000) NOT NULL,\n  address character varying(1000) NOT NULL,\n  sourcetime timestamp with time zone NOT NULL,\n  servertime timestamp with time zone NOT NULL,\n  numericvalue float,\n  stringvalue text,\n  status character varying(30),\n  CONSTRAINT gateway_pk PRIMARY KEY (system, address, sourcetime)\n  );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Generate a private key:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&gt; openssl genrsa 2048 | openssl pkcs8 -topk8 -v2 des3 -inform PEM -out snowflake.p8 -nocrypt<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Generate a public key:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&gt; openssl rsa -in snowflake.p8 -pubout -out snowflake.pub<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Set the public key to your user:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&gt; ALTER USER xxxxxx SET RSA_PUBLIC_KEY=&#8217;MIIBIjANBgkqh&#8230;&#8217;; <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Replace MIIBIjANBgkqh&#8230; with your public key from the snowflake.pub file (without &#8212;&#8211;BEGIN PRIVATE KEY&#8212;&#8211; and without &#8212;&#8211;END PRIVATE KEY&#8212;&#8211;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Details about creating keys can be found <a href=\"https:\/\/docs.snowflake.com\/en\/user-guide\/key-pair-auth\">here<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Prepare the Gateway<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add a Snowflake logger section to the gateways config.yml. In that example we take SparkplugB messages from a MQTT Broker, decode it and write it to Snowflake. And we take some OPC UA nodes and write it also to the same table.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Drivers:\n  OpcUa:\n    - Id: \"test1\"\n      Enabled: true\n      LogLevel: INFO\n      EndpointUrl: \"opc.tcp:\/\/test.monstermq.com:4840\/server\"\n      UpdateEndpointUrl: true\n      SecurityPolicy: None\n\n  Mqtt:\n    - Id: \"test2\"\n      Enabled: true\n      LogLevel: INFO\n      Host: test.monstermq.com\n      Port: 1883\n      Format: SparkplugB\n\nLoggers:\n  Snowflake:\n    - Id: \"snowflake\"\n      Enabled: true\n      LogLevel: INFO\n      PrivateKeyFile: \"snowflake.p8\"\n      Account: xx00000\n      Url: https:\/\/xx00000.eu-central-1.snowflakecomputing.com:443\n      User: xxxxxx\n      Role: accountadmin\n      Scheme: https\n      Port: 443\n      Database: SCADA\n      Schema: SCADA\n      Table: GATEWAY\n      Logging:\n        - Topic: opc\/test1\/path\/Objects\/Mqtt\/#\n        - Topic: mqtt\/test2\/path\/spBv1.0\/vogler\/DDATA\/+\/#<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The Url you can find in the Snowflake web console by going to Admin\/Accounts and then hover over the &#8220;Locator&#8221; column.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.rocworks.at\/wordpress\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-04-at-19.14.18-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"391\" src=\"https:\/\/www.rocworks.at\/wordpress\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-04-at-19.14.18-1-1024x391.png\" alt=\"\" class=\"wp-image-1480\" srcset=\"https:\/\/www.rocworks.at\/wordpress\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-04-at-19.14.18-1-1024x391.png 1024w, https:\/\/www.rocworks.at\/wordpress\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-04-at-19.14.18-1-300x114.png 300w, https:\/\/www.rocworks.at\/wordpress\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-04-at-19.14.18-1-768x293.png 768w, https:\/\/www.rocworks.at\/wordpress\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-04-at-19.14.18-1-1536x586.png 1536w, https:\/\/www.rocworks.at\/wordpress\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-04-at-19.14.18-1-2048x781.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Start the Gateway<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>> git checkout snowflake\n> cd automation-gateway\/source\/app  \n> ..\/gradlew run\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><br>Note: Using gradlew to start the gateway is not recommended for production. Instead, consider using a Docker image or the files from the build\/distribution for a more robust setup..<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.rocworks.at\/wordpress\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-04-at-16.18.06.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"362\" src=\"https:\/\/www.rocworks.at\/wordpress\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-04-at-16.18.06-1024x362.png\" alt=\"\" class=\"wp-image-1470\" srcset=\"https:\/\/www.rocworks.at\/wordpress\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-04-at-16.18.06-1024x362.png 1024w, https:\/\/www.rocworks.at\/wordpress\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-04-at-16.18.06-300x106.png 300w, https:\/\/www.rocworks.at\/wordpress\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-04-at-16.18.06-768x271.png 768w, https:\/\/www.rocworks.at\/wordpress\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-04-at-16.18.06-1536x543.png 1536w, https:\/\/www.rocworks.at\/wordpress\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-04-at-16.18.06-2048x724.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>In that example we take SparkplugB messages from a MQTT Broker, decode it and write it to Snowflake. And we take some OPC UA nodes and write it also to the same table. Create a database and a schema for &hellip; <a href=\"https:\/\/www.rocworks.at\/wordpress\/?p=1469\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1469","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"_links":{"self":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1469","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1469"}],"version-history":[{"count":8,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1469\/revisions"}],"predecessor-version":[{"id":1481,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1469\/revisions\/1481"}],"wp:attachment":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}