RC76xx HTTP Connection via PySerial

Hi all, I’m having some issues making HTTP connections in Python (via the serial module) and I’m not sure why—I keep on getting the “5—HTTP connection error due to internal trouble” error.

I’ve had success running the following AT commands outside of Python, even though I get some errors in response:

AT+CGACT=1,3

AT+KCNXFG=3,"GPRS","nimblink.gw12.vzwentp"

AT+KHTTPCFG=3,"www.dweet.io",80
OK

+KCNX_IND: 3,4,1
+KCNX_IND: 3,1,0
+KHTTP_IND: 1,1
+KCNX_IND: 3,5, 30
+KHTTP_ERROR: 1, 5
+KHTTP_IND: 1,0
+KCNX_IND: 3,3
+KCNX_IND: 3, 0, 0

AT+KHTTPCNX=1

+KCNX_IND: 3,4,1
+KCNX_IND: 3,1,0
+KHTTP_IND: 1,1
+KCNX_IND: 3,5, 30
+KHTTP_ERROR: 1, 5
+KHTTP_IND: 1,0

AT+KHTTPGET=1,"/dweet/for/my-thing?hello=world"
CONNECT
...
+KHTTP_IND: 1, 3, 387, 200, "OK"
+KCNX_IND: 3, 5, 30
+KHTTP_ERROR: 1, 5
+KHTTP_IND: 1, 0

I’m not sure why I keep on getting the KHTTP 5 error and then the modem would indicate a successful connection afterwards. In general I’ve been able to execute AT commands through Python’s serial module, but repeating the same AT commands in Python somehow isn’t working.

import serial
s = serial.Serial("/dev/ttyUSB0", ...)
s.write('AT+CGACT=1,3\r'.encode())
s.write('AT+KCNXFG=3,"GPRS","nimblink.gw12.vzwentp"\r'.encode())
s.write('AT+KHTTPCFG=3,"www.dweet.io",80\r'.encode())
...

Usually the error happens when I try to configure the HTTP connection; the modem would try a couple of times, but I typically end up with

KHTTP_ERROR: 1,5

but it never goes anywhere beyond that.

Any help or pointers would be appreciated!

You can try to same command as mine to use profile 1:

AT+KCNXCFG=1,"GPRS","CMHK"
OK
AT+KCNXPROFILE=1
OK
AT+KHTTPCFG=1,"www.google.com",80,0,,,,,0

+KHTTPCFG: 1

OK


+KCNX_IND: 1,4,1



+KCNX_IND: 1,1,0



+KHTTP_IND: 1,1

AT+KHTTPGET=1,"/index.html"
CONNECT
HTTP/1.1 200 OK
date: Thu, 23 Nov 2023 11:18:31 GMT
expires: -1
cache-control: private, max-age=0
content-type: text/html; charset=ISO-8859-1
content-security-policy-report-only: object-src 'none';base-uri 'self';script-src 'nonce-uF_ycRR8sT-Xv0t1Qv5DMg' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
server: gws
x-xss-protection: 0
x-frame-options: SAMEORIGIN
set-cookie: 1P_JAR=2023-11-23-11; expires=Sat, 23-Dec-2023 11:18:31 GMT; path=/; domain=.google.com; Secure


NO CARRIER



+KCNX_IND: 1,5,30



+KHTTP_ERROR: 1,5

at+khttpclose=1

+CME ERROR: 922

at+khttpdel=1
OK


+KCNX_IND: 1,3



+KCNX_IND: 1,0,0

Thanks for the response. Running AT+KCNXPROFILE didn’t seem to fix it, but also now I seem to be running into errors when trying to start an HTTP connection even with the AT command without Python, which previously worked.

Could it be sim card or network issue?

I tried a few different things and somehow landed at a working solution where I detach and then re-attach the packet service with AT+CGATT=0 then AT+CGATT=1. The odd thing is that after activating the PDP context (with AT+CGACT=1,3) the packet service is already attached, hence the need to detach before re-attaching.

So the sequence that ended up working (multiple times) is

AT+CGACT=1,3
AT+KCNXCFG=3,"GPRS","nimblink.gw12.vzwentp"
AT+CGATT=0
AT+CGATT=1
(wait for OK)
AT+KHTTPCFG=3,"dweet.io",80
AT+KHTTPGET=1,...

This works both in Python and through plain AT commands. One other thing to note is that after the detach/re-attach procedure, the responses I get after AT+KHTTPCFG seem to be shorter—the modem only needs to make 1 attempt and is then able to connect.