Author Topic: Raspberry Pi Probleme beim ausführen  (Read 2483 times)

Janik

  • Newbie
  • *
  • Posts: 13
    • View Profile
Raspberry Pi Probleme beim ausführen
« on: January 12, 2017, 20:48:32 »
Hallo zusammen

Ich habe ein Problem wenn ich mein Python 3 Programm, mit dem ich einen Masterbrick mit einem NFC Bricklet ansteuern möchte, ausführe. Der Raspberry Pi hat einen Samba Server, Brickd und die Tinkerforge Library drauf. Beim Ausführen kommen komische Fehlermeldungen aus der Library.

Code: [Select]
#!/usr/bin/env python
# -*- coding: utf-8 -*-



HOST = "localhost"
PORT = 4223
UID = "uo1"




from tinkerforge.ip_connection import IPConnection

from tinkerforge.bricklet_nfc_rfid import BrickletNFCRFID

import sqlite3

import time





def cb_state_changed(state, idle, nr):
    if state == nr.STATE_REQUEST_TAG_ID_READY:
#data = nr.get_page() ist probehalber hier#
       
        data = nr.get_page()
       
        if ("[" + " ".join(map(str, data)) + "]") == """Nummer des NFC-Tags von kast""":
           
            connection = sqlite3.connect("arbeitszeit.db")
            cursor = connection.cursor()
            connection.commit()

           
           
            try:
                cursor.connection.cursor()
                cursor.execute('''INSERT INTO kast VALUES (date('now'), time('now'))''')
                time.sleep(2)
                connection.commit()
               

               
            except:
                print('Transaktionsprobleme Andrea Kast!!!')
                print('Bitte in 1 Minute nochmals einstempeln')
                #Rot Blinken!!!!!!(Raspi Led)
                time.sleep(4)
                connection.rollback()





               
        if ("[" + " ".join(map(str, data)) + "]") == """Nummer des NFC-Tags von jud""":
           
            connection = sqlite3.connect("arbeitszeit.db")
            cursor = connection.cursor()
            connection.commit()
           

           
            try:
                cursor.connection.cursor()
                cursor.execute('''INSERT INTO jud VALUES (date('now'), time('now'))''')
                time.sleep(2)
                connection.commit()

               
               
            except:
                print('Transaktionsprobleme Oliver Jud!!!')
                print('Bitte in 1 Minute nochmals einstempeln')
                #Rot Blinken!!!!!!(Raspi Led)
                time.sleep(4)
                connection.rollback()





               
        if ("[" + " ".join(map(str, data)) + "]") == """Nummer des NFC-Tags von ruegg""":
           
            connection = sqlite3.connect("arbeitszeit.db")
            cursor = connection.cursor()
            connection.commit()
           

           
            try:
                cursor.connection.cursor()
                cursor.execute('''INSERT INTO ruegg VALUES (date('now'), time('now'))''')
                time.sleep(2)
                connection.commit()

               
               
            except:
                print('Transaktionsprobleme Oliver Patrick Ruegg!!!')
                print('Bitte in 1 Minute nochmals einstempeln')
                #Rot Blinken!!!!!!(Raspi Led)
                time.sleep(4)
                connection.rollback()
       
       
       








if __name__ == "__main__":
    ipcon = IPConnection()
    nr = BrickletNFCRFID(UID, ipcon)

    ipcon.connect(HOST, PORT)
   
    nr.register_callback(nr.CALLBACK_STATE_CHANGED,
                         lambda x, y: cb_state_changed(x, y, nr))

   
    nr.request_tag_id(nr.TAG_TYPE_TYPE2)

Fehlermeldung
pi@stempeluhr:~ $ sudo python beta_1.2.py
Exception in thread Brickd-Receiver (most likely raised during interpreter shutdo                                                                                       wn):Exception in thread Disconnect-Prober (most likely raised during interpreter                                                                                        shutdown):

Traceback (most recent call last):Traceback (most recent call last):

  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner  File "/                                                                                       usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner

  File "/usr/lib/python2.7/threading.py", line 763, in run  File "/usr/lib/python                                                                                       2.7/threading.py", line 763, in run

  File "build/bdist.linux-armv6l/egg/tinkerforge/ip_connection.py", line 822, in                                                                                        disconnect_probe_loop  File "build/bdist.linux-armv6l/egg/tinkerforge/ip_connecti                                                                                       on.py", line 687, in receive_loop

<type 'exceptions.TypeError'>: 'NoneType' object is not callable  File "/usr/lib/                                                                                       python2.7/Queue.py", line 174, in get

<type 'exceptions.TypeError'>: 'NoneType' object is not callable





photron

  • Tinkerforge Staff
  • Administrator
  • Hero Member
  • *****
  • Posts: 2.467
    • View Profile
Re: Raspberry Pi Probleme beim ausführen
« Reply #1 on: January 13, 2017, 10:06:49 »
Du musst ganz am Ende deines Scripts, nach "nr.request_tag_id(nr.TAG_TYPE_TYPE2)" noch "ipcon.disconnect()" aufrufen.

Janik

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Raspberry Pi Probleme beim ausführen
« Reply #2 on: January 13, 2017, 14:09:42 »
Danke für die Antwort

Noch eine Frage, was muss ich machen damit das Programm sich wiederholt?


Janik

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Raspberry Pi Probleme beim ausführen
« Reply #3 on: January 16, 2017, 16:35:29 »
Hallo zusammen

Ich habe erfolglos versucht eine While Schleife in das Skript einzubauen.

Das Skript sollte sich im Abstand von z.B. 5 Sekunden wiederholen. Wenn ich über der Definition von cb_state_changed eine While Schleife einfüge, kommen Fehlermeldungen aus der TK Library und mit multiprocessing...

Vieleicht wisst ihr was es ist (was ich falsch mache) oder ich zeige noch die Fehlermeldungen.

photron

  • Tinkerforge Staff
  • Administrator
  • Hero Member
  • *****
  • Posts: 2.467
    • View Profile
Re: Raspberry Pi Probleme beim ausführen
« Reply #4 on: January 16, 2017, 16:46:09 »
Im Moment wartet dein Program nicht darauf das cb_state_changed() überhaupt aufgerufen wird.

In den Beispielen verwenden wir raw_input("Press key to exit\n") von dem finalen ipcon.disconnect() Aufruf, damit das Programm dort darauf wartet, dass der Nutzer eine Taste Drückt um das Program zu beenden.

Damit du immer wieder Tags abfragen kannst, könntest du am Anfang von cb_state_changed() einfach nochmal nr.request_tag_id(nr.TAG_TYPE_TYPE2) aufrufen, wenn idle == True ist. Im Prinzip so wie in diesem Beispiel:

https://www.tinkerforge.com/de/doc/Software/Bricklets/NFCRFID_Bricklet_Python.html#scan-for-tags

Übrigens rufst du nr.get_data() auf ohne vorher nr.request_data() aufgerufen zu haben.

Janik

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Raspberry Pi Probleme beim ausführen
« Reply #5 on: January 18, 2017, 07:41:11 »
Hi photron

Ich habe das ganze nochmal angepasst, soweit ich deine Angaben verstehen konnte.
Leider kommt immer noch die Fehlermeldung mit dem Threading. Liegt das daran dass mein Raspberry pi nur einen Core hat? Oder Habe ich wieder einen Fehler? kann es sein, dass die Tinkerforge-Teile zu schnell nach dem Tag abgefragt werden?
Danke für deine Geduld :)

Code: [Select]
#!/usr/bin/env python
# -*- coding: utf-8 -*-



HOST = "localhost"
PORT = 4223
UID = "uo1"




from tinkerforge.ip_connection import IPConnection

from tinkerforge.bricklet_nfc_rfid import BrickletNFCRFID

import sqlite3

import time

tag_type = 2




def cb_state_changed(state, idle, nr):
    if idle:
        nr.request_tag_id(nr.TAG_TYPE_TYPE2)
       
       
        if state == nr.STATE_REQUEST_TAG_ID_READY:
            ret = nr.get_tag_id()


            if (" ".join(map(str, map(hex, ret.tid[:ret.tid_length])))) == "04 98 5D 32 BA 2F 80":
                connection = sqlite3.connect("arbeitszeit.db")
                cursor = connection.cursor()
                connection.commit()
                print("geklappt")
               
                try:
                    cursor.connection.cursor()
                    cursor.execute('''INSERT INTO kast VALUES (date('now'), time('now'))''')
                    connection.commit()

                except:
                    print('Transaktionsprobleme Andrea Kast!!!')
                    print('Bitte in 1 Minute nochmals einstempeln')
                    #Rot Blinken!!!!!!(Raspi Led)
                    connection.rollback()
               





            elif (" ".join(map(str, map(hex, ret.tid[:ret.tid_length])))) == "04 98 5D 32 BA 2F 81":
                connection = sqlite3.connect("arbeitszeit.db")
                cursor = connection.cursor()
                connection.commit()
                try:
                    cursor.connection.cursor()
                    cursor.execute('''INSERT INTO jud VALUES (date('now'), time('now'))''')
                    time.sleep(2)
                    connection.commit()
                    print("geklappt")

                except:
                    print('Transaktionsprobleme Oliver Jud!!!')
                    print('Bitte in 1 Minute nochmals einstempeln')
                    #Rot Blinken!!!!!!(Raspi Led)
                    time.sleep(2)
                    connection.rollback()




            if (" ".join(map(str, map(hex, ret.tid[:ret.tid_length])))) == "04 98 5D 32 BA 2F 82":
                connection = sqlite3.connect("arbeitszeit.db")
                cursor = connection.cursor()
                connection.commit()

                try:
                    cursor.connection.cursor()
                    cursor.execute('''INSERT INTO ruegg VALUES (date('now'), time('now'))''')
                    time.sleep(2)
                    connection.commit()

                except:
                    print('Transaktionsprobleme Oliver Patrick Ruegg!!!')
                    print('Bitte in 1 Minute nochmals einstempeln')
                    #Rot Blinken!!!!!!(Raspi Led)
                    time.sleep(4)
                    connection.rollback()








if __name__ == "__main__":
    ipcon = IPConnection()
    nr = BrickletNFCRFID(UID, ipcon)
    ipcon.connect(HOST, PORT)
    nr.register_callback(nr.CALLBACK_STATE_CHANGED,
                         lambda x, y: cb_state_changed(x, y, nr))
   
    nr.request_tag_id(nr.TAG_TYPE_TYPE2)

    input("Beenden\n")
    ipcon.disconnect()

Noch eine der Fehlermeldungen
SyntaxError: unexpected EOF while parsing
Exception in thread Disconnect-Prober (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
  File "/usr/lib/python2.7/threading.py", line 763, in run
  File "build/bdist.linux-armv6l/egg/tinkerforge/ip_connection.py", line 822, in disconnect_probe_loop
  File "/usr/lib/python2.7/Queue.py", line 174, in get
<type 'exceptions.TypeError'>: 'NoneType' object is not callable

photron

  • Tinkerforge Staff
  • Administrator
  • Hero Member
  • *****
  • Posts: 2.467
    • View Profile
Re: Raspberry Pi Probleme beim ausführen
« Reply #6 on: January 18, 2017, 09:53:05 »
Ersetzt mal input() durch raw_input().

Und ich denke du muss deine cb_state_changed() Funktion so abändern von

Code: [Select]
def cb_state_changed(state, idle, nr):
    if idle:
        nr.request_tag_id(nr.TAG_TYPE_TYPE2)
       
        if state == nr.STATE_REQUEST_TAG_ID_READY:
            ret = nr.get_tag_id()

zu

Code: [Select]
def cb_state_changed(state, idle, nr):
    if idle:
        nr.request_tag_id(nr.TAG_TYPE_TYPE2)
       
    if state == nr.STATE_REQUEST_TAG_ID_READY:
        ret = nr.get_tag_id()

Janik

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Raspberry Pi Probleme beim ausführen
« Reply #7 on: January 18, 2017, 11:21:09 »
Das geht leider nicht, weil ich Python 3 benutze.

photron

  • Tinkerforge Staff
  • Administrator
  • Hero Member
  • *****
  • Posts: 2.467
    • View Profile
Re: Raspberry Pi Probleme beim ausführen
« Reply #8 on: January 18, 2017, 11:23:45 »
Noch eine der Fehlermeldungen
SyntaxError: unexpected EOF while parsing
Exception in thread Disconnect-Prober (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
  File "/usr/lib/python2.7/threading.py", line 763, in run
  File "build/bdist.linux-armv6l/egg/tinkerforge/ip_connection.py", line 822, in disconnect_probe_loop
  File "/usr/lib/python2.7/Queue.py", line 174, in get
<type 'exceptions.TypeError'>: 'NoneType' object is not callable

Nein, tust du nicht. Da steht überall Python 2.7.

Janik

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Raspberry Pi Probleme beim ausführen
« Reply #9 on: January 19, 2017, 10:45:45 »
Danke Photron

Jetzt funktioniert es endlich.

Janik

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Raspberry Pi Probleme beim ausführen
« Reply #10 on: January 31, 2017, 11:47:44 »
Hallo zusammen

Ich wage einem neuen Anlauf. Es wird alles in Python3 ausgeführt und sollte meiner Meinung nach funktionieren. Es gibt keine Fehlermeldungen. Was mach ich schon wieder Falsch???

Script auf dem Raspberry pi

#!/usr/bin/env python
# -*- coding: utf-8 -*-



HOST = "localhost"
PORT = 4223
UID = "uo1"

from tinkerforge.ip_connection import IPConnection

from tinkerforge.bricklet_nfc_rfid import BrickletNFCRFID

import sqlite3

import time


tag_type = 0



   

def cb_state_changed(state, idle, nfc):
   
    if idle:
        global tag_type
        tag_type = (tag_type + 1) % 3
        nfc.request_tag_id(tag_type)
   
       
    if state == nfc.STATE_REQUEST_TAG_ID_READY:
        ret = nfc.get_tag_id()
        tp = str(" ".join(map(str, map(hex, ret.tid[:ret.tid_length]))))
        if tp == "0x4 0x98 0x5d 0x32 0xba 0x2f 0x80":
            connection = sqlite3.connect("arbeitszeit.db")
            cursor = connection.cursor()
            connection.commit()
            print("geklappt")
           
            try:
                cursor.connection.cursor()
                cursor.execute('''INSERT INTO kast VALUES (date('now'), time('now'))''')
                connection.commit()
               
            except:
                print('Transaktionsprobleme Andrea Kast!!!')
                print('Bitte in 1 Minute nochmals einstempeln')
                #Rot Blinken!!!!!!(Raspi Led)
                connection.rollback()




if __name__ == "__main__":
    ipcon = IPConnection()
    nfc = BrickletNFCRFID(UID, ipcon)
    ipcon.connect(HOST, PORT)
    nfc.register_callback(nfc.CALLBACK_STATE_CHANGED,
                         lambda x, y: cb_state_changed(x, y, nfc))

    nfc.request_tag_id(tag_type)

    input("Beenden\n")
    ipcon.disconnect()


Script auf dem Pc der die Daten auslesen soll, allerdings wird das Excel Sheet leer.(Hauptproblem)


import sys
from tkinter import *
import sqlite3
from xlsxwriter.workbook import Workbook
def importexcel():
    workbook = Workbook('arbeitszeit.xlsx')
    worksheet = workbook.add_worksheet()
    conn=sqlite3.connect('arbeitszeit.db')
    c=conn.cursor()
    c.execute("select * from kast")
    mysel=c.execute("select * from kast")
    for i, row in enumerate(mysel):
        for j, value in enumerate(row):
            worksheet.write(i, j, row[j]);
    workbook.close()
    mLabel2 = Label(mGui,text='alles importiert, Datei liegt auf dem Desktop.').pack()

mGui =Tk()
mGui.geometry('450x450')
mGui.title('Excel Datei Importierer')
mLabel = Label(mGui,text='janik Ruggle Label').pack()
mbutton = Button(mGui,text ='import excel file', command = importexcel).pack()




photron

  • Tinkerforge Staff
  • Administrator
  • Hero Member
  • *****
  • Posts: 2.467
    • View Profile
Re: Raspberry Pi Probleme beim ausführen
« Reply #11 on: January 31, 2017, 17:10:52 »
Ist denn in deiner sqlite Datenbank was drin? Sprich, ist das Problem, dass nichts in der sqlite Datenbank ist, oder dass das Konvertieren nach Excel nicht klappt?

Janik

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Raspberry Pi Probleme beim ausführen
« Reply #12 on: January 31, 2017, 18:31:54 »
In meiner Datenbank sind nur die Tabellen drin, es hat keine Einträge, obwohl ich den Tag mehrmals auf das NFC-Bricklet draufgehalten habe.

photron

  • Tinkerforge Staff
  • Administrator
  • Hero Member
  • *****
  • Posts: 2.467
    • View Profile
Re: Raspberry Pi Probleme beim ausführen
« Reply #13 on: February 01, 2017, 16:36:18 »
Siehst du denn die prints die du in cb_state_changed() drin hast? Sprich wird cb_state_changed() aufgerufen. Vielleicht muss du da ein paar mehr prints einbauen um zusehen bis wohin der Code kommt.

Janik

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Raspberry Pi Probleme beim ausführen
« Reply #14 on: February 02, 2017, 09:30:47 »
Hallo photron

Ich habe den Trick mit den Prints schon gemacht. Python führt den Sqlite3 Teil aus, es steht aber nichts in der DB.