Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AT+HTTPDATA
#1
I'm trying to use the gsm library

gsm.atcmd ('AT + HTTPDATA = 40,10000', response = 'DOWNLOAD', cmddata = '{"code": "02", "message": "Test Loboris"}', printable = True)

where cmddata must be a Json, but it always returns the following error:

Request Body: Invalid Json Syntax! "} \ R \ nOK \ r \ n '

Is there a proper way to assign a Json in cmddata ??

thankful
Reply
#2
The length of your data (json string) is 41 and you have requested sending 40 bytes (AT+HTTPDATA=40,10000).
Reply
#3
(11-21-2018, 09:23 AM)lobo Wrote: The length of your data (json string) is 41 and you have requested sending 40 bytes (AT+HTTPDATA=40,10000).

Thanks.
It worked. But after some execution time I return the 604 stack busy error. Is there any way to fix this error ??
Reply
#4
It is an internal error of your GSM module. It is not related to MicroPython and I don't think you can do anything about it other than reset the module or the protocol stack.
Do you know that you can go online and use other modules, like curl, requests, mqtt, socket, etc. to access the Internet resources the same way as when using WiFi?
Is there any special reason to use the GSM module http functions via AT commands?
Reply
#5
(11-22-2018, 10:21 PM)lobo Wrote: It is an internal error of your GSM module. It is not related to MicroPython and I don't think you can do anything about it other than reset the module or the protocol stack.
Do you know that you can go online and use other modules, like curl, requests, mqtt, socket, etc. to access the Internet resources the same way as when using WiFi?
Is there any special reason to use the GSM module http functions via AT commands?

It is an internal error of your GSM module. It is not related to MicroPython and I don't think you can do anything about it other than reset the module or the protocol stack. 

Reply: Ok.

Do you know that you can go online and use other modules, like curl, requests, mqtt, socket, etc. to access the Internet resources the same way as when using WiFi?

Reply: Yes

Is there any special reason to use the GSM module http functions via AT commands?

Reply: No, I am using the SIM module for internet access, because the location that will be used does not have Wi-Fi. I'm testing in internet mode (gsm off) but I can not access GPS data.

code:

import gsm

gsm.debug (True)
gsm.start (tx = 17, rx = 16, baudrate = 115200, apn = 'clear.com.br', user = 'clear', password = 'clear', connect = True, wait = True)
gsm.status ()

(1, 'Connected')

import machine
uart = machine.UART(2, rx=16, tx=17, baudrate=9600, bits=8, parity=None, stop=1, timeout=1500, buffer_size=1024, lineend='\r\n')
gps = machine.GPS(uart)
gps

GPS(default_timeout=1500, use_crc=True, task_running=False, read_sentences=0)

gps.read()
'' (Does not return GPS information.)
gps.startservice()
True
gps.service()
True

gps.getdata()
((1900, 1, 1, 0, 0, 0, 1, 1), 0.0, 0.0, 0.0, 0, 0, 0.0, 0.0, 0.0)

gps.getdata()
((1900, 1, 1, 0, 0, 0, 1, 1), 0.0, 0.0, 0.0, 0, 0, 0.0, 0.0, 0.0)


What am I doing wrong ??

How can I use GPS in internet mode of the SIM module ??

Thanks
Reply
#6
Which SIM module are you using?

Simcom modules with GPS outputs NMEA data on one of the USB ports.

Your GSM module is connected to the ESP32 via UART port.
When offline, this port is used to execute AT commands.
When connected (online, DATA mode), it is used by PPPoS for Internet access.

The simplest method to access the GPS data is to go offline and use AT commands to access the GPS data.
You can use AT+CGPS=on/off,mode to turn the GPS on/off.
When GPS is on, you can simply use AT+CGPSINFO to get the GPS data. You don't need to use MicroPython GPS module.
See the Simcom's AT Command Manual for sintax and returned data format.

You could also configure Simcom module to output NMEA data to UART using AT+CGPSSWITCH command.
In that case you could use MicroPython GPS module to work with GPS data.
To use SIM module for GSM/Internet again you have to reset it, so I don't think it is a good option.

>>> gsm.start(tx=GSM_TX, rx=GSM_RX, apn='internet.ht.hr')
True
>>> gsm.status()
(98, 'Not started')
>>> gsm.status()
(89, 'Idle')
# GSM is ready, we can now connect to the Internet
>>> gsm.connect()
True
>>> gsm.status()
(1, 'Connected')
>>> gsm.ifconfig()
('10.228.133.40', '255.255.255.255', '192.200.1.21')
>>> 
# ============================================================================
# We can now use all network commands the same way as when connected with WiFi
# ============================================================================

>>> import network, requests

>>> rtc.ntp_sync(server="hr.pool.ntp.org")
>>> rtc.synced()
True
>>> print("Time set:", utime.strftime("%c"))
Time set: Sun Nov 25 10:29:17 2018
>>> 
>>> res = requests.get("http://loboris.eu/ESP32/info.txt")

>>> print(res[2])
================
Welcome to ESP32
================

The ESP32 is a low cost, low power microcontroller
with integrated Wi-Fi & dual-mode Bluetooth,
which employs a dual-core
Tensilica Xtensa LX6 microprocessor.

ESP32 is created and developed by Espressif Systems,
a Shanghai-based Chinese company,
and is manufactured by TSMC using their 40 nm process.

---------
2017 LoBo
---------

# We have to disconnect from Internet to use AT commands
>>> gsm.status()
(1, 'Connected')
>>> gsm.disconnect()
True
>>> gsm.status()
(89, 'Idle')

# ========================================================
# We can now use GPS related AT commands to start/stop GPS
# and to get GPS data
# THE MODULE I'M USING DOES NOT HAVE GPS AND RETURNS ERROR 
# ========================================================
>>> gsm.atcmd("AT+CGPS=1,1")

'\r\nERROR\r\n'
>>> gsm.atcmd("AT+CGPSINFO")
'\r\nERROR\r\n'
>>> 

Reply
#7
(11-25-2018, 10:48 AM)lobo Wrote: Which SIM module are you using?

Simcom modules with GPS outputs NMEA data on one of the USB ports.

Your GSM module is connected to the ESP32 via UART port.
When offline, this port is used to execute AT commands.
When connected (online, DATA mode), it is used by PPPoS for Internet access.

The simplest method to access the GPS data is to go offline and use AT commands to access the GPS data.
You can use AT+CGPS=on/off,mode to turn the GPS on/off.
When GPS is on, you can simply use AT+CGPSINFO to get the GPS data. You don't need to use MicroPython GPS module.
See the Simcom's AT Command Manual for sintax and returned data format.

You could also configure Simcom module to output NMEA data to UART using AT+CGPSSWITCH command.
In that case you could use MicroPython GPS module to work with GPS data.
To use SIM module for GSM/Internet again you have to reset it, so I don't think it is a good option.

>>> gsm.start(tx=GSM_TX, rx=GSM_RX, apn='internet.ht.hr')
True
>>> gsm.status()
(98, 'Not started')
>>> gsm.status()
(89, 'Idle')
# GSM is ready, we can now connect to the Internet
>>> gsm.connect()
True
>>> gsm.status()
(1, 'Connected')
>>> gsm.ifconfig()
('10.228.133.40', '255.255.255.255', '192.200.1.21')
>>> 
# ============================================================================
# We can now use all network commands the same way as when connected with WiFi
# ============================================================================

>>> import network, requests

>>> rtc.ntp_sync(server="hr.pool.ntp.org")
>>> rtc.synced()
True
>>> print("Time set:", utime.strftime("%c"))
Time set: Sun Nov 25 10:29:17 2018
>>> 
>>> res = requests.get("http://loboris.eu/ESP32/info.txt")

>>> print(res[2])
================
Welcome to ESP32
================

The ESP32 is a low cost, low power microcontroller
with integrated Wi-Fi & dual-mode Bluetooth,
which employs a dual-core
Tensilica Xtensa LX6 microprocessor.

ESP32 is created and developed by Espressif Systems,
a Shanghai-based Chinese company,
and is manufactured by TSMC using their 40 nm process.

---------
2017 LoBo
---------

# We have to disconnect from Internet to use AT commands
>>> gsm.status()
(1, 'Connected')
>>> gsm.disconnect()
True
>>> gsm.status()
(89, 'Idle')

# ========================================================
# We can now use GPS related AT commands to start/stop GPS
# and to get GPS data
# THE MODULE I'M USING DOES NOT HAVE GPS AND RETURNS ERROR 
# ========================================================
>>> gsm.atcmd("AT+CGPS=1,1")

'\r\nERROR\r\n'
>>> gsm.atcmd("AT+CGPSINFO")
'\r\nERROR\r\n'
>>> 


Which SIM module are you using?

Reply: SIM800

Thank you very much for the explanation.
I will test
thankful
Reply
#8
SIM800 does not have GPS/GNSS, only SIM868, SIM5320,SIM5360,SIM7500E, and some LTE modules have it
Reply
#9
(11-25-2018, 10:28 PM)lobo Wrote: SIM800 does not have GPS/GNSS, only SIM868, SIM5320,SIM5360,SIM7500E, and some LTE modules have it

Okay, I'm using sim808.


thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)