• Python script run in Pi desktop terminal, but not by ssh terminal

    From RobH@3:770/3 to All on Tue Nov 10 17:40:45 2020
    I have a python script to run some leds, and I'm having a problem with it!
    When I ssh into my pi zero, then sudo python3 python script.py, it
    doesn't run, no leds are lit.
    But if I open a terminal in the pi desktop and run the same command
    line, it works and the leds light up.

    Anyone know why this happens.

    Thanks

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Vincent Coen@2:250/1 to RobH on Tue Nov 10 19:05:45 2020
    Hello RobH!

    Tuesday November 10 2020 17:40, you wrote to All:

    I have a python script to run some leds, and I'm having a problem with
    it! When I ssh into my pi zero, then sudo python3 python script.py, it doesn't run, no leds are lit.
    But if I open a terminal in the pi desktop and run the same command
    line, it works and the leds light up.

    Anyone know why this happens.

    Who owns the script.py and where is it ?


    Remember sudo takes root priv. and the directory so try :

    sudo python3 /home/pi/script.py or whater the user name is along with the correct python run command is.


    Vincent

    --- Mageia Linux v7.1 X64/Mbse v1.0.7.17/GoldED+/LNX 1.1.5-b20180707
    * Origin: Air Applewood, The Linux Gateway to the UK & Eire (2:250/1)
  • From RobH@3:770/3 to Vincent Coen on Tue Nov 10 20:08:09 2020
    On 10/11/2020 06:05, Vincent Coen wrote:
    Hello RobH!

    Tuesday November 10 2020 17:40, you wrote to All:

    > I have a python script to run some leds, and I'm having a problem with
    > it! When I ssh into my pi zero, then sudo python3 python script.py, it
    > doesn't run, no leds are lit.
    > But if I open a terminal in the pi desktop and run the same command
    > line, it works and the leds light up.

    > Anyone know why this happens.

    Who owns the script.py and where is it ?


    Remember sudo takes root priv. and the directory so try :

    sudo python3 /home/pi/script.py or whater the user name is along with the correct python run command is.


    Vincent


    I ssh'd into my pi zero, then I created the script with : sudo nano
    script.py then copied some other python script into the new script.py.
    I then ran sudo python3 script.py from within the directory the said
    script is in, which is the Downloads directory.
    Nothing happens, no errors, no leds lit.

    If I open a terminal window on the pi desktop and run the exact same
    sudo python3 script.py, it runs and the leds light up

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Chris Green@3:770/3 to RobH on Tue Nov 10 19:38:00 2020
    RobH <rob@despammer.com> wrote:
    I have a python script to run some leds, and I'm having a problem with it! When I ssh into my pi zero, then sudo python3 python script.py, it
    doesn't run, no leds are lit.
    But if I open a terminal in the pi desktop and run the same command
    line, it works and the leds light up.

    Anyone know why this happens.

    Because you have written some very clever code that differentiates
    between a local login and an ssh login! :-) :-)

    More seriously I can't think of any obvious answer, we need more
    information, or at least *you* need more information. Put some print statements around the code that turns the LEDs and see if it's reached
    in bith cases.

    --
    Chris Green
    ·

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Dennis Lee Bieber@3:770/3 to All on Tue Nov 10 15:28:24 2020
    On Tue, 10 Nov 2020 20:08:09 +0000, RobH <rob@despammer.com> declaimed the following:

    I ssh'd into my pi zero, then I created the script with : sudo nano
    script.py then copied some other python script into the new script.py.
    I then ran sudo python3 script.py from within the directory the said
    script is in, which is the Downloads directory.
    Nothing happens, no errors, no leds lit.

    My first question is: WHY use "sudo". Isn't the regular user account a member of a group that has access to GPIO?

    pi@rpi3bplus-1:~$ groups
    pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio
    i2c spi

    My second would be: Show us the CODE AND the commands you are performing... Don't just "say" what you did -- cut&paste directly from the
    SSH console into a message.


    If I open a terminal window on the pi desktop and run the exact same
    sudo python3 script.py, it runs and the leds light up

    Again -- show us (cut&paste) the exact command sequence being performed.

    However...

    pi@rpi3bplus-1:~/Downloads$ groups
    pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio
    i2c spi
    pi@rpi3bplus-1:~/Downloads$ sudo groups
    root
    pi@rpi3bplus-1:~/Downloads$

    ... the root user (sudo) does NOT appear to have access to GPIO, SPI, I2C,
    etc.

    Without seeing the script one can not tell if errors are being swallowed or just being ignored.


    --
    Wulfraed Dennis Lee Bieber AF6VN
    wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From RobH@3:770/3 to Chris Green on Tue Nov 10 20:22:33 2020
    On 10/11/2020 19:38, Chris Green wrote:
    RobH <rob@despammer.com> wrote:
    I have a python script to run some leds, and I'm having a problem with it! >> When I ssh into my pi zero, then sudo python3 python script.py, it
    doesn't run, no leds are lit.
    But if I open a terminal in the pi desktop and run the same command
    line, it works and the leds light up.

    Anyone know why this happens.

    Because you have written some very clever code that differentiates
    between a local login and an ssh login! :-) :-)

    More seriously I can't think of any obvious answer, we need more
    information, or at least *you* need more information. Put some print statements around the code that turns the LEDs and see if it's reached
    in bith cases.


    Putting
    print.pixels.fill((0, 0, 0))
    sleep(2)
    print.pixels.fill((0, 0, 255))
    print.pixels.show()

    produces this error:
    File "ledstest.py", line 6, in <module>
    print.pixels.fill((0, 0, 0))
    AttributeError: 'builtin_function_or_method' object has no attribute
    'pixels'

    But as I said, the script runs perfectly well in a terminal on the pi
    desktop

    Thanks

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From RobH@3:770/3 to Dennis Lee Bieber on Tue Nov 10 20:43:31 2020
    On 10/11/2020 20:28, Dennis Lee Bieber wrote:
    On Tue, 10 Nov 2020 20:08:09 +0000, RobH <rob@despammer.com> declaimed the following:

    I ssh'd into my pi zero, then I created the script with : sudo nano
    script.py then copied some other python script into the new script.py.
    I then ran sudo python3 script.py from within the directory the said
    script is in, which is the Downloads directory.
    Nothing happens, no errors, no leds lit.

    My first question is: WHY use "sudo". Isn't the regular user account a member of a group that has access to GPIO?

    pi@rpi3bplus-1:~$ groups
    pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi

    My second would be: Show us the CODE AND the commands you are performing... Don't just "say" what you did -- cut&paste directly from the SSH console into a message.


    If I open a terminal window on the pi desktop and run the exact same
    sudo python3 script.py, it runs and the leds light up

    Again -- show us (cut&paste) the exact command sequence being performed.

    However...

    pi@rpi3bplus-1:~/Downloads$ groups
    pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi
    pi@rpi3bplus-1:~/Downloads$ sudo groups
    root
    pi@rpi3bplus-1:~/Downloads$

    ... the root user (sudo) does NOT appear to have access to GPIO, SPI, I2C, etc.

    Without seeing the script one can not tell if errors are being swallowed or just being ignored.



    This is the script:

    pi@raspberrypi:~/Downloads $ sudo nano ledstest.py

    import board
    import neopixel
    from time import sleep

    pixels = neopixel.NeoPixel(board.D18, 56, brightness =1)
    pixels.fill((0, 0, 0))
    sleep(2)
    pixels.fill((0, 0, 255))
    pixels.show()

    pi@raspberrypi:~/Downloads $ sudo python3 ledstest.py pi@raspberrypi:~/Downloads $

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From RobH@3:770/3 to RobH on Tue Nov 10 20:48:51 2020
    On 10/11/2020 20:43, RobH wrote:
    On 10/11/2020 20:28, Dennis Lee Bieber wrote:
    On Tue, 10 Nov 2020 20:08:09 +0000, RobH <rob@despammer.com> declaimed
    the
    following:

    I ssh'd into my pi zero, then I created the script with : sudo nano
    script.py then copied some other python script into the new script.py.
    I then ran sudo python3 script.py from within the directory the said
    script is in, which is the Downloads directory.
    Nothing happens, no errors, no leds lit.

        My first question is: WHY use "sudo". Isn't the regular user
    account a
    member of a group that has access to GPIO?

    pi@rpi3bplus-1:~$ groups
    pi adm dialout cdrom sudo audio video plugdev games users input netdev
    gpio
    i2c spi

        My second would be: Show us the CODE AND the commands you are
    performing... Don't just "say" what you did -- cut&paste directly from
    the
    SSH console into a message.


    If I open a terminal window on the pi desktop and run the exact same
    sudo python3 script.py, it runs and the leds light up

        Again -- show us (cut&paste) the exact command sequence being
    performed.

        However...

    pi@rpi3bplus-1:~/Downloads$ groups
    pi adm dialout cdrom sudo audio video plugdev games users input netdev
    gpio
    i2c spi
    pi@rpi3bplus-1:~/Downloads$ sudo groups
    root
    pi@rpi3bplus-1:~/Downloads$

    ... the root user (sudo) does NOT appear to have access to GPIO, SPI,
    I2C,
    etc.

        Without seeing the script one can not tell if errors are being
    swallowed or just being ignored.



    This is the script:

    pi@raspberrypi:~/Downloads $ sudo nano ledstest.py

    import board
    import neopixel
    from time import sleep

    pixels = neopixel.NeoPixel(board.D18, 56, brightness =1)
    pixels.fill((0, 0, 0))
    sleep(2)
    pixels.fill((0, 0, 255))
    pixels.show()

    pi@raspberrypi:~/Downloads $ sudo python3 ledstest.py pi@raspberrypi:~/Downloads $


    pi@raspberrypi:~/Downloads $ groups
    pi adm dialout cdrom sudo audio video plugdev games users input netdev
    gpio i2c spi
    pi@raspberrypi:~/Downloads $ sudo groups
    root
    pi@raspberrypi:~/Downloads $

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From RobH@3:770/3 to RobH on Tue Nov 10 22:57:47 2020
    On 10/11/2020 20:22, RobH wrote:
    On 10/11/2020 19:38, Chris Green wrote:
    RobH <rob@despammer.com> wrote:
    I have a python script to run some leds, and I'm having a problem
    with it!
    When I ssh into my pi zero, then sudo python3 python script.py, it
    doesn't run, no leds are lit.
    But if I open a terminal in the pi desktop and run the same command
    line, it works and the leds light up.

    Anyone know why this happens.

    Because you have written some very clever code that differentiates
    between a local login and an ssh login! :-) :-)

    More seriously I can't think of any obvious answer, we need more
    information, or at least *you* need more information.  Put some print
    statements around the code that turns the LEDs and see if it's reached
    in bith cases.


    Putting
    print.pixels.fill((0, 0, 0))
    sleep(2)
    print.pixels.fill((0, 0, 255))
    print.pixels.show()

    produces this error:
     File "ledstest.py", line 6, in <module>
        print.pixels.fill((0, 0, 0))
    AttributeError: 'builtin_function_or_method' object has no attribute
    'pixels'

    But as I said, the script runs perfectly well in a terminal on the pi
    desktop

    Thanks


    It was the led strip at fault, as I found after I tried another strip
    which did light up when I ran the script.

    Thanks

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Dennis Lee Bieber@3:770/3 to All on Tue Nov 10 21:17:46 2020
    On Tue, 10 Nov 2020 20:48:51 +0000, RobH <rob@despammer.com> declaimed the following:

    On 10/11/2020 20:43, RobH wrote:
    pi@raspberrypi:~/Downloads $ sudo nano ledstest.py

    I'll repeat my previous question: WHY are you using SUDO?

    Develop using the default account, and only use SUDO when the system tells you that you don't have privileges to perform some action. (Okay --
    it seems Adafruits neopixel library does claim it needs to be run as root; likely due to the need to set up DMA, but editing the script sure doesn't
    need to be done using "sudo")


    import board
    import neopixel
    from time import sleep

    pixels = neopixel.NeoPixel(board.D18, 56, brightness =1)

    That's a pretty long Neopixel strip, if it has 56 pixels on it.

    pixels.fill((0, 0, 0))
    sleep(2)

    The above fill appears to be a do nothing as you don't issue a .show() {You are filling the pixel array with all-OFF, sleeping 2 seconds, and
    then...

    pixels.fill((0, 0, 255))
    pixels.show()

    ... filling the array with all-BLUE, then issuing a .show() command to send these to the Neopixel strip. You also do not have anything delaying the
    program after this .show().}

    The Neopixel library has a built-in clean-up method which sets everything back to OFF and .show() it when your "pixels" object is garbage collected, and that occurs immediately after your pixels.show() statement, since the program itself ends at that point.

    And to save some traffic...

    File "ledstest.py", line 6, in <module>
    print.pixels.fill((0, 0, 0))
    AttributeError: 'builtin_function_or_method' object has no attribute
    'pixels'

    Of course that fails. print() is a function which takes as argument the item to be printed.

    print(pixels.fill((0, 0, 0)))

    Note that if the .fill() call does not return any status, this will print

    None

    Try running in interactive mode (entering each line at the prompt, as shown here. NOTE: I don't have a Neopixel strip attached, I'd have to hook
    an oscilloscope to D18 to see if anything happens -- more than I want to
    try at this moment.

    =-=-=
    pi@rpi3bplus-1:~$ sudo python3
    Python 3.7.3 (default, Jul 25 2020, 13:03:44)
    [GCC 8.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    import board
    import neopixel
    import time

    pixels = neopixel.NeoPixel(board.D18, 56, brightness = 1)
    pixels.fill((0, 0, 0))
    time.sleep(2)
    pixels.fill((0, 0, 255))
    pixels.show()
    time.sleep(2)
    exit()
    pi@rpi3bplus-1:~$
    =-=-=


    --
    Wulfraed Dennis Lee Bieber AF6VN
    wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From RobH@3:770/3 to Dennis Lee Bieber on Wed Nov 11 12:06:01 2020
    On 11/11/2020 02:17, Dennis Lee Bieber wrote:
    On Tue, 10 Nov 2020 20:48:51 +0000, RobH <rob@despammer.com> declaimed the following:

    On 10/11/2020 20:43, RobH wrote:
    pi@raspberrypi:~/Downloads $ sudo nano ledstest.py

    I'll repeat my previous question: WHY are you using SUDO?

    Because I have always done since I started using a Pi.

    Develop using the default account, and only use SUDO when the system tells you that you don't have privileges to perform some action. (Okay --
    it seems Adafruits neopixel library does claim it needs to be run as root; likely due to the need to set up DMA, but editing the script sure doesn't need to be done using "sudo")


    import board
    import neopixel
    from time import sleep

    pixels = neopixel.NeoPixel(board.D18, 56, brightness =1)

    That's a pretty long Neopixel strip, if it has 56 pixels on it.

    No, it isn't, that's a short one by comparison to the ones with either
    144 or 300 leds


    pixels.fill((0, 0, 0))
    sleep(2)

    The above fill appears to be a do nothing as you don't issue a .show() {You are filling the pixel array with all-OFF, sleeping 2 seconds, and then...

    pixels.fill((0, 0, 255))
    pixels.show()

    ... filling the array with all-BLUE, then issuing a .show() command to send these to the Neopixel strip. You also do not have anything delaying the program after this .show().}

    The Neopixel library has a built-in clean-up method which sets everything back to OFF and .show() it when your "pixels" object is garbage collected, and that occurs immediately after your pixels.show() statement, since the program itself ends at that point.

    And to save some traffic...

    File "ledstest.py", line 6, in <module>
    print.pixels.fill((0, 0, 0))
    AttributeError: 'builtin_function_or_method' object has no attribute
    'pixels'

    Of course that fails. print() is a function which takes as argument the item to be printed.

    print(pixels.fill((0, 0, 0)))

    Note that if the .fill() call does not return any status, this will print

    None

    Try running in interactive mode (entering each line at the prompt, as shown here. NOTE: I don't have a Neopixel strip attached, I'd have to hook
    an oscilloscope to D18 to see if anything happens -- more than I want to
    try at this moment.

    =-=-=
    pi@rpi3bplus-1:~$ sudo python3
    Python 3.7.3 (default, Jul 25 2020, 13:03:44)
    [GCC 8.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    import board
    import neopixel
    import time

    pixels = neopixel.NeoPixel(board.D18, 56, brightness = 1)
    pixels.fill((0, 0, 0))
    time.sleep(2)
    pixels.fill((0, 0, 255))
    pixels.show()
    time.sleep(2)
    exit()
    pi@rpi3bplus-1:~$
    =-=-=



    Alright, the script needs some editing or whatever, but it was something
    I used to see if it would light the leds up without errors, which it did initially.

    Anyway as per my post lower down, the problem was the actual led strip
    and nothing else. I tried a 144 leds strip and it worked fine.

    Thanks

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)