├── .gitmodules ├── .idea ├── encodings.xml ├── misc.xml ├── modules.xml ├── opcua-animal-server.iml ├── serialmonitor_settings.xml └── vcs.xml ├── CMakeLists.txt ├── LICENSE ├── README.md └── src └── server_animal.c /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "opcua-animal-cs"] 2 | path = opcua-animal-cs 3 | url = https://github.com/Pro/opcua-animal-cs 4 | branch = master 5 | [submodule "open62541"] 6 | path = open62541 7 | url = https://github.com/open62541/open62541 8 | branch = master 9 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/opcua-animal-server.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.idea/serialmonitor_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(opcua-anmal-server) 3 | 4 | set(UA_NAMESPACE_ZERO FULL CACHE STRING "" FORCE) 5 | set(open62541_TOOLS_DIR "${CMAKE_SOURCE_DIR}/open62541/tools") 6 | set(open62541_NODESET_DIR "${CMAKE_SOURCE_DIR}/open62541/deps/ua-nodeset") 7 | add_subdirectory(open62541) 8 | 9 | ua_generate_nodeset_and_datatypes( 10 | NAME "animal" 11 | FILE_CSV "${CMAKE_SOURCE_DIR}/opcua-animal-cs/Published/animal/animalModel.csv" 12 | FILE_BSD "${CMAKE_SOURCE_DIR}/opcua-animal-cs/Published/animal/animal.Types.bsd" 13 | NAMESPACE_IDX 2 14 | FILE_NS "${CMAKE_SOURCE_DIR}/opcua-animal-cs/Published/animal/animal.NodeSet2.xml" 15 | OUTPUT_DIR "${CMAKE_BINARY_DIR}/animal_cs" 16 | INTERNAL 17 | ) 18 | 19 | include_directories(${CMAKE_BINARY_DIR}/animal_cs) 20 | 21 | add_executable(server_animal 22 | src/server_animal.c 23 | ${UA_NODESET_ANIMAL_SOURCES} 24 | ${UA_TYPES_ANIMAL_SOURCES}) 25 | target_link_libraries(server_animal open62541::open62541) 26 | 27 | add_dependencies(server_animal open62541-generator-ns-animal) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OPC UA Animal Server 2 | 3 | OPC UA Server for the OPC UA Companion Specification for Animals - A Tutorial 4 | 5 | This repository shows how to use the OPC UA Animal companion specification from the repository: 6 | https://github.com/Pro/opcua-animal-cs 7 | 8 | The corresponding Tutorial can be found here: 9 | https://opcua.rocks/custom-information-models/ 10 | 11 | ## Build 12 | 13 | First clone this repository and initialize the git submodule: 14 | 15 | ```bash 16 | git clone https://github.com/Pro/opcua-animal-server 17 | cd opcua-animal-server 18 | git submodule update --init --recursive 19 | ``` 20 | 21 | Then just run CMake and make: 22 | 23 | ```bash 24 | mkdir build 25 | cd build 26 | cmake .. 27 | make -j 28 | ``` 29 | 30 | ## Run 31 | 32 | After building the repository, just run the executable: 33 | 34 | ```bash 35 | cd build 36 | ./server_animal 37 | ``` 38 | 39 | Then use e.g. UaExpert to connect to the server. 40 | The Endpoint URL is printed in the terminal, but should be the default: `opc.tcp://localhost:4840` 41 | 42 | -------------------------------------------------------------------------------- /src/server_animal.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by profanter on 17/05/19. 3 | // This is free and unencumbered software released into the public domain. 4 | // 5 | 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | /* Files namespace_animal_generated.h and namespace_animal_generated.c are created from animal.NodeSet2.xml in the 12 | * /src_generated/animal_cs directory by CMake */ 13 | #include "animal_nodeids.h" 14 | #include "namespace_animal_generated.h" 15 | 16 | #include 17 | #include 18 | 19 | UA_Boolean running = true; 20 | 21 | static void stopHandler(int sign) { 22 | UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c"); 23 | running = false; 24 | } 25 | 26 | int main(int argc, char** argv) { 27 | signal(SIGINT, stopHandler); 28 | signal(SIGTERM, stopHandler); 29 | 30 | UA_Server *server = UA_Server_new(); 31 | UA_ServerConfig_setDefault(UA_Server_getConfig(server)); 32 | 33 | UA_StatusCode retval; 34 | /* create nodes from nodeset */ 35 | if(namespace_animal_generated(server) != UA_STATUSCODE_GOOD) { 36 | UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Could not add the animal nodeset. " 37 | "Check previous output for any error."); 38 | retval = UA_STATUSCODE_BADUNEXPECTEDERROR; 39 | } else { 40 | 41 | retval = UA_Server_run(server, &running); 42 | } 43 | 44 | UA_Server_delete(server); 45 | return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE; 46 | } 47 | --------------------------------------------------------------------------------