[SOLVED] Plugin to play a song when button is pressed (door bell)

Max2Play Home Forums Max2Play on Raspberry PI [SOLVED] Plugin to play a song when button is pressed (door bell)

Viewing 3 posts - 1 through 3 (of 3 total)
  • 29. Juli 2015 at 13:57 #15233

    Hi,

    I’d like to implement a special door bell for our house which plays a specific MP3 (saved on SD card) when the door bell is pressed.
    I have experience with Arduino and I’m a software developer.

    The HiFiBerry Amp+ is exactly what I was looking for hardware wise. And the combination with Max2Play looks very promising.

    All I need to do know is to read an input pin on the Raspberry and start a song on Max2Play if the button is pressed.
    I had a look at your plugin developing video but it seems more like a webinterface tool than what I’d like to do.

    In a nutshell: Can you tell me if such a plugin/addition can be (easily) added to Max2Play?
    The very cool solution would be if I can change/choose the song via webinterface… which should be possible with the plugin developing as far as I can tell.

    thanks
    Soko

    • This topic was modified 9 years, 3 months ago by soko.
    • This topic was modified 7 years, 11 months ago by Christoph.
    30. Juli 2015 at 15:23 #15240

    Hi Soko,

    it is possible to connect your doorbell to some audiooutput with Max2Play. You basically need to write your own bash-script to play a MP3. Following things are needed:

    1. WiringPI library and a small script written in C that compiles on the PI to capture the event of the GPIO-PIN. This script should execute a Shell Script.

    This is an example of a C-Script, that captures a button event on the PI:

    //build with gcc -I. -o button button.c -lwiringPi
    #include <stdio.h>
    #include <string.h>
    #include <errno.h>
    #include <stdlib.h>
    #include <wiringPi.h>
    
    typedef enum { false, true } bool;
    static bool globalActive = false;
    static int globalCounter = 0;
    
    void myInterrupt(void) {
      int pin = digitalRead(2);
      if(pin == LOW && globalActive == false){
        globalActive = true;
        printf ("Button pressed\n");
      }else if(pin == HIGH && globalActive == true){
        printf ("Button Released\n");    
        int sysreturn = 0;    
        sysreturn = system("/opt/max2play/scriptyouwant.sh");    
        printf("System: %d", sysreturn);
        globalActive = false;
      }
    }
    
    int main (void)
    {
      wiringPiSetup () ;
    
      wiringPiISR (2, INT_EDGE_BOTH, &myInterrupt) ;
    
      for (;;) {
        sleep(1000);
      }
      return 0 ;
    }

    2. Shell-Script, that plays a MP3 with either mpc (command line MPD-Tool) or tells the squeezeboxserver (may be on another device in your network) via http-Get request to play a mp3 on one of your audioplayers (or on all). If you go big, use a squeezebox server and make use the command-line arguments like this in your Shell-Script (you may find the documentation for this command line interface in the squeezebox server interface after installation):

    
    # Example CLI-Call to Play current song via http-GET Request to Squeezebox Server on Max2Play 
    wget -q -O - "http://max2play:9000/status.html?p0=play&p1=preset_1.single&player=[MAC-Address URL-encoded]"
    

    Cheers,
    Stefan

    30. Juli 2015 at 15:33 #15241

    sweeet as!
    thx man for the source, i got the idea.
    it may take a while until im able to try it but i will report back for sure.
    thx
    Soko

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

Register here