无法将已发布的消息发送给 open62541 中的订阅者

如何解决无法将已发布的消息发送给 open62541 中的订阅者

我正在尝试构建学习 open62541,我正在使用示例示例 Here

我将示例保存为 publish.c 并使用 cmake 选项编译, cmake -DUA_ENABLE_SUBSCRIPTIONS=ON -DUA_ARCHITECTURE=freertosLWIP -DUA_ENABLE_AMALGAMATION=ON -DUA_ENABLE_PUBSUB=ON -DUA_ENABLE_PUBSUB_ETH_UADP=ON ../ 编译示例后 我收到以下错误:

[2021-02-10 21:15:41.328 (UTC+0100)] warn/server AccessControl: Unconfigured AccessControl. Users have all permissions.
[2021-02-10 21:15:41.328 (UTC+0100)] info/server AccessControl: Anonymous login is enabled
[2021-02-10 21:15:41.328 (UTC+0100)] warn/server Username/Password configured,but no encrypting SecurityPolicy. This can leak credentials on the network.
[2021-02-10 21:15:41.328 (UTC+0100)] warn/userland AcceptAll Certificate Verification. Any remote certificate will be accepted.
[2021-02-10 21:15:41.328 (UTC+0100)] info/userland PubSub channel requested
[2021-02-10 21:15:41.328 (UTC+0100)] info/network TCP network layer listening on opc.tcp://gaurav-VirtualBox:4840
[2021-02-10 21:15:41.431 (UTC+0100)] warn/server PubSub Connection sending failed.
[2021-02-10 21:15:41.431 (UTC+0100)] error/server PubSub Publish: Could not send a NetworkMessage
[2021-02-10 21:15:41.528 (UTC+0100)] warn/server PubSub Connection sending failed.
[2021-02-10 21:15:41.528 (UTC+0100)] error/server PubSub Publish: Could not send a NetworkMessage
[2021-02-10 21:15:41.631 (UTC+0100)] warn/server PubSub Connection sending failed.
[2021-02-10 21:15:41.631 (UTC+0100)] error/server PubSub Publish: Could not send a NetworkMessage
**[2021-02-10 21:15:41.729 (UTC+0100)] warn/server PubSub Connection sending failed.
[2021-02-10 21:15:41.729 (UTC+0100)] error/server PubSub Publish: Could not send a NetworkMessage**

我将发布间隔更改为 1 秒。 因此,每 1 秒后,已发布的消息就会发出消息,但不知何故我收到此错误:

**PubSub Connection sending failed. & error/server PubSub Publish: Could not send a NetworkMessage**

连续直到按下 ctrl-c。

谁能帮我在我的电脑上实现这个功能

代码如下

    #include "OPCUA/open62541.h"
    #include "OPCUA/opcua.h"

    UA_NodeId connectionIdent,publishedDataSetIdent,writerGroupIdent,dataSetWriterIdent;
    UA_NodeId connectionIdentifier;
    UA_PublishedDataSetConfig publishedDataSetConfig;
    UA_DataSetWriterConfig dataSetWriterConfig;
    UA_Boolean running = true;



     static void
     addPubSubConnection(UA_Server *server,UA_String *transportProfile,UA_NetworkAddressUrlDataType *networkAddressUrl){
    /* Details about the connection configuration and handling are located
     * in the pubsub connection tutorial */
    UA_PubSubConnectionConfig connectionConfig;
    memset(&connectionConfig,sizeof(connectionConfig));
    connectionConfig.name = UA_STRING("UADP Connection 1");
    connectionConfig.transportProfileUri = *transportProfile;
    connectionConfig.enabled = UA_TRUE;
    UA_Variant_setScalar(&connectionConfig.address,networkAddressUrl,&UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);


    /* Changed to static publisherId from random generation to identify
     * the publisher on Subscriber side */
    connectionConfig.publisherId.numeric = UA_UInt32_random();
    UA_KeyValuePair connectionOptions[3];

        connectionOptions[0].key = UA_QUALIFIEDNAME(0,"ttl");
        UA_UInt32 ttl = 10;
        UA_Variant_setScalar(&connectionOptions[0].value,&ttl,&UA_TYPES[UA_TYPES_UINT32]);

        connectionOptions[1].key = UA_QUALIFIEDNAME(0,"loopback");
        UA_Boolean loopback = UA_FALSE;
        UA_Variant_setScalar(&connectionOptions[1].value,&loopback,&UA_TYPES[UA_TYPES_BOOLEAN]);

        connectionOptions[2].key = UA_QUALIFIEDNAME(0,"reuse");
        UA_Boolean reuse = UA_TRUE;
        UA_Variant_setScalar(&connectionOptions[2].value,&reuse,&UA_TYPES[UA_TYPES_BOOLEAN]);

        connectionConfig.connectionProperties = connectionOptions;
        connectionConfig.connectionPropertiesSize = 3;
    UA_StatusCode retval = UA_Server_addPubSubConnection(server,&connectionConfig,&connectionIdent);
    if (retval == UA_STATUSCODE_GOOD) {
      UA_LOG_INFO(UA_Log_Stdout,UA_LOGCATEGORY_SERVER,"1 --> The PubSub Connection was added successfully!");
      }
    printf("networkAddressUrl.url                                   : %s \n",networkAddressUrl->url.data);
    printf ("Done addPubSubConnection here...\r\n");
}
     static void
     addPublishedDataSet(UA_Server *server) {
    /* The PublishedDataSetConfig contains all necessary public
    * informations for the creation of a new PublishedDataSet */
    UA_PublishedDataSetConfig publishedDataSetConfig;
    memset(&publishedDataSetConfig,sizeof(UA_PublishedDataSetConfig));
    publishedDataSetConfig.publishedDataSetType = UA_PUBSUB_DATASET_PUBLISHEDITEMS;
    publishedDataSetConfig.name = UA_STRING("Demo PDS");
    /* Create new PublishedDataSet based on the PublishedDataSetConfig. */
    UA_AddPublishedDataSetResult result = UA_Server_addPublishedDataSet(server,&publishedDataSetConfig,&publishedDataSetIdent);
    if (result.addResult == UA_STATUSCODE_GOOD){
        UA_LOG_INFO(UA_Log_Stdout,"2 -->The addPublishedDataSet was created successfully!");
    }
        printf ("Done addPublishedDataSet here...\r\n");
}

static void
addDataSetField(UA_Server *server) {
    /* Add a field to the previous created PublishedDataSet */
    UA_NodeId dataSetFieldIdent;
    UA_DataSetFieldConfig dataSetFieldConfig;
    memset(&dataSetFieldConfig,sizeof(UA_DataSetFieldConfig));
    dataSetFieldConfig.dataSetFieldType = UA_PUBSUB_DATASETFIELD_VARIABLE;
    dataSetFieldConfig.field.variable.fieldNameAlias = UA_STRING("Server localtime");
    dataSetFieldConfig.field.variable.promotedField = UA_FALSE;
    dataSetFieldConfig.field.variable.publishParameters.publishedVariable =
    UA_NODEID_NUMERIC(0,UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
    dataSetFieldConfig.field.variable.publishParameters.attributeId = UA_ATTRIBUTEID_VALUE;
    UA_DataSetFieldResult result = UA_Server_addDataSetField(server,&dataSetFieldConfig,&dataSetFieldIdent);
    if (result.result == UA_STATUSCODE_GOOD)
    {
        UA_LOG_INFO(UA_Log_Stdout,"3--> The PubSub UA_Server_addDataSetField successfully!");
    }
    printf ("Done addDataSetField here...\r\n");
}

static void
addWriterGroup(UA_Server *server) {
    /* Now we create a new WriterGroupConfig and add the group to the existing
     * PubSubConnection. */
    UA_WriterGroupConfig writerGroupConfig;
    memset(&writerGroupConfig,sizeof(UA_WriterGroupConfig));
    writerGroupConfig.name = UA_STRING("Demo WriterGroup");
    writerGroupConfig.publishingInterval = 1000;
    writerGroupConfig.enabled = UA_FALSE;
    writerGroupConfig.writerGroupId = 2234;
    writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
    writerGroupConfig.messageSettings.encoding = UA_EXTENSIONOBJECT_DECODED;
    writerGroupConfig.messageSettings.content.decoded.type = &UA_TYPES[UA_TYPES_UADPWRITERGROUPMESSAGEDATATYPE];
    /* The configuration flags for the messages are encapsulated inside the
     * message- and transport settings extension objects. These extension
     * objects are defined by the standard. e.g.
     * UadpWriterGroupMessageDataType */
    UA_UadpWriterGroupMessageDataType *writerGroupMessage  = UA_UadpWriterGroupMessageDataType_new();
    /* Change message settings of writerGroup to send PublisherId,* WriterGroupId in GroupHeader and DataSetWriterId in PayloadHeader
     * of NetworkMessage */
    writerGroupMessage->networkMessageContentMask          = (UA_UadpNetworkMessageContentMask)(UA_UADPNETWORKMESSAGECONTENTMASK_PUBLISHERID |
                                                              (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_GROUPHEADER |
                                                              (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_WRITERGROUPID |
                                                              (UA_UadpNetworkMessageContentMask)UA_UADPNETWORKMESSAGECONTENTMASK_PAYLOADHEADER);
    writerGroupConfig.messageSettings.content.decoded.data = writerGroupMessage;
    UA_StatusCode retval1 = UA_Server_addWriterGroup(server,connectionIdent,&writerGroupConfig,&writerGroupIdent);
    if (retval1 == UA_STATUSCODE_GOOD )
    {
        UA_LOG_INFO(UA_Log_Stdout,"4-->The PubSub Connection UA_Server_addWriterGroup successfully!");
    }
    UA_StatusCode retval2 =  UA_Server_setWriterGroupOperational(server,writerGroupIdent);
    if (retval2 == UA_STATUSCODE_GOOD )
        {
            UA_LOG_INFO(UA_Log_Stdout,"4.1-->The PubSub UA_Server_setWriterGroupOperational executed successfully!");
        }
    UA_UadpWriterGroupMessageDataType_delete(writerGroupMessage);

    printf("Done addWriterGroup here...\r\n");
}

static void
addDataSetWriter(UA_Server *server) {
    /* We need now a DataSetWriter within the WriterGroup. This means we must
     * create a new DataSetWriterConfig and add call the addWriterGroup function. */
    UA_NodeId dataSetWriterIdent;
    UA_DataSetWriterConfig dataSetWriterConfig;
    memset(&dataSetWriterConfig,sizeof(UA_DataSetWriterConfig));
    dataSetWriterConfig.name = UA_STRING("Demo DataSetWriter");
    dataSetWriterConfig.dataSetWriterId = 62541;
    dataSetWriterConfig.keyFrameCount = 10;
    UA_StatusCode retval =  UA_Server_addDataSetWriter(server,&dataSetWriterConfig,&dataSetWriterIdent);
    if (retval == UA_STATUSCODE_GOOD)
    {
        UA_LOG_INFO(UA_Log_Stdout,"5-->The PubSub addDataSetWriter executed successfully!");
    }
    printf("Done addDataSetWriter here...\r\n");
}


    static int opcua_call (UA_String *transportProfile,UA_NetworkAddressUrlDataType *networkAddressUrl)
{
    UA_Boolean running = true;
    /* Create the Server */
    UA_Server *server = UA_Server_new();
    if (server != 0)
        printf("Server Created Successfully...\r\n");
    else
        printf("Failed to create Server...\r\n");

    UA_ServerConfig *config = UA_Server_getConfig(server);
    UA_ServerConfig_setDefault(config);
        /* Server is created now */

    /* Add the PubSubTransportLayer implementation to the server config.
     * The PubSubTransportLayer is a factory to create new connections
     * on runtime. The UA_PubSubTransportLayer is used for all kinds of
     * concrete connections e.g. UDP,MQTT,AMQP...
     */
    UA_String hostname;
    hostname = UA_STRING("opc.udp://224.0.0.21");
    UA_ServerConfig_setCustomHostname(UA_Server_getConfig(server),hostname);


    wiced_hostname_t whn;
    wiced_result_t wres;
    memset(&whn,sizeof(whn));
    wiced_network_set_hostname("myServer");
    wres = wiced_network_get_hostname( &whn );
    printf ("wiced_network_get_hostname returned %d\n",wres);
    printf ("wiced_network_get_hostname: %s\n",whn.value );

/* Change the host name */
//            UA_String hostname;
//            UA_String_init(&hostname);
//            hostname.length = 8;
//            hostname.data =   "myServer";// "opc.udp://224.0.0.23:4841/"; //224.0.0.22:4840
//            printf ("Hostname is set with %s...\r\n",hostname.data);
//            UA_ServerConfig_setCustomHostname(UA_Server_getConfig(server),hostname);


    config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_calloc(
            2,sizeof(UA_PubSubTransportLayer));

    config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
    config->pubsubTransportLayersSize++;

       UA_PubSubConnectionConfig connectionConfig;
       memset(&connectionConfig,sizeof(connectionConfig));
       connectionConfig.name = UA_STRING("UDP-UADP Connection 1");
       connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
       connectionConfig.enabled = UA_TRUE;


    addPubSubConnection(server,transportProfile,networkAddressUrl);
    addPublishedDataSet(server);
    addDataSetField(server);
    addWriterGroup(server);
    addDataSetWriter(server);


    UA_Server_run_startup(server);
    if (!config->pubsubTransportLayers) {
        UA_Server_delete(server);
        return -1;
        printf("Error ! \r\n");
    } else
        printf("Success Adding the Transport Layer... \r\n");

   // UA_StatusCode retval = UA_Server_run(server,&running);

    UA_Server_delete(server);

}

int opcua_pub_thread (void *arg)
{
    /* Configure the transport profile and Network Address*/
    UA_String transportProfile =
                        UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
    UA_NetworkAddressUrlDataType networkAddressUrl =
                        {UA_STRING_NULL,UA_STRING("opc.udp://224.0.0.22:4840/")};

    networkAddressUrl.networkInterface = UA_STRING("udp");
    networkAddressUrl.url = UA_STRING("opc.udp://224.0.0.22");
    /* Start the pubsub procedure*/
    return opcua_call(&transportProfile,&networkAddressUrl);
}

void opcua_pub_init(void)
{
     printf("OPCUA Thread Created...\r\n");
    /* Create the opcua sttarting point thread */
    sys_thread_new("OPCUA Start",opcua_pub_thread,NULL,20000,WICED_DEFAULT_LIBRARY_PRIORITY);

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)> insert overwrite table dwd_trade_cart_add_inc > select data.id, > data.user_id, > data.course_id, > date_format(
错误1 hive (edu)> insert into huanhuan values(1,'haoge'); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive> show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 <configuration> <property> <name>yarn.nodemanager.res