• Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Connecting 2 unipi controllers over RS485

    UniPi Neuron Series
    3
    8
    125
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Martijn Hemeryck
      Martijn Hemeryck last edited by

      I currently have a setup where all my input switches are on a single unipi controller and all the relay outputs are on another. The connection between the 2 of these is done with an automation in home assistant, using MQTT.

      So, pushing a push button to switching on the light means:

      1. push button triggers MQTT event (on a neuron L303)
      2. MQTT event is picked up by home assistant (on a dedicated x86 computer) and send out another MQTT event
      3. MQTT event triggers a relay toggle (on a neuron L403).

      While this has been working OK for me, I have been thinking about some redundancy and would like the overall basic system to still working without home assistant and without a network connection.

      I was reading https://www.unipi.technology/news/the-four-ways-to-set-up-your-automation-project-257 the other day, and I did notice the possiblity to link some unipi controllers directly using RS485 / modbus RTU. My idea would be that a button press on the L303 would then just directly send a command over modbus RTU to the L403. Apart from that I would also still keep the MQTT interface, such that home assistant can still work with it.

      Up to now however, I haven't been able to connect the 2 together.

      What I did try:

      1. wiring; I did use 2 wires from a CAT6 ethernet cable and put these into the RS485A / B connectors
      2. DIP switches: I read somewhere these need to be on such that the line is properly terminated (tried actually in a bunch of on / off configurations)
      3. software: the evok interface shows me the serial 1.01 ports for both controllers is 19200 baud rate, 8 bits, no parity stop bit 1
      4. I did try reading data from the serial line using mbpoll, e.g.
      sudo mbpoll -t 0 -m rtu -P none -a 15 -b 19200 -r 100 -c 20 /dev/extcomm/1/0 
      mbpoll 1.4-12 - FieldTalk(tm) Modbus(R) Master Simulator
      Copyright © 2015-2019 Pascal JEAN, https://github.com/epsilonrt/mbpoll
      This program comes with ABSOLUTELY NO WARRANTY.
      This is free software, and you are welcome to redistribute it
      under certain conditions; type 'mbpoll -w' for details.
      
      Protocol configuration: Modbus RTU
      Slave configuration...: address = [15]
                              start reference = 100, count = 20
      Communication.........: /dev/extcomm/1/0,      19200-8N1 
                              t/o 1.00 s, poll rate 1000 ms
      Data type.............: discrete output (coil)
      
      -- Polling slave 15... Ctrl-C to stop)
      Read discrete output (coil) failed: Connection timed out
      -- Polling slave 15... Ctrl-C to stop)
      Read discrete output (coil) failed: Connection timed out
      ^C--- /dev/extcomm/1/0 poll statistics ---
      2 frames transmitted, 0 received, 2 errors, 100.0% frame loss
      

      Any clue what I'm doing wrong?

      1 Reply Last reply Reply Quote 0
      • K
        knebb last edited by

        Hi,

        I have no experience with the RS485 but I did some reading according addressing.

        You can choose either hardware- or software-addressing. If you want to use software you should set all DIP switches to 0. Otherwiese you use hardware-switching (which seems to be recommended for beginning).

        I do not know if you have seen this document but I guess is will help: Link.

        Good luck, pleas update if you have a solution (I might use multiple devices in future, too).

        Otherwise have you considered using network with MQTT between these two devices? Seems to be much easier as both already are configured to use MQTT. Simply subscribe to the channel and it should work, right?

        Greetings

        /KNEBB

        1 Reply Last reply Reply Quote 0
        • Martijn Hemeryck
          Martijn Hemeryck last edited by

          Thanks for your feedback.

          You can choose either hardware- or software-addressing. If you want to use software you should set all DIP switches to 0. Otherwiese you use hardware-switching (which seems to be recommended for beginning).

          I do not know if you have seen this document but I guess is will help

          The document you point to is about addressing an extension module from a controller module. My use case is about 2 controllers talking directly to each other. It also has a single DIP switch, but I guess this is to enable the internal terminal resistor (which I probably should do).

          Otherwise have you considered using network with MQTT between these two devices?

          Yes, that is actually my current setup. Have a look at https://blog.mhemeryck.com/2021-06-15/home_automation_why and related posts :)

          The reason why I would like to connect the 2 modules directly together is that I would not need a network connection and no other software in between. While that setup works OK for me, I think it would be nice to have a direct connection as a fallback.

          Martin Kudláček 1 Reply Last reply Reply Quote 0
          • Martin Kudláček
            Martin Kudláček @Martijn Hemeryck last edited by Martin Kudláček

            Hi @Martijn-Hemeryck,
            it is unclear for me what you have configured on the "other" side. On one side, you are using mbpoll, which is correct - it acts as a Modbus master. On the "other" side, there has to be some software running, which will act as a ModbusRTU slave device.

            As I know you use Evok, then the problem most probably lies directly there - the Evok doesn't (and cannot as of now) act as a Modbus slave. Only as a Modbus master.

            It is a bit unusual setup, but pyModbus is able to act both as a master and slave. Be aware of the limitation of the RS485 bus as it can have only one master - one initiator of the communication.

            And another caveat. Our RS485 have so-called biasing resistors. Those stabilize the bus when no device is communicating otherwise the lines would be just dangling in the air susceptible to pick of EMI noise. From a certain batch of PLC (ca 2 years ago) we have started to add these resistors.
            The downside of this permanent biasing resistors is, that they should be present only once on the same bus. And since both PLC have them, the direct communication over RS485 doesn't have to work in some cases because of that. Luckily enough, the RS485 allows all sorts of unusual stuff hapening (and generating) so it might work for you.

            Hope that sheds more light on the matter.
            Martin

            Martijn Hemeryck 1 Reply Last reply Reply Quote 0
            • Martijn Hemeryck
              Martijn Hemeryck @Martin Kudláček last edited by

              @Martin-Kudláček said in Connecting 2 unipi controllers over RS485:

              it is unclear for me what you have configured on the "other" side. On one side, you are using mbpoll, which is correct - it acts as a Modbus master. On the "other" side, there has to be some software running, which will act as a ModbusRTU slave device.

              Ah indeed, I figured that there would already be some modbus client on the other end.

              I will have a look at if it's possible then have such a client application using pymodbus as you mentioned.

              It's just because of this article https://www.unipi.technology/news/the-four-ways-to-set-up-your-automation-project-257 (option 3). Perhaps this is a setup which is supported with mervis?

              As for the resistors: I did notice a DIP switch on both my unipi controllers -- I assume these are related to enabling these resistors? And if so, I should only toggle them once (preferably on my "slave" device, since it should be the last in the series?)

              Martin Kudláček 1 Reply Last reply Reply Quote 0
              • Martin Kudláček
                Martin Kudláček @Martijn Hemeryck last edited by

                Hi @Martijn-Hemeryck,
                the article comes from the era when the resistors hasn't been present. But you can still use it now.

                The Mervis has ability to act as a Modbus master (client) and Modbus slave (server). More on that can be found in our KB: https://kb.unipi.technology/en:sw:01-mervis:setting-modbus-server-hidden

                The DIP switch is for engaging the terminator - a 120ohm resistor between RS485-A and RS485-B. The biasing resistors are two - one connects the 5V to RS485-A and the second connects RS485-B to the ground. Both biasing resistors are fixed and cannot be unplugged neither by HW DIP switch, nor SW configuration

                Martijn Hemeryck 1 Reply Last reply Reply Quote 0
                • Martijn Hemeryck
                  Martijn Hemeryck @Martin Kudláček last edited by

                  Small update: I can confirm a connection between the two unit if I run a modbus server on the slave device; setup:

                  • slave device: run https://github.com/riptideio/pymodbus/blob/731b080df0d277f0c6c32c949667a24a69a6bd7b/examples/common/synchronous_server.py
                  • master device: mbpoll -t 0 -m rtu -P none -a 100 -b 19200 /dev/ttyNS0

                  (sidenote: I first tried the asyncio version, but still had some bug in it ... https://github.com/riptideio/pymodbus/blob/731b080df0d277f0c6c32c949667a24a69a6bd7b/examples/common/asyncio_server.py)

                  It's not doing anything useful atm, but I can see both master and slave pinging back to each other!

                  1 Reply Last reply Reply Quote 0
                  • Martijn Hemeryck
                    Martijn Hemeryck last edited by

                    Small update: check out my blog for the solution I did create https://blog.mhemeryck.com/2021-11-16/modbusbackup

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post