Python Write Personal User ID using RC522 - python-3.4

I'm struggling in using Python3 for writing and reading personal user id in rc522. Here I want to write (for example, 123) in the rfid based on the input. However, after I write '123', the python says
can't concat list to bytearray.
Please, help. Thank you :D
info = input("Personal ID")
info = int(info)
status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A,8,key,uid)
if status == MIFAREReader.MI_OK:
data = bytearray(16)
value = format(info,'x')
while (8 > len(value)):
value = '0' + value
data[0:8] = bytearray.fromhex(value)
MIFAREReader.MFRC522_Write(8,data)
def (self,blockAddr,writeData)
buff = []
buff.append(self.PICC_WRITE)
buff.append(blockAddr)
crc = self.CalulateCRC(buff)
buff += crc
(status,backData,backLen) = self.MFRC522_ToCard(
self.PCD_TRANSCEIVE,buff
)
buff = writeData[0:8]
crc = self.CalulateCRC(buff)
buff += crc /////the error is pointed here
(status,backData,backLen) = self.MFRC522_ToCard(
self.PCD_TRANSCEIVE,buff
)
if status == self.MI_OK:
return True

Related

putting letters with number inside lua variables

I have this Nginx lua code which is used to encrypt numbers from 0 to 9 with its equivalent encrypted code ... ( see the example below )
and its working great , but i want to make it also encrypt Letters from A to Z.
I'm not familiar with lua so i don't know what is the best way to make it works !
content_by_lua_block {
local bf = {}
bf[0] = '(((_<<_)<<_)'
bf[1] = '(({}>[])-(()>[]))'
bf[2] = '(({}>[])-(()>[]))])'
bf[3] = '(({}>[])-(()>[]))])*'
bf[4] = '(({}>[])-(()>[]))])*(()>[])'
bf[5] = '(({}>[])-(()>[]))])*(()>[])%'
bf[6] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_'
bf[7] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_'
bf[8] = '(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf[9] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
local cookie = ngx.var.token
for i=0, 9 do
cookie = string.gsub(cookie, i, "'+"..bf[i].."+'")
end
Maybe something like that :
content_by_lua_block {
local bf = {}
bf[0] = '(((_<<_)<<_)'
bf[1] = '(({}>[])-(()>[]))'
bf[2] = '(({}>[])-(()>[]))])'
bf[3] = '(({}>[])-(()>[]))])*'
bf[4] = '(({}>[])-(()>[]))])*(()>[])'
bf[5] = '(({}>[])-(()>[]))])*(()>[])%'
bf[6] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_'
bf[7] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_'
bf[8] = '(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf[9] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf[a] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%'
bf[b] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%'
bf[c] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%'
...................
...................
...................
...................
bf[z] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%)%(()>[])%)%(()>[])%'
local cookie = ngx.var.token
for i=0, 9 and a, z do
cookie = string.gsub(cookie, i, "'+"..bf[i].."+'")
end
I tried to rewrite your code:
local bf = {}
bf[0] = '(((_<<_)<<_)'
bf[1] = '(({}>[])-(()>[]))'
bf[2] = '(({}>[])-(()>[]))])'
bf[3] = '(({}>[])-(()>[]))])*'
bf[4] = '(({}>[])-(()>[]))])*(()>[])'
bf[5] = '(({}>[])-(()>[]))])*(()>[])%'
bf[6] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_'
bf[7] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_'
bf[8] = '(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf[9] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))'
bf['a'] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%'
bf['b'] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%'
bf['c'] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%'
--
--
--
bf['z'] = '(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%)%(()>[])%)%(()>[])%'
local cookie = "01sdz" -- ngx.var.token
-- first example
local cookie = cookie:gsub ( '.', function (x)
local s = tonumber(x) or x
if bf[s] then return "'+".. bf[s] .."+'"
else return x
end
end )
print(cookie)
-- second example
cookie = "01sdz"
for i=0, 9 do
cookie = string.gsub(cookie, i, "'+".. bf[i] .."+'")
-- may be use bf[i]:gsub( '([%%])', '%%%1') with escape escaping symbol %
end
for i= string.byte('a'), string.byte('z') do
local v = bf[string.char(i)]
if v then
cookie = cookie:gsub( string.char(i), "'+".. v:gsub( '([%%])', '%%%1') .."+'")
end
end
print(cookie)
result
'+(((_<<_)<<_)+''+(({}>[])-(()>[]))+'sd'+(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%)%(()>[])%)%(()>[])%+'
'+(((_<<_)<<_)+''+(({}>[])-(()>[]))+'sd'+(({}>[])-(()>[]))])*(()>[])%(((_<<_)<<_)+((_<<_)*_))(()>[])%(()>[])%(()>[])%)%(()>[])%)%(()>[])%+'
I updated my code, anyway the second example will help you

Best way to import bulk data into ArangoDB

I'm currently working on an ArangoDB POC. I find that the time taken for document creation is very high in ArangoDB with PyArango. It takes about 5 minutes to insert 300 documents. I've pasted the rough code below, please let me know if there are better ways to speed this up :
with open('abc.csv') as fp:
for line in fp:
dataList = line.split(",")
aaa = dbObj['aaa'].createDocument()
bbb = dbObj['bbb'].createDocument()
ccc = dbObj['ccc'].createEdge()
bbb['bbb'] = dataList[1]
aaa['aaa'] = dataList[0]
aaa._key = dataList[0]
aaa.save()
bbb.save()
ccc.links(aaa,bbb)
ccc['related_to'] = "gfdgf"
ccc['weight'] = 0
ccc.save()
The different collections are created by the below code :
dbObj.createCollection(className='aaa', waitForSync=False)
for your problem with the batch mode in the arango java driver. if you know the key attributes of the vertices you can build the document handle by "collectionName" + "/" + "documentKey".
Example:
arangoDriver.startBatchMode();
for(String line : lines)
{
String[] data = line.split(",");
BaseDocument device = new BaseDocument();
BaseDocument phyAddress = new BaseDocument();
BaseDocument conn = new BaseDocument();
String keyDevice = data[0];
String handleDevice = "DeviceId/" + keyDevice;
device.setDocumentKey(keyDevice);
device.addAttribute("device_id",data[0]);
String keyPhyAddress = data[1];
String handlePhyAddress = "PhysicalLocation/" + keyPhyAddress;
phyAddress.setDocumentKey(keyPhyAddress);
phyAddress.addAttribute("address",data[1]);
final DocumentEntity<BaseDocument> from = arangoDriver.graphCreateVertex("testGraph", "DeviceId", device, null);
final DocumentEntity<BaseDocument> to = arangoDriver.graphCreateVertex("testGraph", "PhysicalLocation", phyAddress, null);
arangoDriver.graphCreateEdge("testGraph", "DeviceId_PhysicalLocation", null, handleDevice, handlePhyAddress, null, null);
}
arangoDriver.executeBatch();
I would build all of the data to be inserted into a json formatted string and use createDocumentRaw to create them all at once with one save.

One Esp8266 Client One Esp8266 Server

I did Server-Client Application with lua using one Esp8266. I wanna do this with two Esp8266. I wanna use one of these Esp8266 is Server and the other other one is Client. You can see below first code using for get RSSI from one AP and second code is using for writing these RSSI in a Server. How can i placed these two codes in two Esp8266?
i=5
tmr.alarm(1,10000,1, function()
print(wifi.sta.getap(scan_cfg, 1, listap))
if i>1 then
print(i)
i=i-1
else
tmr.stop(1)
print("Timer Durdu")
end
end
)
function listap(t)
for bssid,v in pairs(t) do
local ssid = string.match(v, "([^,]+)")
l=string.format("%-10s",ssid)
stringtoarray = {}
index = 1
for value in string.gmatch(v,"%w+") do
stringtoarray [index] = value
index = index + 1
end
print(l)
print(stringtoarray[2])
end
end
scan_cfg = {}
scan_cfg.ssid = "VSP250s"
scan_cfg.bssid = "00:09:df:8e:03:b4"
scan_cfg.channel = 0
scan_cfg.show_hidden = 1
Second code:
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local buf = "";
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
if(method == nil)then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
end
local _GET = {}
if (vars ~= nil)then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
end
end
buf = buf.."<!DOCTYPE html><html><div id='container'><font size='5'>"
buf = buf..'<style>body{width:auto;height:auto;background-color:#ffffff;}'
buf = buf..'.button {font-size: 20px;}</style>'
buf = buf.."<head> <meta http-equiv='refresh' content=3> "
buf = buf.."<p><h1>RSSI meter<br> ESP8266</h1>";
--buf = buf.."<p>Refresh : <button class='button'>ON</button>&nbsp</p>";
--buf = buf.."<p>Relay Switch : <button class='button'>ON</button>  "
--buf = buf.."<button class='button'>OFF</button><br>"
buf = buf..'<B>Voltage :<font color=red>'..string.format('%s',l)..' V</font></b><br>'
buf = buf..'<B>Current :<B><font color=blue>'..string.format('%g',stringtoarray[2])..' A</font></b><br>'
--buf = buf..'<B>Power Consumption :<B><font color=DeepSkyBlue>'..'Not Available'..'</font></b><br><BR>'
-- buf = buf..'<p>Function Button :<B><font color=BlueViolet>'..button_status..'</font></b><br></p>';
buf = buf..'</head>'
buf = buf..'<br><br><details><summary><font color=red>BURAK IPEK</font><p>'
buf = buf..'<summary><p>Vestel Electronics </p></details>'
buf = buf.."</body></font></div></html>"
client:send(buf);
client:close();
collectgarbage();
end)
end)
Put each code into a lua file. Include both from init.lua with typing
dofile("client.lua");
dofile("server.lua");
To make things easier, write methods.
Good luck.

Encryption sorted...Decryption is close to finished - python 3.4.1

I can encrypt fine. That works will numbers, spaces and upper and lower case. However, when I set my code to decrypt the encrypted message, the code, for some reason, thinks that the decrypted message is empty. It prints an empty space. I'm not explaining it very well, but if you run the code you will understand what I am on about. If you have any ideas, please let me know.
alphabetL = 'abcdefghijklmnopqrstuvwxyz'
alphabetC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
number = '0123456789'
space = ' '
Ll = len(alphabetL)
Lc = len(alphabetC)
Ln = len(number)
Lall = Ll + Lc + Ln
Question1 = input("Hello, please insert the message you want encrypted: ")
key1 = int(input("Please insert the key you want used [Keep between 1 and 26]: "))
cipher = ''
cipher2 = ''
for A in Question1:
if A in alphabetL:
cipher += alphabetL[(alphabetL.index(A)+key1)%Ll]
elif A in alphabetC:
cipher += alphabetC[(alphabetC.index(A)+key1)%Lc]
elif A in number:
cipher += number[(number.index(A)+key1)%Ln]
elif A in space:
cipher += space
else:
print ("Error, please use abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
print (cipher)
Question2 = input("Would you like to decrypt the message? [Y/N]: ")
if Question2 == "Y":
for A in cipher2:
cipher2 += cipher[(cipher(A)-key1)%(len(cipher))]
print (cipher2)

web2py SQLFORM.grid url

When I try to put form = SQLFORM.grid(db.mytable) in my controller the request changes to my/web/site/view?_signature=520af19b1095db04dda2f1b6cbea3a03c3551e13 which causes my if statement in controller to collapse. Can smbd please explain why this happens?
If I put user_signature=False then on view load the grid is shown (though the looks is awful, and I still need to find out how to change the view of my table), but on search,edit, etc. click, the same thing happens again. The url is changed and I get an error
Any suggestions?
thank you
EDIT
This is my edit function
#auth.requires_login()
def edit():
#Load workers
workers = db(db.worker.w_organisation == 10).select(db.worker.w_id_w, db.worker.w_organisation, db.worker.w_first_name, db.worker.w_last_name,db.worker.w_nick_name,db.worker.w_email,db.worker.w_status,db.worker.w_note).as_list()
#Define the query object. Here we are pulling all contacts having date of birth less than 18 Nov 1990
query = ((db.worker.w_organisation == 10) & (db.worker.w_status==db.status.s_id_s))
#Define the fields to show on grid. Note: (you need to specify id field in fields section in 1.99.2
fields = (db.worker.w_first_name, db.worker.w_last_name,db.worker.w_nick_name,db.worker.w_email,db.status.s_code,db.worker.w_note)
#Define headers as tuples/dictionaries
headers = { 'worker.w_first_name' : 'Ime',
'worker.w_last_name' : 'Priimek',
'worker.w_nick_name' : 'Vzdevek',
'worker.w_email' : 'E-posta',
'status.s_code': 'Status',
'worker.w_note' : 'Komentar' }
#Let's specify a default sort order on date_of_birth column in grid
default_sort_order=[db.worker.w_last_name]
#Creating the grid object
form = SQLFORM.grid(query=query, fields=fields, headers=headers,searchable=True, orderby=default_sort_order,create=True, \
deletable=True, editable=True, maxtextlength=64, paginate=25,user_signature=False
)
form = SQLFORM.grid(db.worker,user_signature=False)
workersDb = db((db.worker.w_organisation == 10) & (db.worker.w_status==db.status.s_id_s)).select(db.worker.w_id_w, \
db.worker.w_organisation, db.worker.w_first_name, \
db.worker.w_last_name,db.worker.w_nick_name,db.worker.w_email,\
db.status.s_code,db.worker.w_note).as_list()
workersList = []
for rec in workersDb:
status = rec['status']['s_code']
workers = rec['worker']
if not rec["worker"]["w_first_name"]:
polno_ime = rec["worker"]["w_last_name"]
elif not rec["worker"]["w_last_name"]:
polno_ime = rec["worker"]["w_first_name"]
else:
polno_ime = rec["worker"]["w_first_name"] + " " + rec["worker"]["w_last_name"]
rec["worker"]['w_full_name'] = polno_ime
rec["worker"]["w_status"] = status
data = rec["worker"]
#print rec
#print data
workersList.append(rec["worker"])
# If type of arg is int, we know that user wants to edit a script with an id of the argument
if(request.args[0].isdigit()):
script = db(getDbScript(request.args[0])).select(db.script.sc_lls, db.script.sc_name, db.script.id, db.script.sc_menu_data).first()
formData = str(script["sc_menu_data"])
#form = SQLFORM.grid(db.auth_user)
#print formData
# If we dont get any results that means that user is not giving proper request and we show him error
#print script
#Parsing script to be inserted into view
if not script:
return error(0)
return dict(newScript = False, script = script, formData = formData, workers = workersList, form = form)
# If the argument is new we prepare page for new script
elif request.args[0] == 'new':
scripts = db((auth.user.organization == db.script.sc_organization)).select(db.script.sc_name, db.script.id, workers = workersList, form = form)
return dict(newScript = True, scripts = scripts, workers = workersList, form = form)
# Else error
else:
return error(0)
also not to mention the sqlgrid looks awful, here is link to the picture https://plus.google.com/103827646559093653557/posts/Bci4PCG4BQQ

Resources