communication between RevolutionPi and RaspberryPi using revpimodio

Moderator: RevPiModIO

User avatar
Frido
Posts: 53
Joined: 21 Apr 2018, 10:47
Answers: 0
Location: Stuttgart

communication between RevolutionPi and RaspberryPi using revpimodio

Post by Frido »

Dear all,
my question addresses a communication problem between a Raspberry Pi 3B+ (RasPi) and a Revolution Pi Core 3 (RevPi), as described here: https://revpimodio.org/gpio-zu-revolution/
The goal is to display state variables of my control program, which runs on a RevPi (in logiCAD), on a screen controlled by the RasPi.

I proceeded as described following the above link, but got the error message can not connect to revpi slave:

Image

I tried all I can think of to get rid of the error, but haven’t succeeded. I am very much looking forward to seeing any ideas and will be very thankfull.

Some background information:
- RasPi and RevPi are connected via a patch cable (RJ45)
- there is no control program on the RevPi running
- both devices have a static IP
- I can ping both devices from the other respectively
- the RevPi runs on Jessie and the RasPi on Stretch
- I set the Enable/Disable Modbus Slave on the RevPi web-interface to both enabled and disabled without success
- on the RasPi I changed the file /boot/cmdline.txt by adding net.ifnames=0 to its end in order to change the network name back to Jessie-like nomenclature (as described here).


(There is a comment section on revpimodio.org which I tried, but it doesn’t seem to be activated)
User avatar
volker
Posts: 1046
Joined: 09 Nov 2016, 15:41
Answers: 1

Re: communication between RevolutionPi and RaspberryPi using revpimodio

Post by volker »

Hi Frido,
as your question is very specific and using RevPiModIO I have moved it to the RevPiModIO forum. Sven will be able to answer your question here.
Unser RevPi Motto: Don't just claim it - make it!
User avatar
RevPiModIO
KUNBUS
Posts: 322
Joined: 20 Jan 2017, 08:44
Answers: 0
Contact:

Re: communication between RevolutionPi and RaspberryPi using revpimodio

Post by RevPiModIO »

Oh man, i think it is an error in the blog post. It shows a RevPiPyLoad configuration before version 0.6.5! (I will fix that)

I'm sure you are using the current version 0.6.5 and there is no parameter "plcslaveacl" in the "revpipyload.conf" anymore. The ACLs are now configured in the "/etc/revpipyload/aclplcslave.conf" file. Please visit this Post to check out configuration on version 0.6.5 https://revpimodio.org/en/revpipyplc-2/revpipyload/!

The original file "revpipyload.conf" looks like this:

Code: Select all

[DEFAULT]
autoreload = 1
autoreloaddelay = 5
autostart = 1
plcworkdir = /var/lib/revpipyload
plcprogram = program.py
plcarguments = 
plcuid = 1000
plcgid = 1000
pythonversion = 3
rtlevel = 0
zeroonerror = 0
zeroonexit = 0

[PLCSLAVE]
plcslave = 0
aclfile = /etc/revpipyload/aclplcslave.conf
bindip = *
port = 55234

[XMLRPC]
xmlrpc = 0
aclfile = /etc/revpipyload/aclxmlrpc.conf
bindip = *
Important parameters are aclfile in the [PLCSLAVE] and [XMLRPC] section.

Your "aclplcslave.conf" could look like this:

Code: Select all

# PLC-SLAVE Access Control List (acl)
# One entry per Line IPADRESS,LEVEL
#
169.254.*.*,1
Than you can read/write to the process image.

Check the log file of RevPiPyLoad on the Revolution Pi, it should log denied connect requests: /var/log/revpipyload

Sven
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
User avatar
Frido
Posts: 53
Joined: 21 Apr 2018, 10:47
Answers: 0
Location: Stuttgart

Re: communication between RevolutionPi and RaspberryPi using revpimodio

Post by Frido »

Hey Sven,
thanks a lot for your answer!
Yes, I use the most recent version 0.6.5, I installed it via sudo apt-get install revpipyload approx. 10 days ago.
I followed your steps and added an entry in the ACL in the /etc/revpipyload/aclplcslave.conf file on my RevPi:

Code: Select all

169.254.*.*,0
(I only want to read)
Also, I reset the revpipyload.conf file on the RevPi.
Unfortunately, I didn't succeed: I still get the exact same error on the RasPi as shown in the screenshot in my first post. (What calls my attention is that this error appears instantaneously, no time whatsoever passes to "reach out" in order to establish a connection.) So I had a look in the log file on the RevPi via sudo nano /var/log/revpipyload, which looks like this:
Image
So I uninstalled revpipyload with sudo apt-get remove revpipyload and installed it again. After the new installation of revpipyload and a restart of the RevPi, the same message appeared twice, the second one below the first one, just with an updated time of the restart.
I had a look at /var/lib/revpipyload/ : It is empty, no program.py or anything there. Also, I don't know what the [WARNING] is, as I only added the above line to the /etc/revpipyload/aclplcslave.conf file.
Could you please be so kind and explain the [WARNING] and the [ERROR] in the screenshot?

Do you have any ideas of what I might have done or be doing wrong?

Best regards and thanks again!
Frido
User avatar
RevPiModIO
KUNBUS
Posts: 322
Joined: 20 Jan 2017, 08:44
Answers: 0
Contact:

Re: communication between RevolutionPi and RaspberryPi using revpimodio

Post by RevPiModIO »

Hi Frido, sorry for that trouble!

Could you purge your installation of revpipyload with

Code: Select all

sudo apt-get purge revpipyload
to remove all program and configuration files?

Please be sure that the /etc/revpipyload directory is removed

Code: Select all

sudo rm -R /etc/revpipyload
And than try an updated Version: http://revpimodio.org/dnl/revpipyload_0.6.7-1_all.deb

Download an install it manually on the RevPi:

Code: Select all

wget http://revpimodio.org/dnl/revpipyload_0.6.7-1_all.deb
sudo dpkg -i revpipyload_0.6.7-1_all.deb
About the errors and warnings in the log file:

[WARNING]: RevPiPyLoad can not load the given "aclfile" in the [PLCSLAVE] (should be resolved with purged reinstall)
[ERROR] (logged): The RevPiPyLoad System loads a python program on the RevolutionPi. If you do not use a Python program for controlling your RevPi, set parameter "autostart" in the [DEFAULT] section to "0".
LAST ERROR: NoneType()... : Program error, I fixed in the new 0.6.7 Version. Appears if the xmlrpc is set to "0"

So, please try the new update with a clean installation (purge the old version) and setup the new configuration files https://revpimodio.org/en/revpipyplc-2/revpipyload/.

Regards, Sven

Could you send me your "/etc/revpipyload" folder with all files before purge?
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
User avatar
Frido
Posts: 53
Joined: 21 Apr 2018, 10:47
Answers: 0
Location: Stuttgart

Re: communication between RevolutionPi and RaspberryPi using revpimodio

Post by Frido »

Hello Sven,

thanks again for your answer! And sorry for getting back so late, I just came back from a trip.

So, I followed your steps. (Before that, I updated my RasPi to Strecht 2018-06-27 and work now without a static IP on my RasPi.)
  1. First, I deleted the old installation of revpipyload (I sent you the folder before purge)
  2. in order to install the newest version of revpipyload on the RevPi, I first had to update to python3-revpimodio2_2.1.6-1_all.deb via

    Code: Select all

    pi@RevPi ~/ $ wget http://revpimodio.org/dnl/python3-revpimodio2_2.1.6-1_all.deb
    pi@RevPi ~/ $ sudo dpkg -i python3-revpimodio2_2.1.6-1_all.deb
    
    Source
  3. then I (re-)installed revpipyload as you suggested in your last answer:

    Code: Select all

    wget http://revpimodio.org/dnl/revpipyload_0.6.7-1_all.deb
    sudo dpkg -i revpipyload_0.6.7-1_all.deb
  4. I followed the steps here in order to set permissions etc. (I skipped the installation process I did above, of course)

I now established a lan connection between RasPi and RevPi (checked it using ping). On my RasPi I typed:

Code: Select all

pi@raspberrypi:~ $ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)                                                                                                                                                                                                                                  
[GCC 6.3.0 20170124] on linux                                                                                                                                                                                                                                                  
Type "help", "copyright", "credits" or "license" for more information.                                                                                                                                                                                                         
>>> import revpimodio2                                                                                                                                                                                                                              
>>> rpi = revpimodio2.RevPiNetIO("196.254.59.10", autorefresh=False) 
Unfortunately, this leads to an error:
Image

When I do

Code: Select all

rpi = revpimodio2.RevPiNetIO("196.254.59.10", autorefresh=True)
I get this this text scrolling very fast on my terminal.

I feel that I am a step closer to get it working, but I am sorry to have to ask you again: Do you have any clues what I still might be doing wrong?

Best
Frido
User avatar
RevPiModIO
KUNBUS
Posts: 322
Joined: 20 Jan 2017, 08:44
Answers: 0
Contact:

Re: communication between RevolutionPi and RaspberryPi using revpimodio

Post by RevPiModIO »

Hi Frido! (from my trip in Greek) :D

It looks much better, but strange :( It looks like your RaspberryPi is connecting the RevolutionPi successfully but can not exchange data with RevPiPyLoad.

Could you check the log files of RevPiPyload on the RevolutonPi? You can find them in: /var/log/revpipyload
Check the output of systemctl status revpipyload

And maybe activate more verbose logging via:
https://revpimodio.org/en/revpipyplc-2/ ... d/#logging

And could you please send me your /etc/revpi/config.rsc (piCtory configuration)? I like to simulate your system on my machine and test it with your RevPi setup!

It is a good idea to not use autorefresh for testing. But than you have to .readprocimg() an .writeprocimg() yourself to get or set the IO data on RevPi.

Code: Select all

pi@raspberrypi:~ $ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)                                                                                                                                                                                                                                  
[GCC 6.3.0 20170124] on linux                                                                                                                                                                                                                                                  
Type "help", "copyright", "credits" or "license" for more information.                                                                                                                                                                                                         
>>> import revpimodio2                                                                                                                                                                                                                              
>>> rpi = revpimodio2.RevPiNetIO("196.254.59.10", autorefresh=False)
rpi.readprocimg()
rpi.core.temperature
I think at the moment .readprocimg() would show another warning - so let's start with inspecting the log files...

I'm so sorry about that trouble, but I want to find that error! Our unit test with code coverage and tests against RevPiPyLoad does not report an error :(

Regards, Sven
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
User avatar
Frido
Posts: 53
Joined: 21 Apr 2018, 10:47
Answers: 0
Location: Stuttgart

Re: communication between RevolutionPi and RaspberryPi using revpimodio

Post by Frido »

Hello Sven,

thanks a lot for your help and for your will to find this error!

I looked for the log message in /var/log/revpipyload, which looks like this:

Code: Select all

2018-07-03 21:13:55 [ERROR   ] plc file does not exists /var/lib/revpipyload/program.py
Traceback (most recent call last):
  File "/usr/share/revpipyload/revpipyload.py", line 998, in <module>
    root.start()
  File "/usr/share/revpipyload/revpipyload.py", line 502, in start
    if self.xmlrpc >= 1:
TypeError: unorderable types: NoneType() >= int()
2018-07-03 23:55:17 [ERROR   ] plc file does not exists /var/lib/revpipyload/program.py
2018-07-04 00:04:02 [ERROR   ] plc file does not exists /var/lib/revpipyload/program.py
2018-07-04 00:06:17 [ERROR   ] dirty shutdown of connection
2018-07-04 00:06:17 [ERROR   ] dirty shutdown of connection
2018-07-04 00:06:17 [ERROR   ] dirty shutdown of connection
2018-07-04 00:06:18 [ERROR   ] dirty shutdown of connection
#...
#... (a hundret times more the same ERROR, several times per second)
2018-07-04 00:09:41 [ERROR   ] dirty shutdown of connection
1970-01-01 01:00:11 [ERROR   ] plc file does not exists /var/lib/revpipyload/program.py


When I did

Code: Select all

>>> import revpimodio2                                                                                                                                                                                                                              
>>> rpi = revpimodio2.RevPiNetIO("196.254.59.10", autorefresh=False)
rpi.readprocimg()
rpi.core.temperature

I could read to cpu temperature, the Inputbyte1 and even a VAR_EXTERNAL from my logiCAD3 programm, called RevPiLED, see the screenshot below. Although, the format of RevPiLED looks weird (it should be a BYTE). When I tried to call the local logiCAD variable i_zaehl, it could not be read (as expected). So, this seems to work! But there still are some runtimewarnings:
Image
(sorry for the bad quality, it is two screenshots sticked together)

Code: Select all

>>> rpi = revpimodio2.RevPiNetIO("196.254.59.10", autorefresh=True)
still produces the same behavior as in my previous post.

So, this is a big step closer! Basically three questions still remain:
  1. What is the cause of the runtimewarnings in the terminal screenshot above?
  2. What happens when I do

    Code: Select all

    >>> rpi = revpimodio2.RevPiNetIO("196.254.59.10", autorefresh=True)
    and why?
  3. What can I do to change the format of my external logiCAD variable RevPiLED? It looks like packed binary data, so I thought I can just do (in python3)

    Code: Select all

    >>> from struct import *
    a = rpi.io.RevPiLED.value
    >>> unpack('hhl', a)
    

    but this produces an error: unpack requires a bytes object of length 8. So maybe there is a simpler way?

If I can provide you with more error logs or anything else, please let me know.
Have a good time in Greece!

P.S: My logiCAD3 programm has been running all the time on the RevPi. It does only blink the onboard A1 LED on the RevPi and meassure the input voltage on one AIO module pin. I have a RevPi Core 3 with a AIO module on the right.
Also, I sent you the files you asked for. The above outputs were generated with the piCtory configuration I sent you. The logfiles from /var/log/revpipyload where saved before I did the testing above.
User avatar
RevPiModIO
KUNBUS
Posts: 322
Joined: 20 Jan 2017, 08:44
Answers: 0
Contact:

Re: communication between RevolutionPi and RaspberryPi using revpimodio

Post by RevPiModIO »

Hi Frido (Back from my trip)!

I think we are running into a timeout (Network / CPU load on the RevPi)...

First your questions:
1) The runtime warning will occur if the revpi does not response over the network fast enough.
2) If your instantiate the RevPiNetIO on the Raspberry Pi, the revpimodio module requests the pictory configuration over the network to build up all the io objects (the names of your IOs). This seems to work properly.
If you use autorefresh=True, the module will start a sync-thread to get the io data every 50 milliseconds. If you leave the parameter than you have to sync the io data by .readprocimg() (read) or .wirteprocimg() (write) manually. So it will not float the console with runtime warnings from the background task.
3) To read / write the LEDs, please use .core.A1 or .core.A2 (values are <class 'int'> 0 = off | 1 = green | 2 = red). The LEDs are in one byte and the module changes the bits for you, if you use (rpi.core.A1 = 1) and so on. That is the reason why struct.unpack does not work in your case, because rpi.io.RevPiLED.value is just one byte long)

I can not reproduce this error, so may you try the following things for me?

1) Could you try to instantiate the rpi on your Raspberry Pi like this? It is the monitoring mode an you just can READ all values, so the system will not WRITE values to the process image an interfere with logiCAD.

Code: Select all

import revpimodio2
rpi = revpimodio2.RevPiNetIO("169.254.59.10", monitoring=True)
rpi.readprocimg()
# and try to read rpi.io values

# sync again an try to read values
rpi.readprocimg()
2) Stop the logiCAD runtime (an your logiCAD program) on the RevolutionPi webpage and try your old code - or something like this - on your Raspberry Pi:

Code: Select all

import revpimodio2
rpi = revpimodio2.RevPiNetIO("169.254.59.10")
rpi.core.A1 = 1
rpi.writeprocimg()
rpi.core.A1 = 2
rpi.writeprocimg()
Does the LED A1 change from off to green to red?

The Revolution Pi an Raspberry Pi are still connected by wire, right?

Thank you,
Sven
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
User avatar
Frido
Posts: 53
Joined: 21 Apr 2018, 10:47
Answers: 0
Location: Stuttgart

Re: communication between RevolutionPi and RaspberryPi using revpimodio

Post by Frido »

Hey Sven,

thanks for your answer and the explanation, it helps a lot! I've been away far too long, sorry for that! Now I'm back and eager to get this working :)
  • You mentioned that the module will try to get io data every 50ms. I checked how fast a cycle on my RevPi is and found approx. 15Hz (66.6ms). Could this be a cause for the runtimewarnings?
  • Thanks to your answer I can now read the on-board LED status of the RevPi from the RasPi in python3 via rpi.core.A1. As mentioned, I have a logiCAD program running on the RevPi which blinks the A1-LED. But no matter at which time I do rpi.core.A1, it always returns 1. This is weird, isn't it? It should show 0 when the A1-LED is turned off.
  • So I executed the code you asked me to try.
    1. the monitoring mode doesn't produce an errors:
      Image
      For now, this seems to be a good solution for me, since I don't want to write at the moment. But in your blog you suggest that autorefresh should always be True. Would it therefore be a good idea to work with the monitoring mode?
    2. After this I stopped my logiCAD program on the RevPi and disabled the logiCAD service on the RevPi webpage. Also, I changed the aclplcslave.conf file to allow writing: (169.254.*.*,1). (It used to be 169.254.*.*,0).
      The "standard" mode does produce errors, again some runtimewarnings:
      Image
      The LED didn't change its color, it was turned off all along (since I stopped the logiCAD program)
    Yes, the RevPi and the RasPi are still connected by wire.
Sorry for getting back so late! But maybe you still have some ideas on this issue? I'd appreciate that very much!

Best
Frido
Post Reply