mirror of
https://github.com/emqx/neuron.git
synced 2026-10-27 12:28:44 +08:00
Read configuration file
This commit is contained in:
+17
-1
@@ -1,7 +1,14 @@
|
||||
lib_path: ./
|
||||
mqtt:
|
||||
id: neuron-lite-mqtt-plugin-10012
|
||||
mqtt_version: 4
|
||||
topic: neuronlite/response
|
||||
qos: 1
|
||||
keepalive_interval: 20
|
||||
clean_session: 1
|
||||
broker:
|
||||
host: 127.0.0.1
|
||||
connection: tcp://
|
||||
host: localhost
|
||||
port: 1883
|
||||
web:
|
||||
host: 0.0.0.0
|
||||
@@ -9,3 +16,12 @@ web:
|
||||
api:
|
||||
host: 0.0.0.0
|
||||
port: 7001
|
||||
opcua:
|
||||
default_cert_file: ./opcua-default-cert.der
|
||||
default_key_file: ./opcua-default-key.der
|
||||
host: localhost
|
||||
port: 4840
|
||||
username: gaoc01
|
||||
password: 123456
|
||||
cert_file: ""
|
||||
key_file: ""
|
||||
@@ -1,10 +1,9 @@
|
||||
find_package(eclipse-paho-mqtt-c 1.3.9 REQUIRED)
|
||||
|
||||
# include_directories(../../include/)
|
||||
|
||||
file(GLOB PARSER_SRC "${CMAKE_SOURCE_DIR}/src/parser/*.c")
|
||||
file(GLOB CONFIG_SRC "${CMAKE_SOURCE_DIR}/src/config.c")
|
||||
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}")
|
||||
set(src ${PARSER_SRC} plugin_mqtt.c paho_client.c message_handle.c)
|
||||
set(src ${PARSER_SRC} ${CONFIG_SRC} plugin_mqtt.c paho_client.c message_handle.c)
|
||||
add_library(plugin-mqtt SHARED ${src})
|
||||
|
||||
target_include_directories(plugin-mqtt PRIVATE
|
||||
@@ -12,5 +11,5 @@ target_include_directories(plugin-mqtt PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
target_link_libraries(plugin-mqtt neuron-base paho-mqtt3as ssl crypto)
|
||||
target_link_libraries(plugin-mqtt neuron-base paho-mqtt3as ssl crypto yaml)
|
||||
target_link_libraries(plugin-mqtt ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
+27
-12
@@ -21,6 +21,7 @@
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <config.h>
|
||||
#include <neuron.h>
|
||||
|
||||
#include "message_handle.h"
|
||||
@@ -36,7 +37,6 @@ struct neu_plugin {
|
||||
neu_plugin_common_t common;
|
||||
option_t option;
|
||||
paho_client_t * paho;
|
||||
uint32_t new_event_id;
|
||||
neu_list context_list;
|
||||
};
|
||||
|
||||
@@ -163,19 +163,34 @@ static int mqtt_plugin_close(neu_plugin_t *plugin)
|
||||
|
||||
static int mqtt_plugin_init(neu_plugin_t *plugin)
|
||||
{
|
||||
plugin->new_event_id = 1;
|
||||
const char *clientid =
|
||||
neu_config_get_value("./neuron.yaml", 2, "mqtt", "id");
|
||||
const char *mqtt_version =
|
||||
neu_config_get_value("./neuron.yaml", 2, "mqtt", "mqtt_version");
|
||||
const char *topic =
|
||||
neu_config_get_value("./neuron.yaml", 2, "mqtt", "topic");
|
||||
const char *qos = neu_config_get_value("./neuron.yaml", 2, "mqtt", "qos");
|
||||
const char *keepalive_interval =
|
||||
neu_config_get_value("./neuron.yaml", 2, "mqtt", "keepalive_interval");
|
||||
const char *clean_session =
|
||||
neu_config_get_value("./neuron.yaml", 2, "mqtt", "clean_session");
|
||||
const char *connection = neu_config_get_value("./neuron.yaml", 3, "mqtt",
|
||||
"broker", "connection");
|
||||
const char *host =
|
||||
neu_config_get_value("./neuron.yaml", 3, "mqtt", "broker", "host");
|
||||
const char *port =
|
||||
neu_config_get_value("./neuron.yaml", 3, "mqtt", "broker", "port");
|
||||
|
||||
// MQTT option
|
||||
plugin->option.clientid = "neuron-lite-mqtt-plugin-10012";
|
||||
plugin->option.MQTT_version = 4;
|
||||
plugin->option.topic = "neuronlite/response";
|
||||
plugin->option.qos = 1;
|
||||
plugin->option.connection = "tcp://";
|
||||
// plugin->option.host = "broker.emqx.io";
|
||||
plugin->option.host = "localhost";
|
||||
plugin->option.port = "1883";
|
||||
plugin->option.keepalive_interval = 20;
|
||||
plugin->option.clean_session = 1;
|
||||
plugin->option.clientid = strdup(clientid);
|
||||
plugin->option.MQTT_version = atoi(mqtt_version);
|
||||
plugin->option.topic = strdup(topic);
|
||||
plugin->option.qos = atoi(qos);
|
||||
plugin->option.connection = strdup(connection);
|
||||
plugin->option.host = strdup(host);
|
||||
plugin->option.port = strdup(port);
|
||||
plugin->option.keepalive_interval = atoi(keepalive_interval);
|
||||
plugin->option.clean_session = atoi(clean_session);
|
||||
|
||||
// Paho mqtt client setup
|
||||
client_error error =
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
find_package(open62541 1.2.2 REQUIRED)
|
||||
|
||||
file(GLOB PARSER_SRC "${CMAKE_SOURCE_DIR}/src/parser/*.c")
|
||||
file(GLOB CONFIG_SRC "${CMAKE_SOURCE_DIR}/src/config.c")
|
||||
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}")
|
||||
set(src ${PARSER_SRC} plugin_opcua.c open62541_client.h open62541_client.c plugin_handle.h plugin_handle.c)
|
||||
set(src ${PARSER_SRC} ${CONFIG_SRC} plugin_opcua.c open62541_client.h open62541_client.c plugin_handle.h plugin_handle.c)
|
||||
add_library(plugin-opcua SHARED ${src})
|
||||
|
||||
target_include_directories(plugin-opcua PRIVATE
|
||||
@@ -10,5 +11,5 @@ target_include_directories(plugin-opcua PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
target_link_libraries(plugin-opcua neuron-base open62541 ssl crypto)
|
||||
target_link_libraries(plugin-opcua neuron-base open62541 ssl crypto yaml)
|
||||
target_link_libraries(plugin-opcua ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <config.h>
|
||||
#include <neuron.h>
|
||||
|
||||
#include "option.h"
|
||||
@@ -73,15 +74,31 @@ static int opcua_plugin_close(neu_plugin_t *plugin)
|
||||
|
||||
static int opcua_plugin_init(neu_plugin_t *plugin)
|
||||
{
|
||||
const char *default_cert_file =
|
||||
neu_config_get_value("./neuron.yaml", 2, "opcua", "default_cert_file");
|
||||
const char *default_key_file =
|
||||
neu_config_get_value("./neuron.yaml", 2, "opcua", "default_key_file");
|
||||
const char *host =
|
||||
neu_config_get_value("./neuron.yaml", 2, "opcua", "host");
|
||||
const char *port = neu_config_get_value("neuron.yaml", 2, "opcua", "port");
|
||||
const char *username =
|
||||
neu_config_get_value("./neuron.yaml", 2, "opcua", "username");
|
||||
const char *password =
|
||||
neu_config_get_value("./neuron.yaml", 2, "opcua", "password");
|
||||
const char *cert_file =
|
||||
neu_config_get_value("./neuron.yaml", 2, "opcua", "cert_file");
|
||||
const char *key_file =
|
||||
neu_config_get_value("./neuron.yaml", 2, "opcua", "key_file");
|
||||
|
||||
// OPC-UA option
|
||||
plugin->option.default_cert_file = "./opcua-default-cert.der";
|
||||
plugin->option.default_key_file = "./opcua-default-key.der";
|
||||
plugin->option.host = "localhost";
|
||||
plugin->option.port = 4840;
|
||||
plugin->option.username = "gaoc01";
|
||||
plugin->option.password = "123456";
|
||||
plugin->option.cert_file = "";
|
||||
plugin->option.key_file = "";
|
||||
plugin->option.default_cert_file = strdup(default_cert_file);
|
||||
plugin->option.default_key_file = strdup(default_key_file);
|
||||
plugin->option.host = strdup(host);
|
||||
plugin->option.port = atoi(port);
|
||||
plugin->option.username = strdup(username);
|
||||
plugin->option.password = strdup(password);
|
||||
plugin->option.cert_file = strdup(cert_file);
|
||||
plugin->option.key_file = strdup(key_file);
|
||||
|
||||
int rc = open62541_client_open(&plugin->option, plugin, &plugin->client);
|
||||
if (0 != rc) {
|
||||
|
||||
Reference in New Issue
Block a user