HL7650 modem download file issue

I am using a HL7650 modem. A task to do is download a file from a file server. The file is not downloaded complete and the number of bytes downloaded varies in each attempt.

I am using the HL7560 with an Arduino MKR1000 and the library TinyGSM. The commands the library send to the modem are:

AT+CGREG?
AT+CGACT=0,1
AT+KCNXCFG=1,"GPRS","internet.itelcel.com"
AT+CGDCONT=1,"IP","internet.itelcel.com"
AT+CGACT=1,1
AT+CGATT=1
AT+KTCPCFG?
AT+KTCPCLOSE=1,1
AT+KTCPDEL=1
AT+KTCPCFG?
AT+KTCPCFG=1,0,"www.lefalme.com.mx",80
AT+KTCPCNX=1
AT+KTCPSTAT=1
AT+KTCPSND=1,30
CONNECT
GET /OTA/DownloadFile.ino HTTP/1.0
--EOF--Pattern--

I send them directly to the modem and a I get


+CREG: 1,1

OK

+CGREG: 0,1

OK

OK

+KCNX_IND: 1,0,0

OK

OK

OK

OK

+KTCPCFG: 1,0,1,0,,"www.lefalme.com.mx",80,4923,0,0,0,0

OK

OK

OK

OK

+KTCPCFG: 1

OK

OK

+KCNX_IND: 1,4,1

+KCNX_IND: 1,1,0

+KTCP_IND: 1,1

+KTCPSTAT: 3,-1,0,0

OK

CONNECT

NO CARRIER
NO Carrier: Call dis-connected


+KTCP_NOTIF: 1,8

+KTCP_DATA: 1,1276

+KTCP_DATA: 1,1276

+KTCP_DATA: 1,1276

+KTCP_DATA: 1,1276

+KTCP_DATA: 1,1276

+KTCP_DATA: 1,1276

+KTCP_DATA: 1,1132

+KTCP_DATA: 1,1276

+KTCP_DATA: 1,294

+KTCP_NOTIF: 1,4

ERROR

My question is what modification must be done so that the commands work correctly with the HL7650. The operation is correct but for small files (<1000 bytes) For relatively large files (>50,000 bytes), the downloaded file is incomplete.

how about using AT+KTCPSTART?

Thanks but the behavior with KTCPSND and KTCPSTART is the same. The file is not downloaded complete.

are you using UART or USB?

It is a PCB with the Sierra HL7650, the MKR1000 and other components integrated. Internal communication must be UART. The PCB only has USB external serial communication to upload the sketch to the MKR1000.

Did you enable flow control?
Can you route out the usb to PC?

1)-Do you mean with:

AT&K

If so, I did not.

2)-I do not understand very well, but I can display everything on the computer.

  1. then you can try to enable the flow control and retry
  2. routing out the USB and redo the test can let you know if problem only happens in UART

I am trying with the script:

AT&F
AT&K3
AT+CGREG?
AT+CGACT=0,1
AT+KCNXCFG=1,"GPRS","internet.itelcel.com"
AT+CGDCONT=1,"IP","internet.itelcel.com"
AT+CGACT=1,1
AT+CGATT=1
AT+KTCPCFG?
AT+KTCPCLOSE=1,1
AT+KTCPDEL=1
AT+KTCPCFG?
AT+KTCPCFG=1,0,"www.lefalme.com.mx",80
AT+KTCPCNX=1
AT+KTCPSTAT=1
AT+KTCPSTART=1
GET /OTA/DownloadFile.ino HTTP/1.1\r\nHost: www.lefalme.com.mx\r\nConnection: close\r\n\r\n

However, I get the 400 Bad Request error from the server. I do not identify the error.

The complete output is:

AT&F

OK
AT&K3

OK
AT+CGREG?

+CGREG: 0,1

OK
AT+CGACT=0,1

OK

+KCNX_IND: 1,0,0
AT+KCNXCFG=1,"GPRS","internet.itelcel.com"

OK
AT+CGDCONT=1,"IP","internet.itelcel.com"

OK
AT+CGACT=1,1

OK
AT+CGATT=1

OK
AT+KTCPCFG?

+KTCPCFG: 1,0,1,0,,"www.lefalme.com.mx",80,1199,0,0,0,0

OK
AT+KTCPCLOSE=1,1

TCP connection is closed by remote server

+CME ERROR: 922
AT+KTCPDEL=1

OK
AT+KTCPCFG?

OK
AT+KTCPCFG=1,0,"www.lefalme.com.mx",80

+KTCPCFG: 1

OK
AT+KTCPCNX=1

OK

+KCNX_IND: 1,4,1

+KCNX_IND: 1,1,0

+KTCP_IND: 1,1
AT+KTCPSTAT=1

+KTCPSTAT: 3,-1,0,0

OK
AT+KTCPSTART=1

CONNECT
HTTP/1.1 400 Bad Request
Date: Mon, 21 Feb 2022 07:42:37 GMT
Server: Apache
Upgrade: h2,h2c
Connection: Upgrade, close
Accept-Ranges: bytes
Vary: Accept-Encoding,User-Agent
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
Content-Type: text/html




<!DOCTYPE html>
<html>
    <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>400 Bad Request</title>
    <style type="text/css">
        body {
            font-family: Arial, Helvetica, sans-serif;
            font-size: 14px;
            line-height: 1.428571429;
            background-color: #ffffff;
            color: #2F3230;
            padding: 0;
            margin: 0;
        }
        section, footer {
            display: block;
            padding: 0;
            margin: 0;
        }
        .container {
            margin-left: auto;
            margin-right: auto;
            padding: 0 10px;
        }
        .response-info {
            color: #CCCCCC;
        }
        .status-code {
            font-size: 500%;
        }
        .status-reason {
            font-size: 250%;
            display: block;
        }
        .contact-info,
        .reason-text {
            color: #000000;
        }
        .additional-info {
            background-repeat: no-repeat;
            background-color: #293A4A;
            color: #FFFFFF;
        }
        .additional-info a {
            color: #FFFFFF;
        }
        .additional-info-items {
            padding: 20px 0;
            min-height: 193px;
        }
        .contact-info {
            margin-bottom: 20px;
            font-size: 16px;
        }
        .contact-info a {
            text-decoration: underline;
            color: #428BCA;
        }
        .contact-info a:hover,
        .contact-info a:focus,
        .contact-info a:active {
            color: #2A6496;
        }
        .reason-text {
            margin: 20px 0;
            font-size: 16px;
        }
        ul {
            display: inline-block;
            list-style: none outside none;
            margin: 0;
            padding: 0;
        }
        ul li {
            float: left;
            text-align: center;
        }
        .additional-info-items ul li {
            width: 100%;
        }
        .info-image {
            padding: 10px;
        }
        .info-heading {
            font-weight: bold;
            text-align: left;
            word-break: break-all;
            width: 100%;
        }
        .info-server address {
            text-align: left;
        }
        footer {
            text-align: center;
            margin: 60px 0;
        }
        footer a {
            text-decoration: none;
        }
        footer a img {
            border: 0;
        }
        .copyright {
            font-size: 10px;
            color: #3F4143;
        }
        @media (min-width: 768px) {
            .additional-info {
                position: relative;
                overflow: hidden;
                background-image: none;
            }
            .additional-info-items {
                padding: 20px;
            }
            .container {
                width: 90%;
            }
            .additional-info-items ul li {
                width: 100%;
                text-align: left;
            }
            .additional-info-items ul li:first-child {
                padding: 20px;
            }
            .reason-text {
                font-size: 18px;
            }
            .contact-info {
                font-size: 18px;
            }
            .info-image {
                float: left;
            }
            .info-heading {
                margin: 62px 0 0 98px;
            }
            .info-server address {
                text-align: left;
                position: absolute;
                right: 0;
                bottom: 0;
                margin: 0 10px;
            }
            .status-reason {
                display: inline;
            }
        }
        @media (min-width: 992px) {
            .additional-info {
BvwzqOluTvhDBVB2a4Iyx/4UxLrx8goycW0UEgO4y2L3H+Ul5XI/4voc6rZkA3Bpv3njfS/nhR781E54N6t4OeWxQxuknguJ1S84ARR4RwAqtmaCFZnRiL2lbM+HaAC5npq+IwF+6hhfBWzNNlW6qCrGXRyza0yNOd1E1fsYUC7UV2Jop7XyXbsw90KYUInjpkRcecWfkEmdCAehgueuTmNt+shkReKd3v67nP9cNDJHvoD++xdvpovXKCp5SfoGxHsj0yF+IwHUus7smVh8IHVGIwJtLy7uN6Pe/wAnrBxOnAayISLWkQ8woBKyR++dUTsuEK+L8p2BD4fGdsfqhxGQTQZluHULXrRsUFfBE0OgzIlraR8vkw6qnXmuDSF8RgS8th+d+phci8FJf1fwapi44rFpfqTZAnW+JFRG3kf94Z+sSqdR1UIiI/dc/B6N/M9WsiADO00A3QU0hohX5RTdeCrstyT1WphURTBevBaV4iwYJGGctRDC1FsGaQ3RtGFfL4os34g6T+AkAT84bs0fX2weS88X7X6hXRDDRzdwHZ/5D2hjjght3Mb5y1NINq+beZBu8d84657wPYfN8pZBc0g+JKiKYiNr9r4v1Zrvdbtazp16TSCOfZppMiGD6iVqr271oVokU6AJ9U5FGnXIww5mH+kLEhxI1cl20QCGCTgRMA/3+F2lRXXtzXhURPTTt9GQA6h+d/1dE5An9GRH5o5mwIgKHvhCBi5j60Bci8oe+EKEPrYmg+QNNOw3PdCLgpBUROPQ18mX1ZEx8p9//Ii0qc3Qi6CmAU1dEpD9SA1tT98/GZadvf29GxPYPh9n+MjAuRNg/Hc4WYm8WjT0pABNB7WkAb81kz8fEo5Na0rAQYU8KQEWEPSkAaafnRPiXEGHPCCbcnxphIEPPnhXc9XkRNuHh3Cw8JXteeCV7Zjg/wua8YGl3XvDUPy/c/Avd4/hNDSqegQAAAABJRU5ErkJggg==);
            }
            .container {
                width: 70%;
            }
            .status-code {
                font-size: 900%;
            }
            .status-reason {
                font-size: 450%;
            }
        }
    </style>
    </head>
    <body>
        <div class="container">
            <secion class="response-info">
                <span class="status-code">400</span>
                <span class="status-reason">Bad Request</span>
            </section>

            <section class="contact-info">
                Please forward this error screen to s144.servername.online's <a href="mailto:admin@hostpapa.ca?subject=Error message [400] (none) for (none)/OTA/DownloadFile.ino port 80 on Sunday, 20-Feb-2022 23:42:37 PST"> WebMaster</a>.
            </section>

            <p class="reason-text">Your browser sent a request that this server could not understand:</p>
        </div>
        <section class="additional-info">
            <div class="container">
                <div class="additional-info-items">
                    <ul>
                        <li>
                            <img src="/img-sys/server_misconfigured.png" class="info-image" />
                            <div class="info-heading">
                                (none)/OTA/DownloadFile.ino (port 80)
                            </div>
                        </li>
                        <li class="info-server"></li>
                    </ul>
                </div>
            </div>
        </section>
        <footer>
            <div class="container">
                <a href="http://cpanel.com/?utm_source=cpanelwhm&utm_medium=cplogo&utm_content=logolink&utm_campaign=400referral" target="cpanel" title="cPanel, Inc.">
                    <img src="/img-sys/powered_by_cpanel.svg" height="20" alt="cPanel, Inc." />
                    <div class="copyright">Copyright © 2016 cPanel, Inc.</div>
                </a>
            </div>
        </footer>
    </body>
</html>

NO CARRIER
NO Carrier: Call dis-connected


+KTCP_NOTIF: 1,4

is this server problem?
Have you tried with other server like google server?

I have changed the line:

GET /OTA/DownloadFile.ino HTTP/1.1\r\nHost: www.lefalme.com.mx\r\nConnection: close\r\n\r\n

for the line

<cr><lf>GET /OTA/DownloadFile.ino HTTP/1.1<cr><lf>Host:www.lefalme.com.mx<cr><lf>Connection:keep-alive<cr><lf>

and now the script download the file. I am going to review it to see if it is complete.

The file is complete. I run the script using the “AT Command Tester V27” software.

If I implement the script using the Arduino MKR1000, it does not work. Below is the sketch and the console output. I know I missing something that “AT Command Tester V27” handles, but I have no idea what it is.

CODE

#define SerialAT Serial1

// HL 7650 Pin definition
#define HL_PWR_ON 5                                                             //Sierra PWR_ON Pin
#define HL_RST_N  4                                                             //Sierra RESET_IN_N
#define HL_GP_2   3                                                             //Sierra GPIO2

void setup()
{
  // Set console baud rate
  Serial.begin(115200);
  SerialAT.begin(115200);

  long timeStartRunning = millis();
  while (!Serial&&millis()-timeStartRunning<=3000)
    ;

  // Initialize Sierra
  sierra_Init();

  sendATcommand("AT&F" ,2000);
  sendATcommand("AT+CGREG?" ,2000);
  sendATcommand("AT+CPIN?" ,2000);
  sendATcommand("AT+CGACT=0,1" ,2000);
  sendATcommand("AT+KCNXCFG=1,\"GPRS\",\"internet.itelcel.com\"",2000);
  sendATcommand("AT+CGDCONT=1,\"IP\",\"internet.itelcel.com\"",2000);
  sendATcommand("AT+CGACT=1,1",5000);
  sendATcommand("AT+CGATT=1",2000);
  sendATcommand("AT+KTCPCFG?",2000);
  sendATcommand("AT+KTCPCLOSE=1,1",2000);
  sendATcommand("AT+KTCPDEL=1",2000);
  sendATcommand("AT+KTCPCFG?",2000);
  sendATcommand("AT+KTCPCFG=1,0,\"www.lefalme.com.mx\",80",2000);
  sendATcommand("AT+KTCPCNX=1",2000);
  sendATcommand("AT+KTCPSTAT=1",2000);
  sendATcommand("AT&K3",2000);
  sendATcommand("AT+KTCPSTART=1",10000);
  sendATcommand("\r\nGET /OTA/DownloadFile.ino HTTP/1.1\r\nHost:www.lefalme.com.mx\r\nConnection:keep-alive\r\n\r\n",30000);
}

void loop()
{
  delay(1000);
}

// This function "sierra_Init()" must be included to run sierra chip and in setup
//------------------------------------------------------------------------------
void sierra_Init()
//------------------------------------------------------------------------------
{
  //////////////////////////////////////////////////////////////////
  // Setting POWER_ON Pin active Low for powering up sierra chip.//
  // Setting PWR_ON to active HIGH will make HL7650 to power off//
  ///////////////////////////////////////////////////////////////

  pinMode(HL_PWR_ON, OUTPUT);
  digitalWrite(HL_PWR_ON, LOW);

  //////////////////////////////////////////////////////////////////////////////
  // Setting UART channel for sierra communication                            //
  // Default baud rate is 115200                                              //
  //////////////////////////////////////////////////////////////////////////////

  SerialAT.begin(115200);

  //////////////////////////////////////////////////////////////////////////////
  // RESET_IN_N signal - active low for 20ms to restart HL7650                //
  //////////////////////////////////////////////////////////////////////////////
  pinMode(HL_RST_N, OUTPUT);
  digitalWrite(HL_RST_N, HIGH);

  //////////////////////////////////////////////////////////////////////////////
  // Sierra_GPIO2 signal(IN/OUTPUT) - is used to trigger HL7650 to wake up    //
  // from sleep mode                                                          //
  //////////////////////////////////////////////////////////////////////////////
  pinMode(HL_GP_2, INPUT);
  digitalWrite(HL_GP_2, HIGH);
}
void sendATcommand(const char *toSend, unsigned long milliseconds) {
  Serial.print("Sending: ");
  Serial.println(toSend);
  SerialAT.println(toSend);
  unsigned long startTime = millis();
  Serial.print("Received: ");
  while (millis() - startTime < milliseconds) {
    if (SerialAT.available())
    {
      char c = (char)SerialAT.read();
      Serial.print(c);
    }
  }
  Serial.println("-------------------------");
}

CONSOLE OUTPUT

Sending: AT&F
Received: AT&F

OK
-------------------------
Sending: AT+CGREG?
Received: AT+CGREG?

+CGREG: 0,1

OK
-------------------------
Sending: AT+CPIN?
Received: AT+CPIN?

+CPIN: READY

OK
-------------------------
Sending: AT+CGACT=0,1
Received: AT+CGACT=0,1

OK

+KCNX_IND: 1,0,0
-------------------------
Sending: AT+KCNXCFG=1,"GPRS","internet.itelcel.com"
Received: AT+KCNXCFG=1,"GPRS","internet.itelcel.com"

OK
-------------------------
Sending: AT+CGDCONT=1,"IP","internet.itelcel.com"
Received: AT+CGDCONT=1,"IP","internet.itelcel.com"

OK
-------------------------
Sending: AT+CGACT=1,1
Received: AT+CGACT=1,1

OK
-------------------------
Sending: AT+CGATT=1
Received: AT+CGATT=1

OK
-------------------------
Sending: AT+KTCPCFG?
Received: AT+KTCPCFG?

+KTCPCFG: 1,0,1,0,,"www.lefalme.com.mx",80,3134,0,0,0,0

OK
-------------------------
Sending: AT+KTCPCLOSE=1,1
Received: AT+KTCPCLOSE=1,1

ERROR
-------------------------
Sending: AT+KTCPDEL=1
Received: AT+KTCPDEL=1

OK
-------------------------
Sending: AT+KTCPCFG?
Received: AT+KTCPCFG?

OK
-------------------------
Sending: AT+KTCPCFG=1,0,"www.lefalme.com.mx",80
Received: AT+KTCPCFG=1,0,"www.lefalme.com.mx",80

+KTCPCFG: 1

OK
-------------------------
Sending: AT+KTCPCNX=1
Received: AT+KTCPCNX=1

OK

+KCNX_IND: 1,4,1

+KCNX_IND: 1,1,0

+KTCP_IND: 1,1
-------------------------
Sending: AT+KTCPSTAT=1
Received: AT+KTCPSTAT=1

+KTCPSTAT: 3,-1,0,0

OK
-------------------------
Sending: AT&K3
Received: AT&K3

OK
-------------------------
Sending: AT+KTCPSTART=1
Received: AT+KTCPSTART=1

CONNECT
-------------------------
Sending: 
GET /OTA/DownloadFile.ino HTTP/1.1
Host:www.lefalme.com.mx
Connection:keep-alive


Received: HTTP/1.1 200 OK
Date: Mon, 28 Feb 2022 07:21:35 GMT
Server: Apache
Upgrade: h2,h2c
Connection: Upgrade, Keep-Alive
Last-Modified: Sat, 15 Jan 2022 06:16:26 GMT
Accept-Ranges: bytes
Content-Length: 9778
Vary: Accept-Encoding,User-Agent
Keep-Alive: timeout=2, max=100

//#def o"
eD _
 :dDn_0rfeeR2#YUfefdeX1el#RdY_0fAN0c  AT
DMUeMfI
ei
Siduen ygafMaNem;P= O
h[r.hGbhSw;
da=l
UT
O/.t8dC teedilGbeGeencmeRA_/PonN      efi        
H           Sie

lostEk,tAUpdwaboolegBlsOFcrmwun,201 arar;

vop(/le.0tns)il&mimeing
  Set("")l.pRS / md rialAn(1
nMO/ Ie   sitse
FOGS   th GO iN   00)gitGSLOW   rtte soe
 skallnstest  iniem.  tarendStmm.foriMo
rm nf." Fr))rian("
  10 r }
.prOKer("C toSert(
 emec,GP,GRD)) Stln(;
y(1   re
i(
o aock(

stOirk =)ECKWAvoi
{
hecateurllaeFck>ECMWAchirmte()#if SM
fui)nrhe----------------sier()
-------------------//////////////////// SOWE actfor p uch PWcil6r////////////nMoR_);
alWrWR;
////////////////////Sett chr mun         Dd 1     //////////
  beg);
///////////////////// RE stivr st0     /////////////// LPgLG//////////// SiO2 /OUTis tr50 p // p m                   /////////////
(PgLHiherme( MP t:l.nec);l.Vial"); tiyiHTTP);
(mmengT_HTI
 entr  {i.d;}
is(arnecME_CO)
  Sin  
  milmegCoP>HTTTI   prto coo:eS  AUm 

r(
i"U1.0  cintHosRVE;
 .pcto;
arnecm i e")le(-tyiHTAINN (abl        {Sert("   00);
  ial.""meStgC>=_TI   prinanfil DIM c a")connLo    eSgCP)ce
nng tesRntrsLboDat=falewLe;
ienble
 p 
t =ountter0;ioucli);leva
     e re g)
na]y a+; ite=vio3) {
 ltersL0';   rin
  / C "ea    str(TPLL)    trs2)
  rnn or. ig  iscSL     }   Ma fefL  0l)   /"e+)3 F[1 irmi]
    datrrmw=0      er("Lmwan . Iot e up
  nl(  t   /"n
 elstr(nte")  
  cin
   fi
   lne  eB16]
 }
 iL    ianu 
 tu  }  hane  [0
  la=     (a!=us
fl =         te
 dIWNL  iht   BBy}
efT_OAD  ri
 
.pesd:ri(ces  NErin(lo  ct(if-tyiHTAN  riansthrv
onca cl();al\nsc;
m.ne//ntlS edrin();stirk ;

NO CARRIER

+KTCP_NOTIF: 1,4
-------------------------

Only the HTTP headers are fine. I do not recognize the characters corresponding to the data file.