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



  • Hi,

    How can i reset (disable and enable) 1-wire bus in Neuron M503?

    Vesa


  • administrators

    At the moment this isn't possible via the evok API, as the 1Wire bus device is common to both Neuron and UniPi 1.1 (and resetting the 1Wire bus is not possible on the latter). We are considering adding this option to evok but it will require some changes to the way 1Wire is handled.

    It is possible to reset the bus by using the internal Modbus server, but this is somewhat insecure, non-trivial and requires editing systemd scripts.



  • @tomas_knot said in How to disable and enable the 1Wire bus (M503):

    It is possible to reset the bus by using the internal Modbus server, but this is somewhat insecure, non-trivial and requires editing systemd scripts.

    Insecure is my middle name :D

    So can you tell me how that can be done with Modbus server?

    Vesa


  • administrators

    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.



  • 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


  • administrators

    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.



  • 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


  • administrators

    @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)