Reading QRCodes

Reading QRCodes

Postby reinaldocrespo » Wed May 17, 2023 7:30 pm

Hello again Fiwinners;

Can anyone here read QR Codes?

This squared dot matrix dots and squares can store a lot of information. Given a QR code storing text, can we read it with fw or harbour? Is anyone here reading QR Codes?

Thank you.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Reading QRCodes

Postby Otto » Wed May 17, 2023 8:17 pm

********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Re: Reading QRCodes

Postby Otto » Wed May 17, 2023 8:23 pm

Dear Reinaldo,

By the way, I found a great plugin for ChatGPT.
It creates a button that allows you to select a file and upload it as a knowledge base.
It uses async to read the file as text and split it into chunks of size 15,000, which are then sent.

Here is a video demonstrating how it works: https://www.youtube.com/watch?v=iR99LO28nzM

You can download the Chrome plugin, called "ChatGPT File Uploader," from this link: https://tinyurl.com/5n7rjhar

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Re: Reading QRCodes

Postby NWKL » Thu May 18, 2023 11:06 am

Reinaldo, sorry for off-topic, some time ago you share in this forum an class to twillio, to send sms, whatsapp, you still using this class? do you make updates to this? can you share?

best regards
NWKL
 
Posts: 26
Joined: Thu Aug 04, 2022 12:45 pm

Re: Reading QRCodes

Postby reinaldocrespo » Thu May 18, 2023 11:55 am

Yes, sure.

I wrote methods to send texts and make phone calls but not to send via WhatsApp although it wouldn't be too hard to add. Keep in mind you will need a web hook set up to catch any incoming texts.

Here is that class:
Code: Select all  Expand view

#define ACCOUNT_SID  "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" //assigned by Twilio
#define AUTH_TOKEN   "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" //assigned by Twilio
#define TEL_FROM     "xxxxxxxxxxx"   //Your Twilio number


#INCLUDE "hbClass.ch"
#include "hbcurl.ch"

CLASS TTwilioSMS

   DATA hCurl
   DATA httpcode
   DATA cLogFile        INIT "Twilio.log"
   DATA cResponse
   DATA cDestinationNum
   DATA cSMSText
   DATA cSMSStatusCallBackURL    INIT ''  //Webhook address where to receive SMS status updates

   DATA cUrl            INIT "https://api.twilio.com/2010-04-01/Accounts/" + ACCOUNT_SID + "/Messages.json"
   DATA cVoiceUrl       INIT "https://api.twilio.com/2010-04-01/Accounts/" + ACCOUNT_SID + "/Calls.json"
   DATA cSayVoice       INIT '<Say voice="alice" language="es-MX">'
   DATA cCallSubject    INIT 'Recorded Message'

   DATA nError          INIT 0
   DATA nMaxLogSize     INIT 32768

   DATA cDateStart, cDateEnd
   DATA cvoiceMail, cReplyEmail
   DATA lDebug          INIT .F.

   METHOD New()
   METHOD End()
   METHOD Send()
   METHOD Reset()

   METHOD MakePhoneCall()
     
   METHOD GetMessagesLog()

ENDCLASS


//------------------------------------------------------------------------------------------------
METHOD New() CLASS TTwilioSMS

   ::hCurl := curl_easy_init()

RETURN Self


//------------------------------------------------------------------------------------------------
METHOD Send() CLASS TTwilioSMS
   Local cPostFields
   Local httpcode

   curl_easy_setopt( ::hCurl, HB_CURLOPT_POST, 1 )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_URL, ::cUrl )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_USERPWD, ACCOUNT_SID + ':' + AUTH_TOKEN )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_DL_BUFF_SETUP )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )

   cPostFields := 'To='    + ::cDestinationNum + ;
                  '&From=' + TEL_FROM +;
                  '&Body=' + curl_easy_escape( ::hCurl, AllTrim( ::cSMSText ) )

   IF !Empty( ::cSMSStatusCallBackURL )
      cPostFields += "&statusCallback="+ ::cSMSStatusCallBackURL
   ENDIF

   If ::lDebug
      LogData( ::cLogFile, { cPostFields }, ::nMaxLogSize )
   endif


   curl_easy_setopt( ::hcurl, HB_CURLOPT_POSTFIELDS, cPostFields )
   ::nError := curl_easy_perform( ::hCurl )
   curl_easy_getinfo( ::hCurl, HB_CURLINFO_RESPONSE_CODE, @httpcode )

   ::httpcode := httpcode

   IF ::nError == HB_CURLE_OK

      ::cResponse = curl_easy_dl_buff_get( ::hCurl )
      IF ::lDebug
         LogData( ::cLogFile, ::cResponse, ::nMaxLogSize )
      ENDIF
   Else

      LogData( ::cLogFile, { "Twilio error sending SMS.  Details below:" },      ::nMaxLogSize )
      LogData( ::cLogFile, { "To", ::cDestinationNum, "SMS Text:", ::cSMSText }, ::nMaxLogSize )
      LogData( ::cLogFile, { "Error Num:", ::nError, "Httpcode:", ::httpcode }, ::nMaxLogSize )
      LogData( ::cLogFile, { "Response:", ::cResponse }, ::nMaxLogSize )
      LogData( ::cLogFile, curl_easy_strerror( ::nError ), ::nMaxLogSize )

   ENDIF

return NIL            

//------------------------------------------------------------------------------------------------
METHOD Reset() CLASS TTwilioSMS
     
   curl_easy_reset( ::hCurl )
   ::nError := HB_CURLE_OK

return NIL



//------------------------------------------------------------------------------------------------
METHOD End() CLASS TTwilioSMS

   curl_easy_cleanup( ::hCurl )
   ::hCurl := Nil  
   hb_gcAll( .t. )

return NIL


//------------------------------------------------------------------------------------------------
//must define ::cDateStart and ::cDateEnd before calling this method.
METHOD GetMessagesLog() CLASS TTwilioSMS
   Local cparms := '?DateSent%3E=' + ::cDateStart + "&DateSent%3C=" + ::cDateEnd + "&PageSize=600"
   Local httpcode

   curl_easy_setopt( ::hCurl, HB_CURLOPT_HTTPGET, 1 )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_URL, ::cUrl + cParms )

   curl_easy_setopt( ::hCurl, HB_CURLOPT_USERPWD, ACCOUNT_SID + ':' + AUTH_TOKEN )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_DL_BUFF_SETUP )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )

   ::nError := curl_easy_perform( ::hCurl )

   curl_easy_getinfo( ::hCurl, HB_CURLINFO_RESPONSE_CODE, @httpcode )

   ::httpcode := httpcode

   IF ::nError = HB_CURLE_OK

      ::cResponse = curl_easy_dl_buff_get( ::hCurl )
      ::cResponse := StrTran( ::cResponse, Chr(10), "" )

   Else

      LogData( ::cLogFile, { "Twilio error sending SMS.  Details below:" },      ::nMaxLogSize )
      LogData( ::cLogFile, { "To", ::cDestinationNum, "SMS Text:", ::cSMSText }, ::nMaxLogSize )
      LogData( ::cLogFile, { "Error Num:", ::nError, "Httpcode:", ::httpcode }, ::nMaxLogSize )
      LogData( ::cLogFile, curl_easy_strerror( ::nError ), ::nMaxLogSize )

   ENDIF

   //MemoWrit( "Twilio.log", ::cResponse )

RETURN NIL

//------------------------------------------------------------------------------------------------
/*sample makeing a call using url to fetch parameters
https://www.twilio.com/docs/voice/api/call-resource

EXCLAMATION_MARK='!'
curl -X POST https://api.twilio.com/2010-04-01/Accou ... Calls.json \
--data-urlencode "Twiml=<Response><Say>Ahoy there$EXCLAMATION_MARK</Say></Response>" \
--data-urlencode "To=+15558675310" \
--data-urlencode "From=+15552223214" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
*/

//Twilml sample parameter "Twiml=<Response><Say>Ahoy there$EXCLAMATION_MARK</Say></Response>"


METHOD MakePhoneCall() CLASS TTwilioSMS
   Local cPostFields
   Local httpcode

   curl_easy_setopt( ::hCurl, HB_CURLOPT_POST, 1 )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_URL, ::cVoiceUrl )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_USERPWD, ACCOUNT_SID + ':' + AUTH_TOKEN )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_DL_BUFF_SETUP )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )

   cPostFields := 'To='    + ::cDestinationNum + ; // Line[ 3 ] +;
                  '&From=' + TEL_FROM +;
                  '&CallReason=' + ::cCallSubject +;
                  '&Twiml=' + ::cSayVoice + ::cVoiceMail + '</Say>' +;
                  '&CallerId='   + ::cReplyEmail


   curl_easy_setopt( ::hcurl, HB_CURLOPT_POSTFIELDS, cPostFields )
   ::nError := curl_easy_perform( ::hCurl )
   curl_easy_getinfo( ::hCurl, HB_CURLINFO_RESPONSE_CODE, @httpcode )

   ::httpcode := httpcode

   IF ::nError = HB_CURLE_OK

      ::cResponse = curl_easy_dl_buff_get( ::hCurl )

   Else

      LogData( ::cLogFile, { "Twilio error making voice call.  Details below:" },      ::nMaxLogSize )
      LogData( ::cLogFile, { "To", ::cDestinationNum, "Message:", ::cVoiceMail }, ::nMaxLogSize )
      LogData( ::cLogFile, { "Error Num:", ::nError, "Httpcode:", ::httpcode }, ::nMaxLogSize )
      LogData( ::cLogFile, curl_easy_strerror( ::nError ), ::nMaxLogSize )

   ENDIF

RETURN NIL
 
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Reading QRCodes

Postby MarcoBoschi » Thu May 18, 2023 1:16 pm



zbarimg is fantastic!
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Reading QRCodes

Postby MarcoBoschi » Thu May 18, 2023 1:29 pm

Reinaldo

Code: Select all  Expand view
c:\Program Files (x86)\ZBar\bin\zbarimg QRCODE.JPG  > TEXT.TXT


fast, accurate, never misses a beat

I loaded 2000 qr codes in my application so the name of the jpg and text in a short time

Thank to Antonio!
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Reading QRCodes

Postby Otto » Tue May 23, 2023 11:54 am

Marco,
>zbarimg is fantastic!
can you show an example how to use?

Thank you and best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Re: Reading QRCodes

Postby MarcoBoschi » Tue May 23, 2023 1:22 pm

Otto,
I create a BAT file and launch it (using __RUN)

Code: Select all  Expand view
cComando := '"c:\Program Files (x86)\ZBar\bin\zbarimg" ' + '"' + cFileJpg + '"' + + " > " + '"' + cFileTxt + '"'
cComando := cComando + crlf + "EXIT" + crlf

MEMOWRIT( "do_scan.bat" , cComando )

__RUN ( "START /MIN do_scan.bat" )
 


Then I read the content from file cFiletxt

Code: Select all  Expand view

IF FILE( cFileTxt )
   cLettura := MemoRead( cFileTxt )
ENDIF
 


Dear Otto zbarimg scan and decode image that I pass in command line
this is my last do_scan.bat

"c:\Program Files (x86)\ZBar\bin\zbarimg" "P:\Misuratori Fiscali\QR CODE\99MEY0xxxxx.jpg" > "P:\Misuratori Fiscali\QR CODE\TXT_LINK\99MEY0xxxxx.TXT"
EXIT

In command line after the name of file thad I have to decode I insert > and the name of file TXT to create containng the results of scan. Then I read this txt
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: nageswaragunupudi and 101 guests