【发布时间】:2017-06-19 04:14:46
【问题描述】:
我目前正在从事一个个人项目,其中涉及:
- 带有 RFID 读写器模块的 Raspberry Pi Model b
- Oracle SQL 数据库 (11g)
- Python 脚本
这就是我想要做的事情: 我需要 Raspberry Pi 发送我从 RFID 标签中读取的 UID(唯一标识号),并使用 UID 在我的 SQL 数据库中插入一行。从RFID标签读取的信息是一串数字,可以存储为String。
我目前能够读取标签并将 UID 打印到屏幕上。读数正在由我从网上找到的源代码修改的 Python 脚本处理。
我正在努力将 UID 发送到我的 SQL 数据库。我已经研究过 cx_Oracle 但它似乎不存在于 Raspberry Pi 使用的 ARM 架构中。我也研究了 pyodbc 但我似乎也无法让它工作。这是我用来读取 RFID 标签的 Python 脚本。
额外信息 : 我是 Python 的菜鸟,我有 C、Java、JDBC 和 Oracle SQL 的背景。我了解 JDBC 连接的工作原理,但我似乎无法在 Python 中实现相同的理论。对于 Python 专业人士,请随时修改我的以下代码以访问 Oracle SQL 数据库。我的数据库的凭据如下:
- 地址:本地主机
- 端口:1521
- 用户:学生
- 密码:测试
- 方案:学生
-
表名:EMP
#!/usr/bin/env python # -*- coding: utf8 -*- import RPi.GPIO as GPIO import MFRC522 import signal continue_reading = True # Capture SIGINT for cleanup when the script is aborted def end_read(signal,frame): global continue_reading print "Ctrl+C captured, ending read." continue_reading = False GPIO.cleanup() # Hook the SIGINT signal.signal(signal.SIGINT, end_read) # Create an object of the class MFRC522 MIFAREReader = MFRC522.MFRC522() # Welcome message print "Welcome to the MFRC522 data read example" print "Press Ctrl-C to stop." # This loop keeps checking for chips. If one is near it will get the UID and authenticate while continue_reading: # Scan for cards (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL) # If a card is found if status == MIFAREReader.MI_OK: print "Card detected" # Get the UID of the card (status,uid) = MIFAREReader.MFRC522_Anticoll() # If we have the UID, continue if status == MIFAREReader.MI_OK: # Print UID print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])
【问题讨论】:
-
您正在尝试创建一个 2 层富客户端,但也许另一种方法会更好?您可以在 oracle db(或单独的烧瓶服务器)中创建一个 http rest 端点,并使用请求从 pi 调用它。
标签: python sql database oracle raspberry-pi