Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added OPC UA server support #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 26 additions & 1 deletion install.sh
Expand Up @@ -80,7 +80,12 @@ if [ "$1" == "win" ]; then
exit 1
fi
cd ../..


echo ""
echo "[OPC UA]"
sudo apt-get install -y python-pip python-dev
pip install opcua

echo ""
echo "[LIBMODBUS]"
cd utils/libmodbus_src
Expand Down Expand Up @@ -187,6 +192,11 @@ elif [ "$1" == "linux" ]; then
fi
sudo ldconfig
cd ../..

echo ""
echo "[OPC UA]"
sudo apt-get install -y python-pip python-dev
pip install opcua

echo ""
echo "[OPENPLC SERVICE]"
Expand Down Expand Up @@ -291,6 +301,11 @@ elif [ "$1" == "rpi" ]; then
sudo swapoff swapfile
sudo rm -f ./swapfile
cd ../..

echo ""
echo "[OPC UA]"
sudo apt-get install -y python-pip python-dev
pip install opcua

echo ""
echo "[LIBMODBUS]"
Expand Down Expand Up @@ -409,6 +424,11 @@ elif [ "$1" == "neuron" ]; then
sudo swapoff swapfile
sudo rm -f ./swapfile
cd ../..

echo ""
echo "[OPC UA]"
sudo apt-get install -y python-pip python-dev
pip install opcua

echo ""
echo "[LIBMODBUS]"
Expand Down Expand Up @@ -527,6 +547,11 @@ elif [ "$1" == "custom" ]; then
sudo swapoff swapfile
sudo rm -f ./swapfile
cd ../..

echo ""
echo "[OPC UA]"
sudo apt-get install -y python-pip python-dev
pip install opcua

echo ""
echo "[LIBMODBUS]"
Expand Down
53 changes: 53 additions & 0 deletions webserver/core/interactive_server.cpp
Expand Up @@ -42,6 +42,8 @@ bool run_modbus = 0;
int modbus_port = 502;
bool run_dnp3 = 0;
int dnp3_port = 20000;
bool run_opcua = 0;
int opcua_port = 4840;
unsigned char server_command[1024];
int command_index = 0;
bool processing_command = 0;
Expand All @@ -51,6 +53,7 @@ time_t end_time;
//Global Threads
pthread_t modbus_thread;
pthread_t dnp3_thread;
pthread_t opcua_thread;

//-----------------------------------------------------------------------------
// Start the Modbus Thread
Expand All @@ -68,6 +71,14 @@ void *dnp3Thread(void *arg)
dnp3StartServer(dnp3_port);
}

//-----------------------------------------------------------------------------
// Start the OPC UA Thread
//-----------------------------------------------------------------------------
void *opcuaThread(void *arg)
{
opcuaStartServer(opcua_port);
}

//-----------------------------------------------------------------------------
// Read the argument from a command function
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -210,6 +221,13 @@ void processCommand(unsigned char *buffer, int client_fd)
sprintf(log_msg, "DNP3 server was stopped\n");
log(log_msg);
}
if (run_opcua)
{
run_opcua = 0;
pthread_join(opcua_thread, NULL);
sprintf(log_msg, "OPC UA server was stopped\n");
log(log_msg);
}
run_openplc = 0;
processing_command = false;
}
Expand Down Expand Up @@ -283,6 +301,41 @@ void processCommand(unsigned char *buffer, int client_fd)
}
processing_command = false;
}
else if (strncmp(buffer, "start_opcua(", 12) == 0)
{
processing_command = true;
sprintf(log_msg, "Issued start_opcua() command to start on port: %d\n", readCommandArgument(buffer));
log(log_msg);
opcua_port = readCommandArgument(buffer);
if (run_opcua)
{
sprintf(log_msg, "OPC UA server already active. Restarting on port: %d\n", opcua_port);
log(log_msg);
//Stop OPC UA server
run_opcua = 0;
pthread_join(opcua_thread, NULL);
sprintf(log_msg, "OPC UA server was stopped\n");
log(log_msg);
}
//Start OPC UA server
run_opcua = 1;
pthread_create(&opcua_thread, NULL, opcuaThread, NULL);
processing_command = false;
}
else if (strncmp(buffer, "stop_opcua()", 12) == 0)
{
processing_command = true;
sprintf(log_msg, "Issued stop_opcua() command\n");
log(log_msg);
if (run_opcua)
{
run_opcua = 0;
pthread_join(opcua_thread, NULL);
sprintf(log_msg, "OPC UA server was stopped\n");
log(log_msg);
}
processing_command = false;
}
else if (strncmp(buffer, "runtime_logs()", 14) == 0)
{
processing_command = true;
Expand Down
4 changes: 4 additions & 0 deletions webserver/core/ladder.h
Expand Up @@ -125,6 +125,7 @@ bool SetSocketBlockingEnabled(int fd, bool blocking);
void startInteractiveServer(int port);
extern bool run_modbus;
extern bool run_dnp3;
extern bool run_opcua;
extern time_t start_time;
extern time_t end_time;

Expand All @@ -141,6 +142,9 @@ void updateBuffersOut_MB();
//dnp3.cpp
void dnp3StartServer(int port);

//opcua.cpp
void opcuaStartServer(int port);

//persistent_storage.cpp
void *persistentStorage(void *args);
int readPersistentStorage();