int main(int argc, char **argv) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); UA_Server *server = UA_Server_new(); UA_ServerConfig *config = UA_Server_getConfig(server); UA_ServerConfig_setDefault(config); config->customDataTypes = &customTypesArray; UA_StatusCode retval; /* create nodes from nodeset */ if(namespace_testnodeset_generated(server) != UA_STATUSCODE_GOOD) { UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Could not add the example nodeset. " "Check previous output for any error."); retval = UA_STATUSCODE_BADUNEXPECTEDERROR; } else { UA_Variant out; UA_Variant_init(&out); UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 10002), &out); UA_Point *p = (UA_Point *)out.data; printf("point 2d x: %f y: %f \n", p->x, p->y); retval = UA_Server_run(server, &running); } UA_Server_delete(server); return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE; }
static void setup(void) { running = true; server = UA_Server_new(); UA_ServerConfig_setDefault(UA_Server_getConfig(server)); UA_Server_run_startup(server); THREAD_CREATE(server_thread, serverloop); }
int main(int argc, char** argv) { signal(SIGINT, stopHandler); /* catches ctrl-c */ UA_ServerConfig config = UA_ServerConfig_standard; UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); config.networkLayers = &nl; config.networkLayersSize = 1; UA_Server *server = UA_Server_new(config); /* add a variable node to the address space */ UA_Int32 myInteger = 42; UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer"); UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer"); UA_DataSource dateDataSource = (UA_DataSource) { .handle = &myInteger, .read = readInteger, .write = writeInteger}; UA_VariableAttributes attr; UA_VariableAttributes_init(&attr); attr.description = UA_LOCALIZEDTEXT("en_US","the answer"); attr.displayName = UA_LOCALIZEDTEXT("en_US","the answer"); UA_Server_addDataSourceVariableNode(server, myIntegerNodeId, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), myIntegerName, UA_NODEID_NULL, attr, dateDataSource, NULL); UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); nl.deleteMembers(&nl); return (int)retval; }
static int run(UA_String *transportProfile, UA_NetworkAddressUrlDataType *networkAddressUrl) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); UA_Server *server = UA_Server_new(); UA_ServerConfig *config = UA_Server_getConfig(server); UA_ServerConfig_setMinimal(config, 4801, NULL); /* Details about the PubSubTransportLayer can be found inside the * tutorial_pubsub_connection */ config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_calloc(2, sizeof(UA_PubSubTransportLayer)); if(!config->pubsubTransportLayers) { UA_Server_delete(server); return EXIT_FAILURE; } config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP(); config->pubsubTransportLayersSize++; #ifdef UA_ENABLE_PUBSUB_ETH_UADP config->pubsubTransportLayers[1] = UA_PubSubTransportLayerEthernet(); config->pubsubTransportLayersSize++; #endif UA_PubSubConnectionConfig connectionConfig; memset(&connectionConfig, 0, 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]); UA_NodeId connectionIdent; UA_StatusCode retval = UA_Server_addPubSubConnection(server, &connectionConfig, &connectionIdent); if(retval == UA_STATUSCODE_GOOD) UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "The PubSub Connection was created successfully!"); /* The following lines register the listening on the configured multicast * address and configure a repeated job, which is used to handle received * messages. */ UA_PubSubConnection *connection = UA_PubSubConnection_findConnectionbyId(server, connectionIdent); if(connection != NULL) { UA_StatusCode rv = connection->channel->regist(connection->channel, NULL, NULL); if (rv == UA_STATUSCODE_GOOD) { UA_UInt64 subscriptionCallbackId; UA_Server_addRepeatedCallback(server, (UA_ServerCallback)subscriptionPollingCallback, connection, 100, &subscriptionCallbackId); } else { UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "register channel failed: %s!", UA_StatusCode_name(rv)); } } retval |= UA_Server_run(server, &running); UA_Server_delete(server); return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;; }
static void setup(void) { running = true; config = UA_ServerConfig_new_default(); server = UA_Server_new(config); UA_Server_run_startup(server); THREAD_CREATE(server_thread, serverloop); }
static void setup_lds(void) { // start LDS server running_lds = UA_Boolean_new(); *running_lds = true; config_lds = UA_ServerConfig_new_default(); config_lds->applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER; UA_String_deleteMembers(&config_lds->applicationDescription.applicationUri); config_lds->applicationDescription.applicationUri = UA_STRING_ALLOC("urn:open62541.test.local_discovery_server"); UA_LocalizedText_deleteMembers(&config_lds->applicationDescription.applicationName); config_lds->applicationDescription.applicationName = UA_LOCALIZEDTEXT_ALLOC("en", "LDS Server"); config_lds->mdnsServerName = UA_String_fromChars("LDS_test"); config_lds->serverCapabilitiesSize = 1; UA_String *caps = UA_String_new(); *caps = UA_String_fromChars("LDS"); config_lds->serverCapabilities = caps; config_lds->discoveryCleanupTimeout = registerTimeout; server_lds = UA_Server_new(config_lds); UA_Server_run_startup(server_lds); pthread_create(&server_thread_lds, NULL, serverloop_lds, NULL); // wait until LDS started UA_sleep(1000); sleep(1); }
int main(int argc, char** argv) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); UA_ServerConfig config = UA_ServerConfig_standard; UA_ServerNetworkLayer nl; nl = UA_ServerNetworkLayerUDP(UA_ConnectionConfig_standard, 16664); config.networkLayers = &nl; config.networkLayersSize = 1; UA_Server *server = UA_Server_new(config); // add a variable node to the adresspace UA_VariableAttributes attr; UA_VariableAttributes_init(&attr); UA_Int32 myInteger = 42; UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]); attr.description = UA_LOCALIZEDTEXT("en_US","the answer"); attr.displayName = UA_LOCALIZEDTEXT("en_US","the answer"); UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer"); UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer"); UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER); UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES); UA_Server_addVariableNode(server, myIntegerNodeId, parentNodeId, parentReferenceNodeId, myIntegerName, UA_NODEID_NULL, attr, NULL, NULL); UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); return (int) retval; }
static void setup(void) { running = UA_Boolean_new(); *running = true; config = UA_ServerConfig_new_default(); server = UA_Server_new(config); UA_Server_run_startup(server); pthread_create(&server_thread, NULL, serverloop, NULL); }
static void setup(void) { config = UA_ServerConfig_new_default(); UA_GlobalNodeLifecycle lifecycle; lifecycle.constructor = globalInstantiationMethod; lifecycle.destructor = NULL; config->nodeLifecycle = lifecycle; server = UA_Server_new(config); }
END_TEST START_TEST(Server_new_shutdown_delete) { UA_Server *pServer = UA_Server_new(); configure_lds_server(pServer); UA_StatusCode retval = UA_Server_run_shutdown(pServer); ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); UA_Server_delete(pServer); }
static void setup(void) { running = true; config = UA_ServerConfig_new_default(); server = UA_Server_new(config); UA_Server_run_startup(server); THREAD_CREATE(server_thread, serverloop); /* Waiting server is up */ UA_comboSleep(1000); }
int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); UA_ServerConfig *config = UA_ServerConfig_new_minimal(4801, NULL); /* Details about the PubSubTransportLayer can be found inside the * tutorial_pubsub_connection */ config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_malloc(sizeof(UA_PubSubTransportLayer)); if (!config->pubsubTransportLayers) { UA_ServerConfig_delete(config); return -1; } config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP(); config->pubsubTransportLayersSize++; UA_Server *server = UA_Server_new(config); UA_PubSubConnectionConfig connectionConfig; memset(&connectionConfig, 0, 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; UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL , UA_STRING("opc.udp://224.0.0.22:4840/")}; UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl, &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]); UA_NodeId connectionIdent; UA_StatusCode retval = UA_Server_addPubSubConnection(server, &connectionConfig, &connectionIdent); if(retval == UA_STATUSCODE_GOOD) UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "The PubSub Connection was created successfully!"); /* The following lines register the listening on the configured multicast * address and configure a repeated job, which is used to handle received * messages. */ UA_PubSubConnection *connection = UA_PubSubConnection_findConnectionbyId(server, connectionIdent); if(connection != NULL) { UA_StatusCode rv = connection->channel->regist(connection->channel, NULL); if (rv == UA_STATUSCODE_GOOD) { UA_UInt64 subscriptionCallbackId; UA_Server_addRepeatedCallback(server, (UA_ServerCallback)subscriptionPollingCallback, connection, 100, &subscriptionCallbackId); } else { UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "register channel failed: %s!", UA_StatusCode_name(rv)); } } retval |= UA_Server_run(server, &running); UA_Server_delete(server); UA_ServerConfig_delete(config); return (int)retval; }
//#######################################MAIN####################################### int main(int argc, char** argv) { signal(SIGINT, stopHandler); /* catches ctrl-c */ if (gpioInitialise() < 0) { fprintf(stderr, "pigpio initialisation failed\n"); return 1; } gpioSetMode(17, PI_OUTPUT); gpioSetMode(22, PI_INPUT); gpioSetMode(24, PI_OUTPUT); UA_ServerConfig config = UA_ServerConfig_standard; UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); config.networkLayers = &nl; config.networkLayersSize = 1; UA_Server *server = UA_Server_new(config); /* add a variable node to the address space */ UA_Int32 myIntegerB = 32; UA_NodeId myIntegerBNodeId = UA_NODEID_STRING(1, "button"); UA_QualifiedName myIntegerBName = UA_QUALIFIEDNAME(1, "button"); UA_DataSource dateDataSource = (UA_DataSource) { .handle = &myIntegerB, .read = readIntegerB, .write = writeIntegerB}; UA_VariableAttributes attr; UA_VariableAttributes_init(&attr); attr.description = UA_LOCALIZEDTEXT("en_US","button_on_off"); attr.displayName = UA_LOCALIZEDTEXT("en_US","button"); UA_Server_addDataSourceVariableNode(server, myIntegerBNodeId, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), myIntegerBName, UA_NODEID_NULL, attr, dateDataSource, NULL); /* add a repeated job to the server */ UA_Job job = {.type = UA_JOBTYPE_METHODCALL, .job.methodCall = {.method = testCallback, .data = NULL} }; UA_Server_addRepeatedJob(server, job, 2000, NULL); // call every 2 sec UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); nl.deleteMembers(&nl); return (int)retval; }
static void setup(void) { config = UA_ServerConfig_new_default(); config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_malloc(sizeof(UA_PubSubTransportLayer)); if(!config->pubsubTransportLayers) { UA_ServerConfig_delete(config); } config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP(); config->pubsubTransportLayersSize++; server = UA_Server_new(config); UA_Server_run_startup(server); }
static void setup_server(void) { // start server running_translate_browse = UA_Boolean_new(); *running_translate_browse = true; server_translate_config = UA_ServerConfig_new_default(); UA_String_deleteMembers(&server_translate_config->applicationDescription.applicationUri); server_translate_config->applicationDescription.applicationUri = UA_String_fromChars("urn:open62541.test.server_translate_browse"); server_translate_browse = UA_Server_new(server_translate_config); UA_Server_run_startup(server_translate_browse); pthread_create(&server_thread_translate_browse, NULL, serverloop_register, NULL); }
static void setup(void) { running = true; config = UA_ServerConfig_new_default(); config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_malloc(sizeof(UA_PubSubTransportLayer)); if(!config->pubsubTransportLayers) { UA_ServerConfig_delete(config); } config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP(); config->pubsubTransportLayersSize++; server = UA_Server_new(config); UA_Server_run_startup(server); THREAD_CREATE(server_thread, serverloop); }
static UA_Server* makeTestSequence(void) { UA_Server *server = UA_Server_new(UA_ServerConfig_standard); /* VariableNode */ UA_Variant *myIntegerVariant = UA_Variant_new(); UA_Int32 myInteger = 42; UA_Variant_setScalarCopy(myIntegerVariant, &myInteger, &UA_TYPES[UA_TYPES_INT32]); const UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer"); const UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer"); UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER); UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES); UA_Server_addVariableNode(server, myIntegerNodeId, myIntegerName, UA_LOCALIZEDTEXT("en_US","the answer"), UA_LOCALIZEDTEXT("en_US","the answer"), 0, 0, parentNodeId, parentReferenceNodeId, myIntegerVariant, NULL); /* ObjectNode */ UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, 50), UA_QUALIFIEDNAME(1, "Demo"), UA_LOCALIZEDTEXT("en_US","Demo"), UA_LOCALIZEDTEXT("en_US","Demo"), 0, 0, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), NULL); /* ReferenceTypeNode */ UA_ReferenceTypeNode *organizes = UA_ReferenceTypeNode_new(); copyNames((UA_Node*)organizes, "Organizes"); organizes->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "OrganizedBy"); organizes->nodeId.identifier.numeric = UA_NS0ID_ORGANIZES; organizes->isAbstract = UA_FALSE; organizes->symmetric = UA_FALSE; UA_Server_addNode(server, (UA_Node*)organizes, UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HIERARCHICALREFERENCES), UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE)); /* ViewNode */ UA_ViewNode *viewtest = UA_ViewNode_new(); copyNames((UA_Node*)viewtest, "Viewtest"); viewtest->nodeId.identifier.numeric = UA_NS0ID_VIEWNODE; UA_Server_addNode(server, (UA_Node*)viewtest, UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_VIEWSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE)); /* MethodNode */ UA_MethodNode *methodtest = UA_MethodNode_new(); copyNames((UA_Node*)methodtest, "Methodtest"); methodtest->nodeId.identifier.numeric = UA_NS0ID_METHODNODE; UA_Server_addNode(server, (UA_Node*)methodtest, UA_EXPANDEDNODEID_NUMERIC(0, 3), UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE)); return server; }
int main(int argc, char* argv[]) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); if(argc < 3) { UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "Missing arguments. Arguments are " "<server-certificate.der> <private-key.der> " "[<trustlist1.crl>, ...]"); return 1; } /* Load certificate and private key */ UA_ByteString certificate = loadFile(argv[1]); UA_ByteString privateKey = loadFile(argv[2]); /* Load the trustlist */ size_t trustListSize = 0; if(argc > 3) trustListSize = (size_t)argc-3; UA_STACKARRAY(UA_ByteString, trustList, trustListSize); for(size_t i = 0; i < trustListSize; i++) trustList[i] = loadFile(argv[i+3]); /* Loading of a revocation list currently unsupported */ UA_ByteString *revocationList = NULL; size_t revocationListSize = 0; UA_ServerConfig *config = UA_ServerConfig_new_basic128rsa15(4840, &certificate, &privateKey, trustList, trustListSize, revocationList, revocationListSize); UA_ByteString_deleteMembers(&certificate); UA_ByteString_deleteMembers(&privateKey); for(size_t i = 0; i < trustListSize; i++) UA_ByteString_deleteMembers(&trustList[i]); if(!config) { UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "Could not create the server config"); return 1; } UA_Server *server = UA_Server_new(config); UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); UA_ServerConfig_delete(config); return (int)retval; }
static void setup_lds(void) { // start LDS server running_lds = UA_Boolean_new(); *running_lds = true; server_lds = UA_Server_new(); configure_lds_server(server_lds); UA_Server_run_startup(server_lds); THREAD_CREATE(server_thread_lds, serverloop_lds); // wait until LDS started UA_fakeSleep(1000); UA_realSleep(1000); }
int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); /* Add a repeated callback to the server */ UA_Server_addRepeatedCallback(server, testCallback, NULL, 2000, NULL); /* call every 2 sec */ UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); UA_ServerConfig_delete(config); return (int)retval; }
static void setup(void) { running = UA_Boolean_new(); *running = true; config = UA_ServerConfig_new_default(); config->maxPublishReqPerSession = 5; server = UA_Server_new(config); UA_Server_run_startup(server); addNewEventType(); setupSelectClauses(); THREAD_CREATE(server_thread, serverloop); client = UA_Client_new(UA_ClientConfig_default); UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); setupSubscription(); }
static void setup_register(void) { // start register server running_register = UA_Boolean_new(); *running_register = true; config_register = UA_ServerConfig_new_minimal(16664, NULL); UA_String_deleteMembers(&config_register->applicationDescription.applicationUri); config_register->applicationDescription.applicationUri = UA_String_fromChars("urn:open62541.test.server_register"); UA_LocalizedText_deleteMembers(&config_register->applicationDescription.applicationName); config_register->applicationDescription.applicationName = UA_LOCALIZEDTEXT_ALLOC("de", "Anmeldungsserver"); config_register->mdnsServerName = UA_String_fromChars("Register_test"); server_register = UA_Server_new(config_register); UA_Server_run_startup(server_register); pthread_create(&server_thread_register, NULL, serverloop_register, NULL); }
int main (void) { /* default server values */ signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); addNewEventType(server); addGenerateEventMethod(server); UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); UA_ServerConfig_delete(config); return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE; }
int main(int argc, char** argv) { signal(SIGINT, stopHandler); /* catches ctrl-c */ #ifdef UA_ENABLE_MULTITHREADING pthread_rwlock_init(&writeLock, 0); #endif UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); UA_ServerConfig config = UA_ServerConfig_standard; config.serverCertificate = loadCertificate(); config.networkLayers = &nl; config.networkLayersSize = 1; UA_Server *server = UA_Server_new(config); // add node with the datetime data source UA_DataSource dateDataSource = (UA_DataSource) {.handle = NULL, .read = readTimeData, .write = NULL}; UA_VariableAttributes v_attr; UA_VariableAttributes_init(&v_attr); v_attr.description = UA_LOCALIZEDTEXT("en_US","current time"); v_attr.displayName = UA_LOCALIZEDTEXT("en_US","current time"); v_attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE; const UA_QualifiedName dateName = UA_QUALIFIEDNAME(1, "current time"); UA_NodeId dataSourceId; UA_Server_addDataSourceVariableNode(server, UA_NODEID_NULL, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), dateName, UA_NODEID_NULL, v_attr, dateDataSource, &dataSourceId); #ifndef _WIN32 /* cpu temperature monitoring for linux machines */ const char *temperatureFileName = "/sys/class/thermal/thermal_zone0/temp"; // RaspberryPi // const char *temperatureFileName = "/sys/class/hwmon/hwmon0/device/temp1_input"; // Beaglebone // const char *temperatureFileName = "/sys/class/thermal/thermal_zone3/temp"; // Intel Edison Alternative 1 // const char *temperatureFileName = "/sys/class/thermal/thermal_zone4/temp"; // Intel Edison Alternative 2 if((temperatureFile = fopen(temperatureFileName, "r"))) { // add node with the data source UA_DataSource temperatureDataSource = (UA_DataSource) { .handle = NULL, .read = readTemperature, .write = NULL}; const UA_QualifiedName tempName = UA_QUALIFIEDNAME(1, "cpu temperature"); UA_VariableAttributes_init(&v_attr); v_attr.description = UA_LOCALIZEDTEXT("en_US","temperature"); v_attr.displayName = UA_LOCALIZEDTEXT("en_US","temperature"); v_attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE; UA_Server_addDataSourceVariableNode(server, UA_NODEID_NULL, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), tempName, UA_NODEID_NULL, v_attr, temperatureDataSource, NULL); }
int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); UA_Server *server = UA_Server_new(); UA_ServerConfig_setDefault(UA_Server_getConfig(server)); addVariableType2DPoint(server); addVariable(server); addVariableFail(server); writeVariable(server); UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE; }
int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); addVariableType2DPoint(server); addVariable(server); addVariableFail(server); writeVariable(server); UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); UA_ServerConfig_delete(config); return (int)retval; }
int main(int argc, char** argv) { signal(SIGINT, stopHandler); /* catches ctrl-c */ UA_ServerConfig config = UA_ServerConfig_standard; UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); config.networkLayers = &nl; config.networkLayersSize = 1; UA_Server *server = UA_Server_new(config); /* add a repeated job to the server */ UA_Job job = {.type = UA_JOBTYPE_METHODCALL, .job.methodCall = {.method = testCallback, .data = NULL} }; UA_Server_addRepeatedJob(server, job, 2000, NULL); // call every 2 sec UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); nl.deleteMembers(&nl); return (int)retval; }
static void setup(void) { server = UA_Server_new(); UA_ServerConfig *config = UA_Server_getConfig(server); UA_ServerConfig_setDefault(config); config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_malloc(sizeof(UA_PubSubTransportLayer)); config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP(); config->pubsubTransportLayersSize++; UA_Server_run_startup(server); UA_PubSubConnectionConfig connectionConfig; memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig)); connectionConfig.name = UA_STRING("UADP Connection"); UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL, UA_STRING("opc.udp://224.0.0.22:4840/")}; UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl, &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]); connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp"); UA_Server_addPubSubConnection(server, &connectionConfig, &connection1); }
int main(int argc, char** argv) { signal(SIGINT, signalHandler); /* catch ctrl-c */ /* Create a server with one network layer listening on port 4840 */ UA_ServerConfig config = UA_ServerConfig_standard; UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 4840); config.networkLayers = &nl; config.networkLayersSize = 1; UA_Server *server = UA_Server_new(config); /* Add a variable node */ UA_VariableAttributes attr; UA_VariableAttributes_init(&attr); attr.displayName = UA_LOCALIZEDTEXT("en_US", "Test Var"); UA_Int32 myInteger = 2572; UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]); UA_NodeId newNodeId = UA_NODEID_STRING(1, "Test.Var"); UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER); UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES); UA_NodeId variableType = UA_NODEID_NULL; /* take the default variable type */ UA_QualifiedName browseName = UA_QUALIFIEDNAME(1, "Test Node"); UA_DataSource dateDataSource = (UA_DataSource) {.handle = &myInteger, .read = onRead, .write = NULL}; UA_Server_addDataSourceVariableNode(server, newNodeId, parentNodeId, parentReferenceNodeId, browseName, UA_NODEID_NULL, attr, dateDataSource, NULL); UA_Job job = {.type = UA_JOBTYPE_METHODCALL, .job.methodCall = {.method = testCallback, .data = NULL} }; UA_Server_addRepeatedJob(server, job, 2000, NULL); // call every 2 sec /* Run the server loop */ UA_StatusCode status = UA_Server_run(server, &running); UA_Server_delete(server); nl.deleteMembers(&nl); return status; }
int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); manuallyDefinePump(server); defineObjectTypes(server); addPumpObjectInstance(server, "pump2"); addPumpObjectInstance(server, "pump3"); addPumpTypeConstructor(server); addPumpObjectInstance(server, "pump4"); addPumpObjectInstance(server, "pump5"); UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); UA_ServerConfig_delete(config); return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE; }