QR Code & mobile devices & the desktop
john at splash21.com
Tue Feb 7 08:07:04 CST 2012
Hi, Nicolas. I had thought the exact same thing - there's no need for
additional hardware if you already have a capable phone / tablet.
I put a simple demo together - just paste the following code into a card
and add a button that calls 'serverReset' and a field called 'Data' to
show incoming data. I've used port 10310 for the connections and my
local ip address is 192.168.0.100 - just replace with your own details.
On your scanner app, after scanning a code, you can just;
put URL("http://192.168.0.100:10310/?" & urlEncode("QR code data
12345...")) into tResponse
You can also just use a browser to test quickly. Don't you just love
all this modern mobile technology?! :D
# reset and listen on a custom port
set the socketTimeoutInterval to 30
accept connections on port 10310 with message "socketConnect"
put the millisecs
on socketConnect pSocket
# just read the first line of the request
read from socket pSocket until CRLF with message "socketReceive"
on socketReceive pSocket, pData
# word 2 is the requested URL
put word 2 of pData into tURL
set itemDel to "?"
if the num of items in tURL > 1 then
# data received
put urlDecode(item 2 of tURL) into tData
put the long date && the long time & LF & \
"Received: " & tData & LF \
into fld "Data"
# process data, store in database, etc...
# mirror the data back to signal success - you could send an md5
hash, etc. instead
put tData into tResponse
# no data received, response will be an error message
put "Error: No data!" into tResponse
# send the response and disconnect
socketRespond pSocket, tResponse
on socketRespond pSocket, pData
# send an HTTP response
put "HTTP/1.1 200 OK" & CRLF into tHeaders
put "Content-Type: " & tType & CRLF after tHeaders
put "Cache-Control: no-cache" & CRLF after tHeaders
put "Connection: Close" & CRLF after tHeaders
put "Date: " & the internet date & CRLF after tHeaders
put "Content-Length: " & length(pData) & CRLF after tHeaders
put CRLF after tHeaders
write tHeaders & pData to socket pSocket
on socketDisconnect pSocket
close socket pSocket
on socketError pSocket
on socketTimeout pSocket
on socketClosed pSocket
On 07/02/2012 10:56, Nicolas Cueto wrote:
> Hello All,
> Given the relatively high price of USB 2D code readers, those recent
> and tempting announcements about QR Code libraries aimed for LC users
> have got me wondering.
> What LC components (add-ons?) and LC commands ought I consider for
> somehow relaying (internet? WIFI?) to a desktop computer some QR Code
> scanned by a mobile device (iPhone or Android tablet)?
> A general idea about the steps involved would be great. And much appreaciated.
> Nicolas Cueto
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
More information about the use-livecode