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

    How to disable and enable the 1Wire bus (M503)

    Official EVOK API
    4
    23
    4895
    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.
    • T
      TomasKnot last edited by TomasKnot

      You will need to edit the following line in /etc/systemd/system/neurontcp.service:

      ExecStart=/opt/neuron-bin/neuron_tcp_server -p 502
      

      Change it to say:

      ExecStart=/opt/neuron-bin/neuron_tcp_server -p 502 -l 0.0.0.0
      

      instead.

      Afterwards you will need to send a Modbus write of 1 to coil 1001 and then another write of 0 to coil 1001. This can be done via a short python script using PyModbus, or through another TCP Modbus library, of which there is a wide variety. The Modbus server resides on port 502 with the ip of your Neuron (or 127.0.0.1 if you are doing it locally on the device). The Python script can then be run for some given condition.

      Vesa Kauppinen 1 Reply Last reply Reply Quote 0
      • Vesa Kauppinen
        Vesa Kauppinen last edited by

        It worked, thank you!

        In my case:

        ExecStart=/opt/neurontcp/neuron_tcp_server -p 502 -l 0.0.0.0
        

        So...this maneuver should fix any problems with 1-wire sensors if the fault is not on the connector(s) or the 8 port hub?

        Vesa

        1 Reply Last reply Reply Quote 0
        • T
          TomasKnot last edited by

          Hopefully yes, but it really shouldn't be necessary, it's unfortunate you have to use it.

          We'll try to add it to EVOK soon.

          1 Reply Last reply Reply Quote 0
          • R
            rob last edited by rob

            Hi,

            I just ran into the same problem as Vesa (one wire bus suddenly lost) and I can confirm that this procedure worked, but I had to reboot the rpi afterwards.

            I wonder if the change to /etc/systemd/system/neurontcp.service is really necessary, I initially tried polling the server without modifying the file and it seemed to work anyway.

            If someone else needs this, the only cli tool to poll the modbus server I found functioning on the rpi is this one:
            https://datapacket.dl.sourceforge.net/project/mblogic/MBLogic-All/MBLogic_All_Release-32/mblogic_all_2011-04-16.zip

            You will have to set the line endings in the file to linux style, before running:
            ./pollmb.py -p 502 -u 1 -f 5 -a 1001 -q 1 -d 1
            ./pollmb.py -p 502 -u 1 -f 5 -a 1001 -q 1 -d 0

            T 1 Reply Last reply Reply Quote 0
            • T
              TomasKnot @rob last edited by TomasKnot

              @rob
              It listens on 127.0.0.1 by default. The tool is written by us (you can find the source code at http://git.unipi.technology:3000/UniPi/neuron-modbus-tools, though note that not all of our software is opensourced) so I am quite confident it is necessary. It is of course not necessary if the client software is run locally via 127.0.0.1.

              That said, the Linux libmodbus library did contain a bug where this setting was not applied correctly and ignored instead. Somewhat humorously I believe that the bug is still there in the version used on the main Debian repository (we statically link against a newer version of the modbus library instead, which does not have this issue), and as a result quite a few IoT devices likely unintentionally listen on all IPs.

              (Incidentally this issue was uncovered by DavidCozens, to give proper credit)

              1 Reply Last reply Reply Quote 0
              • Vesa Kauppinen
                Vesa Kauppinen @TomasKnot last edited by

                Hi @tomasknot

                I'll come back to this topic again. Is it possible to do the same for Modbus in M503? I mean reset the bus (disable/enable)

                Br,
                Vesa

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

                  Hello @vesa-kauppinen,
                  yes, check our Modbus Registers Maps: https://kb.unipi.technology/files:products:02-neuron

                  For M503 it is coil 1001 - Enable/Disable 1Wire Bus

                  Best regards,
                  Martin

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

                    @martin-kudláček

                    Hi,

                    That's what we've done with 1-Wire and it works.

                    I mean, is it possible to do this same 'reset' for Modbus (RTU) itself? We sometimes lose a modbus device.

                    Br,
                    Vesa

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

                      Oh, sorry for the misunderstanding @vesa-kauppinen.

                      We have a functionality called Master Watch Dog (MWD). When enabled, the underlying HW will watch when the last communication happend. If it will be longer than the preset time, it will reboot itself. Now, this can be set per group in the PLC, and it will watch if the ModbusTCP server communicates with the given group. If not, the board will reboot. Similarly, this can be set on the extensions as well. If nothing communicates with the extension over ModbusRTU, the extension reboots itself.

                      This can be set via modbus. Look for the "Enable MWD" coil and "MWD timeout" register. The timeout is in miliseconds.

                      Best regards,
                      Martin

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

                        @martin-kudláček

                        Thank you!

                        Can you give a noob example of how to set 'MWD Enable' to 1 with pollmb.py?

                        Br,
                        Vesa

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

                          @vesa-kauppinen

                          Sorry, I've never used the pollmb.py. Would be the mbpoll example sufficient? You can install the mbpoll from our repository: apt update && apt install mbpoll

                          Martin

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

                            @martin-kudláček

                            Yes. If you can give mbpoll example that would be great!

                            :)

                            Br,
                            Vesa

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

                              @vesa-kauppinen

                              For Group 1 on M503

                              Verify the status of the MWD (if 0 - MWD disable, if 1 - MWD enabled but never rebooted, if 2 - MWD enabled and already rebooted):
                              mbpoll -m tcp -a 0 127.0.0.1 -0 -1 -r 6

                              Set the MWD timeout to 5000ms:
                              mbpoll -m tcp -a 0 127.0.0.1 -0 -r 1008 5000

                              Enable the MWD:
                              mbpoll -m tcp -a 0 127.0.0.1 -0 -r 6 1

                              Write the settings to the NVRAM:
                              mbpoll -m tcp -a 0 127.0.0.1 -0 -t 0 -r 1003 1

                              Verify the MWD by stopping the UniPi Modbus TCP server:
                              sudo systemctl stop unipitcp

                              The both lines of LEDs should blink for 1sec after the MWD timeout

                              Disable the MWD:
                              mbpoll -m tcp -a 0 127.0.0.1 -0 -r 6 0

                              Write the settings to the NVRAM:
                              mbpoll -m tcp -a 0 127.0.0.1 -0 -t 0 -r 1003 1

                              For Group 2 on M503
                              Use the MWD control register 114 instead of 6
                              Use the MWD timeout register 1108 instead of 1008
                              Use the Save configuration coil 1103 instead of 1003

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

                                @martin-kudláček

                                Thanks for the good instructions! After enabling MWD, setting timeout and writing the settings:

                                mbpoll -m tcp -a 0 127.0.0.1 -0 -1 -r 6
                                mbpoll 1.2-6 - FieldTalk(tm) Modbus(R) Master Simulator
                                Copyright (c) 2015 epsilonRT, All rights reserved.
                                This software is governed by the CeCILL license <http://www.cecill.info>
                                
                                Protocol configuration: Modbus TCP
                                Slave configuration...: address = [0]
                                                        start reference = 6, count = 1
                                Communication.........: 127.0.0.1, port 502, t/o 1.00 s, poll rate 1000 ms
                                Data type.............: 16-bit register, output (holding) register table
                                
                                -- Polling slave 0...
                                [6]:    3
                                

                                ...or...

                                mbpoll -m tcp -a 0 127.0.0.1 -0 -1 -r 114
                                mbpoll 1.2-6 - FieldTalk(tm) Modbus(R) Master Simulator
                                Copyright (c) 2015 epsilonRT, All rights reserved.
                                This software is governed by the CeCILL license <http://www.cecill.info>
                                
                                Protocol configuration: Modbus TCP
                                Slave configuration...: address = [0]
                                                        start reference = 114, count = 1
                                Communication.........: 127.0.0.1, port 502, t/o 1.00 s, poll rate 1000 ms
                                Data type.............: 16-bit register, output (holding) register table
                                
                                -- Polling slave 0...
                                [114]:  3
                                

                                What does that result (3) mean? Its not 0, 1 or 2.

                                Btw

                                sudo systemctl stop unipitcp
                                

                                should be

                                sudo systemctl stop neurontcp
                                

                                in Neuron M503...right??

                                Br,
                                Vesa

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

                                  Hi @vesa-kauppinen,
                                  sorry the value 3 is 1 + 2, which means board has MWD enabled and the MWD already rebooted the board.

                                  The service is called unipitcp, but in older packages it was called neurontcp. The service is the same for Neurons and Axons, so we renamed it to unipitcp to make it more clear.

                                  Best regards,
                                  Martin

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

                                    @martin-kudláček

                                    Aaaaa...of course :D

                                    But what about this: either 11 or 3

                                    root@residevice:~# mbpoll -m tcp -a 0 127.0.0.1 -0 -1 -r 6
                                    mbpoll 1.2-6 - FieldTalk(tm) Modbus(R) Master Simulator
                                    Copyright (c) 2015 epsilonRT, All rights reserved.
                                    This software is governed by the CeCILL license <http://www.cecill.info>
                                    
                                    Protocol configuration: Modbus TCP
                                    Slave configuration...: address = [0]
                                                            start reference = 6, count = 1
                                    Communication.........: 127.0.0.1, port 502, t/o 1.00 s, poll rate 1000 ms
                                    Data type.............: 16-bit register, output (holding) register table
                                    
                                    -- Polling slave 0...
                                    [6]:    11
                                    
                                    root@residevice:~# mbpoll -m tcp -a 0 127.0.0.1 -0 -1 -r 6
                                    mbpoll 1.2-6 - FieldTalk(tm) Modbus(R) Master Simulator
                                    Copyright (c) 2015 epsilonRT, All rights reserved.
                                    This software is governed by the CeCILL license <http://www.cecill.info>
                                    
                                    Protocol configuration: Modbus TCP
                                    Slave configuration...: address = [0]
                                                            start reference = 6, count = 1
                                    Communication.........: 127.0.0.1, port 502, t/o 1.00 s, poll rate 1000 ms
                                    Data type.............: 16-bit register, output (holding) register table
                                    
                                    -- Polling slave 0...
                                    [6]:    3
                                    
                                    root@residevice:~# mbpoll -m tcp -a 0 127.0.0.1 -0 -1 -r 6
                                    mbpoll 1.2-6 - FieldTalk(tm) Modbus(R) Master Simulator
                                    Copyright (c) 2015 epsilonRT, All rights reserved.
                                    This software is governed by the CeCILL license <http://www.cecill.info>
                                    
                                    Protocol configuration: Modbus TCP
                                    Slave configuration...: address = [0]
                                                            start reference = 6, count = 1
                                    Communication.........: 127.0.0.1, port 502, t/o 1.00 s, poll rate 1000 ms
                                    Data type.............: 16-bit register, output (holding) register table
                                    
                                    -- Polling slave 0...
                                    [6]:    11
                                    

                                    Br,
                                    Vesa

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

                                      @vesa-kauppinen

                                      Ok, this is a little bit tricky. The register has 16bits, and some of the bits represent some state or function.

                                      Bit 0: Set or read the status of the MWD
                                      Bit 1: The MWD rebooted the boarde
                                      other bits contain some debug information, which we haven't documented yet

                                      So value 11 in decimal is 0000 0000 0000 1011 in binary. The bit no. 0 (first from the right) is 1, which means MWD is enabled. The bit no. 1 (second from the right) is 1, which means MWD already rebooted the board. Other bits don't apply to you.

                                      You can "mask" the lowest 2 bits with boolean operation AND, typically with bit mask in hexadecimal representation:

                                      register_6 && 0x0003

                                      Or with binary mask:

                                      register_6 && 0b11

                                      I hope this helps you.
                                      Martin

                                      Vesa Kauppinen 2 Replies Last reply Reply Quote 0
                                      • Vesa Kauppinen
                                        Vesa Kauppinen @Martin Kudláček last edited by

                                        @martin-kudláček

                                        Okay. This clarified the case :)

                                        Thank you!

                                        Br,
                                        Vesa

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

                                          @martin-kudláček

                                          Hi...again

                                          One more stupid question: How do I reset 1-wire bus with mbpoll?

                                          I mean, how can i "convert" those commands:

                                          ./pollmb.py -p 502 -u 1 -f 5 -a 1001 -q 1 -d 1
                                          ./pollmb.py -p 502 -u 1 -f 5 -a 1001 -q 1 -d 0
                                          

                                          to mbpoll "format". I just don't understand how to read/write coils with mbpoll.

                                          Thank you!
                                          Vesa

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

                                            Hi @vesa-kauppinen,
                                            writing 1 to coil 1001:

                                            mbpoll -m tcp -a 0 127.0.0.1 -t 0 -0 -r 1001 1

                                            Writing 0:

                                            mbpoll -m tcp -a 0 127.0.0.1 -t 0 -0 -r 1001 0

                                            You can learn more from the quite detailed help of the mbpoll:

                                            mbpoll -h

                                            Regards,
                                            Martin

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