WOL Magic Packet per LIRC

Heute ist Stammtischzeit:
Jeden Donnerstag 20:30 Uhr hier im Chat.
Wer Lust hat, kann sich gerne beteiligen. ;)
  • Moin.

    Ich beziehe mich auf folgenden Thread.

    Ich bin leider sehr unbedarft was Python angeht. Arbeite an einem Projekt mit dem Raspberry Pi Modell B. Dafür benötige ich ein Script, das ein WOL Magic Packet an meinen Homeserver schickt wenn ich auf meiner IR Fernbedienung eine bestimmte Taste drücke. Wichtig wäre auch das vorher (per Ping?!) angefragt wird ob der Server nicht vielleicht schon WAKE ist. Ich möchte auch mit LED´s arbeiten die ein optisches Feedback geben. Sprich z.B. ; Rote LED für IR Befehl empfangen. Grüne LED für WOL geschickt. Gelbe LED für Server ist bereits WAKE. Die LED´s und den IR Empfänger anschliessen bekomme ich ja noch hin...

    Ich habe mit LIRC schon etwas experimentiert. Ich empfange auch IR Befehle von meiner Fernbedienung. Schaffe es aber nicht, dass der (richtige) Befehlt dann das besagte Script ausführt...

    I habe mir den alten Thread und die dort enthaltenen Links angeschaut. Nun werde ich daraus aber leider nicht ganz schlau. Brauche da etwas Starthilfe beim Aufbau des Scripts. Wenn mir hier jemand dabei helfen könnte wäre das sehr cool!

    • Offizieller Beitrag

    Hast du denn die PYthon bindings für Lirc schon installiert? Wenn nein fangen wir mit

    Code
    sudo apt-get install python-pip
    sudo pip install python-lirc

    an.

    Dann machst du ne python console auf (python, ENTER) und tipps folgendes

    Code
    import lirc
    sockid = lirc.init("myprogram")
    lirc.nextcode()  # Danach die gewünschte Taste auf der FB drücken
    lirc.deinit()

    Nach dem Tastendruck sollte eine Zeile in der console erscheinen, diese postet du dann hier.

  • Ich glaube irgendwas fehlt noch ...

    Python 2.7.3 (default, Mar 18 2014, 05:13:23)
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import lirc
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ImportError: No module named lirc
    >>> sockid = lirc.init("myprogram")
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    NameError: name 'lirc' is not defined
    >>> lirc.nextcode() # Danach die gewünschte Taste auf der FB drücken
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    NameError: name 'lirc' is not defined
    >>> lirc.deinit()

    und

    cat ~/.lircrc
    cat: /home/pi/.lircrc: Datei oder Verzeichnis nicht gefunden

    Bei "mode2 -d /dev/lirc0" bekomme ich aber was empfangen.

    • Offizieller Beitrag

    Hmm, es kam doch schon dem ersten Befehl ne Fehlermeldung, welchen sinn hat es da stumpf weiter zu tippen? Und wenn du das schon ignorierst, dann vermute ich, dass bei der Installation von python-lirc auch was schief gegnagen ist, sonst würde er nicht "no module named lirc" sagen. ;)

  • Stimmt! Ist mir beim erstmal nicht aufgefallen...

    sudo pip install python-lirc
    Downloading/unpacking python-lirc
    Running setup.py egg_info for package python-lirc

    Installing collected packages: python-lirc
    Running setup.py install for python-lirc
    building 'lirc' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/lirc/ -I/usr/include/python2.7 -c lirc/lirc.c -o build/temp.linux-armv6l-2.7/lirc/lirc.o
    lirc/lirc.c:4:20: fatal error: Python.h: Datei oder Verzeichnis nicht gefunden
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/home/pi/build/python-lirc/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-JJ_Aeg-record/install-record.txt:
    running install

    running build

    running build_ext

    building 'lirc' extension

    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/lirc/ -I/usr/include/python2.7 -c lirc/lirc.c -o build/temp.linux-armv6l-2.7/lirc/lirc.o

    lirc/lirc.c:4:20: fatal error: Python.h: Datei oder Verzeichnis nicht gefunden

    compilation terminated.

    error: command 'gcc' failed with exit status 1

    ----------------------------------------
    Command /usr/bin/python -c "import setuptools;__file__='/home/pi/build/python-lirc/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-JJ_Aeg-record/install-record.txt failed with error code 1 in /home/pi/build/python-lirc
    Storing complete log in /root/.pip/pip.log

  • Immer noch Fehler :
    sudo pip install python-lirc
    Downloading/unpacking python-lirc
    Running setup.py egg_info for package python-lirc

    Installing collected packages: python-lirc
    Running setup.py install for python-lirc
    building 'lirc' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/lirc/ -I/usr/include/python2.7 -c lirc/lirc.c -o build/temp.linux-armv6l-2.7/lirc/lirc.o
    lirc/lirc.c:238:30: fatal error: lirc/lirc_client.h: Datei oder Verzeichnis nicht gefunden
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/home/pi/build/python-lirc/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-616WUs-record/install-record.txt:
    running install

    running build

    running build_ext

    building 'lirc' extension

    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/lirc/ -I/usr/include/python2.7 -c lirc/lirc.c -o build/temp.linux-armv6l-2.7/lirc/lirc.o

    lirc/lirc.c:238:30: fatal error: lirc/lirc_client.h: Datei oder Verzeichnis nicht gefunden

    compilation terminated.

    error: command 'gcc' failed with exit status 1

    ----------------------------------------
    Command /usr/bin/python -c "import setuptools;__file__='/home/pi/build/python-lirc/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-616WUs-record/install-record.txt failed with error code 1 in /home/pi/build/python-lirc
    Storing complete log in /root/.pip/pip.log

    EDIT:

    sudo apt-get install liblircclient-dev

    Hat geholfen.

    Einmal editiert, zuletzt von DerGorgon (9. Oktober 2014 um 21:17)

  • Erste Zeile im Python geht jetzt aber dann kommt wieder ein Fehler...

    python
    Python 2.7.3 (default, Mar 18 2014, 05:13:23)
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import lirc
    >>> sockid = lirc.init("myprogram")
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "lirc.pyx", line 122, in lirc.init (lirc/lirc.c:1289)
    lirc.InitError: Unable to initialise lirc (socket was -1 from C library).

    • Offizieller Beitrag

    Na, macht das nicht spass? :) Wir hangeln uns von einem Fehler zum nächsten
    Die doku sagt:

    Dann kopier den Text mal rein und schau mal nach ob der Fehler immer noch kommt.

    btw. Ich hab das auch noch nie gemacht, du bist also nicht alleine ;)

  • ALSO... Ich habe eine lircd.conf erstellt! Hatte ich schon vorher, nur hat er die im falschen Verzeichnis abgelegt. Die habe ich dann nach /etc/lirc/lircd.conf kopiert. Nun startet LIRC auch nach einem reboot endlich!

    Wenn ich deine Zeilen eingebe kommt :

    python
    Python 2.7.3 (default, Mar 18 2014, 05:13:23)
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import lirc
    >>> sockid = lirc.init("myprogram")
    >>> lirc.nextcode() # Danach die gewünschte Taste auf der FB drücken
    []
    >>> lirc.deinit()

    Hilft dir das?! :)

    EDIT:
    Ich habe ein bisschen mit google gesucht und es empfängt jetzt schonmal "MEINE TASTE" ...

    Mit dem Kommando : irw
    kommt dann :

    0000000000000001 00 KEY_POWER /home/pi/lircd.conf
    0000000000000001 00 KEY_POWER /home/pi/lircd.conf
    0000000000000001 01 KEY_POWER /home/pi/lircd.conf
    0000000000000001 02 KEY_POWER /home/pi/lircd.conf
    0000000000000001 03 KEY_POWER /home/pi/lircd.conf

    Einmal editiert, zuletzt von DerGorgon (9. Oktober 2014 um 22:10)

  • Klar.

    cat /etc/lirc/lircd.conf

    # Please make this file available to others
    # by sending it to <lirc@bartelmus.de>
    #
    # this config file was automatically generated
    # using lirc-0.9.0-pre1(default) on Thu Oct 9 19:21:59 2014
    #
    # contributed by
    #
    # brand: /home/pi/lircd.conf
    # model no. of remote control:
    # devices being controlled by this remote:
    #

    begin remote

    name /home/pi/lircd.conf
    flags RAW_CODES|CONST_LENGTH
    eps 30
    aeps 100

    gap 105898

    begin raw_codes

    name KEY_POWER
    1335 1154 486 1178 2151 1179
    1341 1160 2141 1206 2120 1209
    482 1180 508 1984 489 2009
    512

    name KEY_0
    2678 842 482 424 481 397
    484 836 484 835 1365 837
    481 426 482 397 483 398
    457 450 483 399 478 401
    478 399 484 423 489 393
    481 398 922 427 479 398
    482 399 482 867 478 399
    485 397 482 423 483 397
    928 861 483 398 482 398
    478 404 478 430 476 399
    483 396 484 424 482 398
    484 398 482

    name KEY_1
    2675 834 510 397 483 399
    483 836 483 836 1369 862
    480 399 458 418 484 399
    481 425 482 398 484 398
    483 423 484 399 454 421
    482 398 955 395 457 420
    483 399 483 423 484 835
    483 398 482 424 484 397
    923 866 484 397 482 399
    457 449 483 398 479 398
    481 399 484 423 483 399
    920

    name KEY_2
    2703 838 534 345 510 368
    540 783 508 817 1384 834
    539 343 512 368 484 424
    509 372 507 373 508 367
    514 398 508 369 518 363
    512 394 950 374 534 341
    514 367 565 783 509 372
    510 396 510 373 508 367
    950 840 511 366 515 368
    509 398 512 367 510 372
    508 372 539 369 951 806
    512

    end raw_codes

    end remote

    Key_0 / Key_1 / Key_2 habe ich nur zum testen mit gespeichert... KEY_POWER ist was ich brauche.

  • Also hier mal mein Script zum checken/wecken des Servers.

    Läuft soweit. Gibts es da was zu optimieren oder kann man das so lassen?!

Jetzt mitmachen!

Du hast noch kein Benutzerkonto auf unserer Seite? Registriere dich kostenlos und nimm an unserer Community teil!