This site uses cookies for functional purposes. To continue please read and agree to our Data Privacy.

By closing this message, you consent to our use of cookies on this device.

PLCnext on Instagram  PLCnext on YouTube Github PLCnext CommunityStore PLCnext Community

  1. Michael Gulsch
  2. PLCnext Technology & PLCnext Controls
  3. Thursday, 09 August 2018

Hello together I have followed the instructions of Martin to install openhab2 on the AXC F 2152. Anything's work fine, but issue, that openhab won't start automatically after a reboot is a little bit annoying. That forces me to change it, and here is the solution. 

1) Because of the fact, that standard text files couldn't be uploaded (-> hopefully the admins will change that soon after they have eliminated the worm hole) I have attached the sources of the script behind this article. You have to copy & paste it and store it inside a file named "openhab2" (TAKE CARE ABOUT, THAT IT HAS TO BE STORED FOR LINUX SYSTEMS) With notepad++, you can configure it under /settings/Preferences/NewDocuments -> Change it to UNIX....then the string termination will be LF

2) After that, you have to copy this file to the PLC inside the folder "/etc/init.d" (Login as root, otherwise it causes problems)

3) Open a terminal session and login as root user

4) Type in following command "update-rc.d openhab2 defaults 80 10"

5) Be happy

From that point, openhab2 will start automatically after boot. You can run the script as root as follows : ./openhab2 (start | stop | restart)

##################################################### Script Section ###################################################

#!/bin/sh
### BEGIN INIT INFO
# Provides: Start | Stop | Restart of openhab2
# Required-Start: network ha sto be started
# Required-Stop: Was muss vorher beendet werden?
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Script to start, stop and restart openhab
# Description: The script starts openhab normally. Stopping openhab is
# realised by scanning for process Ids and first kiling the karaf console
# and then the main process (this may take a while)
### END INIT INFO
# Author: Michael Gulsch

# Aktionen

umask 077

scan_process(){
scan_result=`ps | grep $1`
scan_result=$(echo ${scan_result%%root*})
scan_result=$(echo ${scan_result%% *})
space=` `
scan_result=$space$scan_result
if [ $scan_result -eq 0 ] | [ $scan_result -ne $1 ];
then
echo "0"
else
echo "1"
fi
}


start(){
/opt/openhab2/start.sh server &
echo "Openhab2 - Service started"
}

stop(){
grep_result=`ps | grep {karaf}`
grep_result=$(echo ${grep_result%%root*})
grep_result=$(echo ${grep_result%% *})
space=` `
grep_result=$space$grep_result
kill $grep_result
scan="1"
echo "Openhab2 - started to kill "karaf" terminal: " $grep_result
while [[ $scan -eq 1 ]]; do
scan=`scan_process $grep_result`
sleep 1
echo -n "."
done
echo
echo "Openhab2 - Terminal terminated"
grep_result=`ps | grep Dopenhab`
grep_result=$(echo ${grep_result%%root*})
grep_result=$(echo ${grep_result%% *})
grep_result=$space$grep_result
kill $grep_result
scan="1"
echo "Openhab2 - started to kill main process: " $grep_result
while [[ $scan -eq 1 ]]; do
scan=`scan_process $grep_result`
sleep 1
echo -n "."
done
echo
echo "Openhab2 - Main process terminated"
}

restart(){
stop && start
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "use: openhab2 {start|stop|restart}"
exit 1
;;
esac

exit $?

 

Martin PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo

Very nice, thank you for posting this exkalibur28.

Out if interest, how are you using OpenHab with the AXC F 2152? Have you tried driving I/O from the controller and, if successful, how did you do this? (we had discussed options like Modbus previously, but the best option would be for someone with the time and inclination to write a custom PLCnext “binding” for OpenHab.)

- Martin

Phoenix Contact Electronics Headquarters - PLCnext Runtime Product Management and Support

Michael Gulsch Accepted Answer Pending Moderation
0
Votes
Undo

Hi Martin,

you can call me Michael...(my Name is visible under Author of the script above).

Today I use the NODE RED and OPENHAB example as demonstrator in sales trainings.

Regarding the binding, I think the best way would be, that someone write an OPC UA bindung for OPENHAB. That is one thing that is in discussion in their community, NODE-RED has one, and it is a fun how easy it is, to connect NODE-RED with PLCnext over OPC UA.

- Michael

Jozef Accepted Answer Pending Moderation
0
Votes
Undo

Hi Michael,

Im trying to connect PLCnext Vars via nodered (node-red-contrib-iiot-opcua, node-red-contrib-openhab-v2) modules together.

I can set some variable from nodered in PLC but not from openhab2 to PLC and vice versa.

Can you send me some short description how should be done to connect openhab with PLC ?

 

I thing I have LISTENER solution.

6_DebugFCT_before_after  - debug and conversion works OK.

OH2 switch item DA16_DA sometime switched OK and sometime does't switched.

What do I wrong please ?

Have you some CMD examples for this direction from PLC to OH and from OH back ?

Same for measured values ?

Thanks for help.

 

Attachments (3)
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.