Professional Documents
Culture Documents
PushSDK Development Guide V1.0
PushSDK Development Guide V1.0
1
PushSDK Development Guide Ver 1.0
Contents
1 Document Description................................................................................................................................ 2
1.1 Function Description ......................................................................................................................... 2
1.2 Intended Audience............................................................................................................................. 2
1.3 Terms................................................................................................................................................. 2
1.4 Technical Support Service................................................................................................................. 2
2 Function Description.................................................................................................................................. 3
2.1 Acquire Configuration Information................................................................................................... 3
2.2 Transfer Device Data......................................................................................................................... 4
2.3 Acquire Commands ........................................................................................................................... 4
2.4 Return an Execution Result ............................................................................................................... 4
1
PushSDK Development Guide Ver 1.0
Contents
1 Document Description................................................................................................................................ 2
1.1 Function Description ......................................................................................................................... 2
1.2 Intended Audience............................................................................................................................. 2
1.3 Terms................................................................................................................................................. 2
1.4 Technical Support Service................................................................................................................. 2
2 Function Description.................................................................................................................................. 3
2.1 Acquire Configuration Information................................................................................................... 3
2.2 Transfer Device Data......................................................................................................................... 4
2.3 Acquire Commands ........................................................................................................................... 4
2.4 Return an Execution Result ............................................................................................................... 4
1
PushSDK Development Guide Ver 1.0
2 Function Description
3
PushSDK Development Guide Ver 1.0
1 Document Description
Thank you for using the PushSDK of our company to develop server applications. PUSHSDK is
a communication protocol developed by ZTE based on the Hyper Text Transfer Protocol (HTTP). It
implements data transfer by adopting the mechanism that enables a device to access the server in an
unsolicited mode. PUSHSDK is applicable to stable TCP/IPcapable networks, for example, the commonly
used Local Area Network (LAN) and the World Wide Web (WWW). It supports resumable multithread
downloading and unsolicited upload of new information. Its high scalability allows users to conveniently
develop and extend new functions.
1.3 Terms
Term Meaning
Interface Provides a URL address for the device to communicate with the server.
Request Indicates a process of sending data over HTTP to the recipient.
Indicates a process of returning relevant information from the server to the device based on the
Return
requested address.
Denotes the time at which data is uploaded and the device obtains information from the server.
Timestamp
Timestamp is used for time synchronization between the device and the server.
IP address of server Indicates the IP address of a web server
Device sequence
Indicates the unique serial number displayed on the device.
number
2
PushSDK Development Guide Ver 1.0
5
PushSDK Development Guide Ver 1.0
Parameter Meaning
maximum of 10 time points.
{TransInterval } Indicates the new data check and transfer interval. (unit: minute)
For the protocol firmware of earlier versions, return a flag in character array format, for example,
“1111000000”. If “0000000000” is returned, it indicates the Att2008 of an old version. In this
case, you only need to upload the attendance photo flag. For the Att2008 of a new version, set a
flag for attendance photo upload. 0: Automatic upload of this type of data is prohibited. 1:
Automatic upload of this type of data is allowed. Table 12 lists the flags of the data types
supported by the standard firmware for automatic upload.
{TransFlag }
For the new version firmware, return a flag in character string format, for example, “TransData
AttLog\tOpLog\tAttPhoto”. The characters are separated by \t. To automatically upload a certain
type of data, set a corresponding flag in character string format. Table 12 lists the flags of the
data types supported by the standard firmware for automatic upload.
To automatically upload user and fingerprint information, you must set the automatic upload of
operation logs.
{Realtime }
{Encrypt }
{ServerVer }
Indicates the time at which data is automatically updated. TableName indicates the data table
name which must be consistent with the data table name registered by firmware. Stamp is a fixed
{TableNameStamp } flag. All the timestamps for automatic upload of data tables must be returned to the device. Each
such timestamp is displayed on every single line. For example, ATTLOGStamp=82983982
indicates the timestamp for attendance logs. For details of data table names, see Table 13.
Table 11
Table 12
6
PushSDK Development Guide Ver 1.0
Table 13
if request.method == 'GET':
pushverValue = 0.0
if request.REQUEST.has_key('pushver'):
if pushverValue >= 2.0: #Judge whether the PushSDK is a new version. If yes, use the new timestamp.
attlogStamp = "ATTLOGStamp"
operlogStamp = "OPERLOGStamp"
attphotoStamp = "ATTPHOTOStamp"
resp += "GET OPTION FROM: %s\n" % device.SN #Prepare the character string to be returned to the device,
where SN indicates the device serial number.
resp += "%s=%s\n" % (attlogStamp, device.LogStamp) #Set a timestamp for the attendance log.
resp += "%s=%s\n" % (operlogStamp, device.OpLogStamp or 0) #Set a timestamp for the operation log.
resp += "%s=%s\n" % (attphotoStamp, device.PhotoStamp or 0) #Set a timestamp for a photo upload event.
resp += "Delay=%d\n" % settings.MIN_REQ_DELAY #Set an interval after which the device reaccesses the
server.
7
PushSDK Development Guide Ver 1.0
try:
except:
pass
resp += "ServerVer=0.0.2 20100722\n" #Only the new version provides the information about server version and
table name timestamp.
response["ContentLength"] = len(resp)
response.write(resp)
8
PushSDK Development Guide Ver 1.0
* Format of ID card number: If an ID card number in HEX format is surrounded by square brackets “[“and
“]", this number denotes a complete ID card number; otherwise, it is consistent with the number displayed
on screen after card swiping.
The server acquires user information:
if request.method == 'POST':
raw_Data = request.raw_post_data #Acquire the data uploaded in POST mode from the device.
import lzo
else:
lines = raw_Data.split("\n") #Split the raw data into lines by line feed. Each line is a piece of user record.
try:
index = item.find("=")
if index > 0: flds[item[:index]] = item[index + 1:] #Store the user information into flds.
employee = getEmployee(pin, device) #Search for the user based on the PIN number. If there is no
match, the user is a new one.
if ename and (ename != employee.EName) or not ename:#If the user name is empty, change of user name is
allowed.
fldNames.append('name')
values.append(ename)
employee.EName = ename
values.append(passwd)
employee.Password = passwd
9
PushSDK Development Guide Ver 1.0
if priv != employee.Privilege:
fldNames.append('privilege')
values.append(priv)
employee.Privilege = priv
values.append(cardToNum(card))
employee.Card = cardToNum(card)
if agrp != employee.AccGroup:
fldNames.append('AccGroup')
values.append(agrp)
employee.AccGroup = agrp
if tz != employee.TimeZones:
fldNames.append('TimeZones')
values.append(tz)
employee.TimeZones = tz
except Exception, e:
print_exc()
return response
raw_Data = request.raw_post_data #Acquire the data uploaded from the device in POST mode.
import lzo
10
PushSDK Development Guide Ver 1.0
else:
lines = raw_Data.split("\n") #Split the raw data into lines by line feed. Each line is a piece of user record.
try:
index = item.find("=")
if index > 0: flds[item[:index]] = item[index + 1:] #Store the fingerprint information into flds.
try:
if fp[:100] == fptemplate.Template[:100]:
else:
sql = "update template set template = '%s', SN='%s', utime='%s' where userid='%s' and fingerid=%s" % (fp,
device.SN, str(datetime.datetime.now())[:19], employee.UserID.id, employee.FingerID) #Update the user fingerprint
template.
except ObjectDoesNotExist: #If the user fingerprint template does not exist
if fp and int(flds["Size"]) == len(fp): #Judge the length consistency. sql = "insert into
template(template, userid, fingerid, SN, utime, valid, DelTag) values('%s', '%s', %s, '%s', '%s', 1, '0')" % (fp, employee.id,
flds["FID"], device.SN, str(datetime.datetime.now())[:19])
response.write(“OK”)
return response
Operation logs
Format:
* \t is a tab character.
Example:
Parameter Meaning
{ OPCode } Operation code
{ AdminID } Administrator ID
11
PushSDK Development Guide Ver 1.0
Parameter Meaning
{ DateTime } Date and time
{ Object1} Operation object 1 **
{ Object2} Operation object 2
{ Object3} Operation object 3
{ Object4} Operation object 4
An operation code can be relevant to different operation objects. For details, see the table below.
Operation code Operation content Parameter description
0 Startup
1 Shutdown
In 1:1 verification mode, “Object 1” indicates the
2 Verification fails.
PIN number of the user.
“Object1” indicates the cause of the alarm. It
supports the following values:
50: Door Close Detected
51: Door Open Detected
3 Alarm 55: Machine Been Broken
53: Out Door Button
54: Door Broken Accidentally
58: Try Invalid Verification
65535: Alarm Cancelled
4 Access the menu.
5 Modify the setting. “Object1” indicates the modified settings.
“Object1” indicates the user ID.
“Object2” indicates the serial number of the
6 Enroll a fingerprint. fingerprint.
“Object3” indicates the length of the fingerprint
template.
7 Enroll a password.
8 Enroll an HID card.
9 Delete a user. “Object1” indicates the user ID.
10 Delete a fingerprint. “Object1” indicates the user ID.
11 Delete a password. “Object1” indicates the user ID.
12 Delete an RF card. “Object1” indicates the user ID.
13 Purge data.
14 Create an MF card.
15 Enroll an MF card.
16 Register an MF card.
17 Cancel the registration of an MF card.
18 Purge the content of an MF card.
19 Move the enrolled data into a card.
20 Copy the data from a card into a device.
21 Set the time.
22 Factory defaults
12
PushSDK Development Guide Ver 1.0
* If an operation code does not correspond to any operation object, the default value of the operation object
is 0.
The server acquires operation logs:
if request.method == 'POST':
raw_Data = request.raw_post_data #Acquire the data uploaded from the device in POST mode.
import lzo
else:
lines = raw_Data.split("\n") #Split the raw data into lines by line feed. Each line is a piece of user record.
try:
index = item.find("=")
if index > 0: flds[item[:index]] = item[index + 1:] #Store the fingerprint information into flds.
if ops[0] == 'OPLOG':
try:
except:
return None
if (datetime.datetime.now() + datetime.timedelta(1, 0, 0)) < logtime: #Set the time to be one day later
than current time. #Judge whether the time is set properly.
13
PushSDK Development Guide Ver 1.0
return None
response.write(“OK”)
Data format:
Description:
Parameter Meaning
Indicate the unique identification number of an image, and supports two formats:
PIN=DATETIMEU: indicates that the user passes the verification. Where DATETIME is the
{ PIN } user verification time expressed in YYYYMMDDHHNNSS format, and U is the attendance
number of the user.
PIN=DATETIME: indicates that the user fails to pass the verification.
{ SN } Indicates the device serial number.
{ SIZE } Indicates the size of the photo file.
Indicates the photo transmission type. If the value of this parameter is uploadphoto, the
{ TYPE } background uploads the photo. If the value of this parameter is realupload, the device uploads the
photo in realtime.
{ BINARY IMAGE
Indicates the binary data of the onsite JPG image.
DATA }
device = checkDevice(request, response) #Acquire the related device information based on the request.
if(device == None): return response #If the device does not exist, the following information is returned:
try:
dt = pin[0]
pin = pin[1]
else:
pin = None
try:
except:
pass #errorLog(request)
f = file(fname, "wb")
d = request.raw_post_data
f.write(d)
f.close()
#if request.REQUEST.has_key('PhotoStamp'):
device.PhotoStamp = request.REQUEST['Stamp']
conn._commit()
except Exception, e:
Note: After finishing each of the three types of operations above, you must update the corresponding
timestamps on the server. For example, you must update the value related to the attendance log
timestamp, namely, AttLog, after attendance log upload is complete. Similarly, you also need to
update the related timestamps after upload photos and fingerprint images, so as to keep timestamp
consistency between the device and the server, thus ensuring proper data transmission.
15
PushSDK Development Guide Ver 1.0
C:ID1:CMD1 \n
C:ID2:CMD2 \n
C:ID3:CMD3 \n
For example:
C:ID1:CHECK \n
C:ID2:CLEAR DATA \n
response = HttpResponse(mimetype='text/plain')
try:
resp = ""
device = checkDevice(request, response) #Check whether the device exists in the system based on the SN.
if(device == None): return response #If the device does not exist, the following information is returned:
cmds = deviceCmd(device) #Acquire the commands to be executed by the device from the server.
cmds = deviceCmd(device)
if len(cmds) > 0:
16
PushSDK Development Guide Ver 1.0
cc = acmd.CmdContent
try:
cc = cc.encode("gb18030")
except:
try:
cc = cc.decode("utf8").encode("gb18030")
except:
errorLog(request)
else:
cc = str(acmd.CmdContent)
if cc:
#In the case of inconsistency of fingerprint template versions, downloading is not allowed.
devObject = getDevice(acmd.SN_id)
if devObject.FPVersion:
if "TMP=" in cc:
tmp = cc.split("TMP=")
FPVersion1 = ""
if tmp :
else:FPVersion1 = "10"
if acmd.CmdTransTime: #If commands failed to be sent last time, 10 less commands are sent this time,
because the transmission failure may result from data oversize.
17
PushSDK Development Guide Ver 1.0
maxRet = 10
acmd.CmdTransTime = datetime.datetime.now()
acmd.save()
c = c + 1;
if acmd.CmdContent in ["REBOOT", "RESTART"]: break; #The reboot command can only be the last
command. except Exception, e: #If there is an exception, cast the exception.
resp = "%s" % e
response["ContentLength"] = len(resp)
response.write(resp)
return response
Note: 1. The commands from the server are not instantly sent to the device, so the device may fail to
acquire or execute the commands in realtime. In such a case, the server can send an RCMD message to the
device over the UDP 4374 port. Upon receiving this message, the device will instantly query commands
from the server. This mechanism greatly improves the response speed of the device, but it applies only to
the cases where the server can be directly connected to the device, for example, within a LAN or the device
has an IP address of a public network.
The server sends an RCMD command:
import socket
try:
ip=device.IPAddress
except:
errorLog()
pass
Command List
Command Meaning
SHELL {CMD_String} Run system commands. {CMD_String} is a system command.
CHECK Check data updates.
CLEAR LOG Purge attendance logs.
CLEAR DATA Purge all data.
CLEAR PHOTO Purge the photos collected on site.
INFO Send the device information to the server.
Set the device options. ITEM indicates the option content. VALUE indicates the
option value. For example:
SET OPTION ITEM=VALUE
SET OPTION IPAddress=192.168.1.225. For details of the options supported by the
devices, see Appendix 1.
18
PushSDK Development Guide Ver 1.0
Command Meaning
REBOOT Reboot
<SUBCMD> includes the following subcommands: UPDATE tablename value: Add
or modify the data in the tablename list.
For example:
DATA <SUBCMD>
UPDATE FINGERTMP PIN=%d\tFID=%d\tSize=%d\tValid=%d\tTMP=%s
UPDATE USERINFO
%d\tName=%s\tPri=%d\tPasswd=%s\tCard=[ %02x%02x%] \tGrp=%d\tTZ=%d
DELETE tablename key: Delete the data in the tablename list based on the key.
DELETE tablename key
DELETE FINGERTMP PIN=%d\tFID=%d
QUERY tablename key: Query the data in the tablename list based on the key.
QUERY tablename key QUERY USERINFO PIN=%d
If no PIN is specified, upload all the PINs.
The user and fingerprint information is in the same format as the information uploaded by the device.
Address 2: http://IP address of
server/iclock/getrequest?SN={SN}&INFO={object1},{object2},{object3},{object4},{object5}
Interface description:
When a device sends a request to the server for the first time, enrolls users or fingerprints, or records
attendance logs, related information is stored under the URL path (INFO=firmware version number,
number of enrolled users, number of enrolled fingerprints, number of attendance logs, IP address of the
attendance machine, and fingerprint algorithm ID).
Parameter Meaning
{ SN } Device serial number
{object1} Firm version number
{object2} Number of enrolled users
{object3} Number of enrolled fingerprints
{object4} Number of attendance logs
{object5} IP address of the attendance machine
{object6} Fingerprint algorithm ID
try:
resp = ""
info = request.GET.get("INFO", "") #Version number, number of users, number of fingerprints, and number of
attendance logs.
if info:
info = info.split(",")
19
PushSDK Development Guide Ver 1.0
info =
"FWVersion=%s\nUserCount=%s\nFPCount=%s\nTransactionCount=%s\nIPAddress=%s\nFPVersion=%s\n" %
tuple(info[:6]) #Six parameters
elif len(info) == 5:
elif len(info) == 4:
else:
info = ""
resp = ""
try:
try:
import lzo
except:
20
PushSDK Development Guide Ver 1.0
rawData = rd
else:
rawData = rd
try:
except:
data0 = rawData
rets = {}
InfoLines = []
pdata = parsePosts(data0)
# appendFile("%s"%pdata)
saveDevInfo(device, apost['Content'])
rets[id] = ret
elif apost['CMD'] == 'PutFile' and ret > 100 * 1024:#Return the PUTFILE result.
checkUpLoadFile(request, apost)
rets[id] = ret
else:
rets[id] = ret
if len(rets) > 0:
updateCmds(rets)
resp += "OK"
checkAndSave(device)
try:
nocmd_device = cache.get("nocmd_device")
if nocmd_device:
nocmd_device.remove(device.SN)
cache.set("nocmd_device", nocmd_device)
21
PushSDK Development Guide Ver 1.0
except: pass
except Exception, e:
errorLog(request)
response["ContentLength"] = len(resp)
response.write(resp)
return response
The returned contents vary with commands. Several commands are listed as follows:
Command: CLEAR PHOTO
Command: INFO
{option} contains all the parameters on the devices. For details, see the option configuration table supported by the device.
Options are separated by line feed.
Where ID=1234 is the command ID number, SN=999999 is the device serial number, FILENAME=FilePath is the file
name, Return=999 is the file size (number of bytes), and Content=ssss is the file content. ssss can be text with multiple lines
or be binary data.
6: Indicates deregistration.
5: indicates the registered fingerprint already exists in the fingerprint library (fingerprint repetition).
4: indicates registration failure due to poor fingerprint quality or inconsistency of fingerprints pressed in three consecutive
times.
9: indicates the fingerprint template and the given size do not match (This value is not supported in earlier versions. The
fingerprint template length verification is added in current version.)
10: indicates the user specified by the PIN does not exist on the equipment. You can only perform related operations after
adding this user by running the DATA UPDATE USERINFO command.
22
PushSDK Development Guide Ver 1.0
2. Select an editor
The wxPython powered Ulipad 4.0 is adopted in the PushSDK development. When using Ulipad, pay
attention to the following: When environment variables change, the files running on Ulipad will not
load the updated environment variables. You need to exit Ulipad and run it again to load updated
variables. Figure 1.3 shows some of the Ulipad configuration items. The firebug of Firefox browser is
recommended for the page debugging. To debug python codes, you can adopt Eclipse. For details
about how to add iclocksvr system in Eclipse configurations, see the Appendix.
23
PushSDK Development Guide Ver 1.0
3. Select a database
You can install MySQL5.1, SQLServer2005, oracle10g or PostgreSQL9.0 as required.
You can start the project development after installing a database.
1. Run the djangoadmin.py startproject mysite command under the project directory to create a
directory named mysite at current directory.
The following files will be generated under the mysite directory:
· __init__.py: indicates a file required for Python to deem this directory as a development kit (that is, a
set of modules).
· manage.py: is a command line tool that allows you to interact with the Django project in many ways.
· settings.py: contains the configurations of the Django project.
· urls.py: indicates the URL statement of the Django project, that is, the content list of the sites
supported by Django.
Django contains a builtin lightweight Web server for use during site development. This Web server is
offered for you to develop sites quickly. That is, before preparing for the product release, you do not
have to perform productlevel Web server (for example, Apache) configurations. This Web server
monitors code changes and automatically reloads them once detecting any code change, which helps
you quickly modify projects without reboot.
2. Open the mysite directory and run the python manage.py runserver command. You can see the
following message:
· 1
Validating models...
0 errors found.
24
PushSDK Development Guide Ver 1.0
Then you can compile handling functions. The communicationrelated handling functions are provided by
the devview module as shown in the preceding figure.
The functions Cdata, getreq, devpost and postPhoto are used to handle contents in an HTTP request. For
details, see preceding handling procedures.
Option Meaning
IPAddress Indicates The IP address of the equipment.
NetMask Indicates the subnet mask of the equipment.
GATEIPAddress Indicates the gateway address of the equipment
VOLUME Indicates the volume.
Indicates the Ethernet MAC address. The MAC address format in C language:
MAC
"%02X:%02X:%02X:%02X:%02X:%02X".
CardKey Indicates the Mifare card password.
DeviceID Indicates the device DI.
LockOn Indicates the unlocking duration.
AlarmAttLog Indicates the attendance alarm.
AlarmReRec Indicates the minimum interval between checkins.
RS232BaudRate Indicates the baud rate of the RS232/RS485 communication.
AutoPowerOff Indicates the automatic poweroff time. The automatic poweroff time format: Hour × 256 +
25
PushSDK Development Guide Ver 1.0
Option Meaning
Minutes. This format is adopted for all the following items that involve time setting.
AutoPowerOn Indicates the automatic poweron time.
AutoPowerSuspend Indicates the automatic standby time.
AutoAlarm1–AutoAlarm50 Indicates 50 automatic alarms.
IdlePower Indicates the idle setting.
IdleMinute Indicates the idle time (unit: minute).
RS232On Indicates whether to enable the RS232 connection.
RS485On Indicates whether to enable the RS485 connection.
UnlockPerson Indicates the number of persons allowed to unlock in simple access control mode.
OnlyPINCard Indicates this parameter is used only when the Mifare card ID is read.
AlarmReRec Indicates the minimum interval between checkins.
RS232BaudRate Indicates the baud rate of the RS232/RS485 communication.
Indicates the automatic poweroff time. The automatic poweroff time format: Hour × 256 +
AutoPowerOff Minutes.
This format is adopted for all the following items that involve time setting.
AutoPowerOn Indicates the automatic poweron time.
AutoPowerSuspend Indicates the automatic standby time.
AutoAlarm1–AutoAlarm50 Indicates 50 automatic alarms.
IdlePower Indicates the idle setting.
IdleMinute Indicates the idle time (unit: minute).
RS232On Indicates whether to enable the RS232 connection.
RS485On Indicates whether to enable the RS485 connection.
UnlockPerson Indicates the number of persons allowed to unlock in simple access control mode.
OnlyPINCard Indicates this parameter is used only when the Mifare card ID is read.
HiSpeedNet Indicates the network rate.
Must1To1 Indicates whether 1:1 fingerprint verification is allowed.
Indicates the unlocking time. An alarm signal will be generated if the door is not closed
ODD
within the specified period.
DSM
AADelay
DUHK Indicates whether to enable the duress alarm function.
DU11 Indicates duress alarm in 1:1 fingerprint verification mode.
DU1N Indicates duress alarm in 1:N fingerprint verification mode.
DUPWD Indicates duress alarm in password verification mode.
DUAD Indicates alarm delay time (Unit: Second) after the duress alarm is generated.
LockPWRButton Indicates the poweroff locking button.
Indicates whether to send a broadcast message for other hosts on the network to know its
SUN
presence at equipment startup.
I1NFrom Indicates the start user number in 1:N fingerprint verification mode.
I1NTo Indicates the stop user number in 1:N fingerprint verification mode.
I1H Indicates whether to enable the 1: H function.
I1G Indicates whether to enable the 1: G function.
KeyPadBeep Indicates whether to beep sound for every keystroke.
WorkCode Indicates whether to enable the WorkCode function.
26