• Help With Sense Hat Python Script

    From Dr Stephen Strange@3:770/3 to All on Fri Dec 22 08:41:46 2023
    I have a Sense Hat and want to run this oython script at boot:

    from sense_hat import SenseHat
    from pydub import AudioSegment
    from pydub.playback import play

    song = AudioSegment.from_wav("/home/pi/redalert.wav")

    sense = SenseHat()

    x = 0.1
    y = 204,0,0
    z = 0,0,153
    y1 = 25,0,0
    z1 = 255,255,0

    while True:
    play(song)
    play(song)
    sense.show_message("!!! Intuder Alert ", x, y, z)

    Now if I boot the Pi and then run the script it runs fine and the sound
    plays.

    However if I use

    @reboot python3 /home/pi/intruder.py via a cron job, the message is
    displayed but no sound.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From The Natural Philosopher@3:770/3 to Dr Stephen Strange on Fri Dec 22 09:50:40 2023
    On 22/12/2023 08:41, Dr Stephen Strange wrote:
    I have a Sense Hat and want to run this oython script at boot:

    from sense_hat import SenseHat
    from pydub import AudioSegment
    from pydub.playback import play

    song = AudioSegment.from_wav("/home/pi/redalert.wav")

    sense = SenseHat()

    x = 0.1
    y = 204,0,0
    z = 0,0,153
    y1 = 25,0,0
    z1 = 255,255,0

    while True:
     play(song)
     play(song)
     sense.show_message("!!! Intuder Alert ", x, y, z)

    Now if I boot the Pi and then run the script it runs fine and the sound plays.

    However if I use

    @reboot python3 /home/pi/intruder.py via a cron job, the message is
    displayed but no sound.

    I think I had this issue. The permissions on sound channels are weird.
    I wanted the web server (user www-data) to play sounds - it wouldn't
    until I did something to it...

    OK I just logged in to that machine

    in /etc/group is this line:

    audio:x:29:me,www-data,pulse,root

    I suggest you add at least root and probably pulse to the audio group

    --
    The biggest threat to humanity comes from socialism, which has utterly
    diverted our attention away from what really matters to our existential survival, to indulging in navel gazing and faux moral investigations
    into what the world ought to be, whilst we fail utterly to deal with
    what it actually is.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Dr Stephen Strange@3:770/3 to Dr Stephen Strange on Fri Dec 22 13:55:58 2023
    Dr Stephen Strange wrote:
    The Natural Philosopher wrote:
    On 22/12/2023 08:41, Dr Stephen Strange wrote:
    I have a Sense Hat and want to run this oython script at boot:

    from sense_hat import SenseHat
    from pydub import AudioSegment
    from pydub.playback import play

    song = AudioSegment.from_wav("/home/pi/redalert.wav")

    sense = SenseHat()

    x = 0.1
    y = 204,0,0
    z = 0,0,153
    y1 = 25,0,0
    z1 = 255,255,0

    while True:
      play(song)
      play(song)
      sense.show_message("!!! Intuder Alert ", x, y, z)

    Now if I boot the Pi and then run the script it runs fine and the
    sound plays.

    However if I use

    @reboot python3 /home/pi/intruder.py via a cron job, the message is
    displayed but no sound.

    I think I had this issue.  The permissions on sound channels are
    weird. I wanted the web server (user www-data) to play sounds - it
    wouldn't until I did something to it...

    OK I  just logged in to that machine

    in /etc/group is this line:

    audio:x:29:me,www-data,pulse,root

    I suggest you add at least root and probably pulse to the audio group



    Hi - thanks for your help - tired that but still no sound

    That is *TRIED* but still no sound!!!

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Dr Stephen Strange@3:770/3 to The Natural Philosopher on Fri Dec 22 13:51:04 2023
    The Natural Philosopher wrote:
    On 22/12/2023 08:41, Dr Stephen Strange wrote:
    I have a Sense Hat and want to run this oython script at boot:

    from sense_hat import SenseHat
    from pydub import AudioSegment
    from pydub.playback import play

    song = AudioSegment.from_wav("/home/pi/redalert.wav")

    sense = SenseHat()

    x = 0.1
    y = 204,0,0
    z = 0,0,153
    y1 = 25,0,0
    z1 = 255,255,0

    while True:
      play(song)
      play(song)
      sense.show_message("!!! Intuder Alert ", x, y, z)

    Now if I boot the Pi and then run the script it runs fine and the
    sound plays.

    However if I use

    @reboot python3 /home/pi/intruder.py via a cron job, the message is
    displayed but no sound.

    I think I had this issue.  The permissions on sound channels are weird.
    I wanted the web server (user www-data) to play sounds - it wouldn't
    until I did something to it...

    OK I  just logged in to that machine

    in /etc/group is this line:

    audio:x:29:me,www-data,pulse,root

    I suggest you add at least root and probably pulse to the audio group



    Hi - thanks for your help - tired that but still no sound

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From The Natural Philosopher@3:770/3 to Dr Stephen Strange on Fri Dec 22 16:15:36 2023
    On 22/12/2023 13:55, Dr Stephen Strange wrote:
    Dr Stephen Strange wrote:
    The Natural Philosopher wrote:
    On 22/12/2023 08:41, Dr Stephen Strange wrote:
    I have a Sense Hat and want to run this oython script at boot:

    from sense_hat import SenseHat
    from pydub import AudioSegment
    from pydub.playback import play

    song = AudioSegment.from_wav("/home/pi/redalert.wav")

    sense = SenseHat()

    x = 0.1
    y = 204,0,0
    z = 0,0,153
    y1 = 25,0,0
    z1 = 255,255,0

    while True:
      play(song)
      play(song)
      sense.show_message("!!! Intuder Alert ", x, y, z)

    Now if I boot the Pi and then run the script it runs fine and the
    sound plays.

    However if I use

    @reboot python3 /home/pi/intruder.py via a cron job, the message is
    displayed but no sound.

    I think I had this issue.  The permissions on sound channels are
    weird. I wanted the web server (user www-data) to play sounds - it
    wouldn't until I did something to it...

    OK I  just logged in to that machine

    in /etc/group is this line:

    audio:x:29:me,www-data,pulse,root

    I suggest you add at least root and probably pulse to the audio group



    Hi - thanks for your help - tired that but still no sound

    That is *TRIED* but still no sound!!!

    Strange. You did reboot etc afterwards?

    Try making the script do a 'who am i' so you can see who is in fact the
    owning process.

    And look in the log files.

    Looking in stack overflow it seems that a 60 second sleep before
    executing the script may allow stuff to settle down, but you probably
    ought to be using systemd to start the script..e.g

    /usr/lib/systemd/system/intruder.service

    [Unit]
    Description=Intruder Server

    [Install]
    WantedBy=multi-user.target

    [Service]
    ExecStart=/bin/bash /home/you/yourscript.py
    Type=simple
    User=root
    Group=root
    WorkingDirectory=/home/you
    Restart=on-failure

    Put this in a file /usr/lib/systemd/system/intruder.service. Then run
    systemctl daemon-reload (once, and whenever you change intruder.service
    to tell systemd to re-read the configuration) and systemctl start intruder.service to start the e server.

    If that works as expected, you can use systemctl enable intruder.service
    to make sure it starts at boot.

    --
    The New Left are the people they warned you about.

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