Jump to content

Raspberry Pi Probleme beim ausführen


Janik

Recommended Posts

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.

 

#!/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

 

 

 

 

 

Link zu diesem Kommentar
Share on other sites

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.

Link zu diesem Kommentar
Share on other sites

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.

Link zu diesem Kommentar
Share on other sites

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 :)

 

#!/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

Link zu diesem Kommentar
Share on other sites

Ersetzt mal input() durch raw_input().

 

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

 

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

 

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()

Link zu diesem Kommentar
Share on other sites

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.

Link zu diesem Kommentar
Share on other sites

  • 2 weeks later...

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()

 

 

 

 

Link zu diesem Kommentar
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Clear editor

×   Du kannst Bilder nicht direkt einfügen. Lade Bilder hoch oder lade sie von einer URL.

×
×
  • Neu erstellen...