May 12, 2024

Sim900a http, SIM900A access HTTP method

Use the Arduino control device to read the data and then transfer it to the server over the mobile network. The SIM900A module with a punctual atom is selected. A listener is deployed on the server, and the Arduino controls the SIM900A to send data to the server via TCP.

Can SIM900A access web pages? Let's take a look at how SIM900A accesses HTTP.

1. To access the webpage, you must first go online.

How does the mobile phone go online? Just open the "data connection". Yep. But how does the mobile phone know how to access the network? When I think of using Hero in the same year, I set the APN countless times, as shown below.

Sim900a http, SIM900A access HTTP method

Sim900a http, SIM900A access HTTP method

do you understand? There is a default network access point in the phone. When the "data connection" is turned on, the phone will access the specified access point. Then, look back at the parameters of the AT+SAPBR command, which is the case. Then we execute the following AT command:

(1) AT+SAPBR=3,1, “APN”, “cmnet”: This command sets the access point name (the second line of the fourth picture).

(2) AT+SAPBR=3,1, “PHONENUM”, “12345678900”: Set the phone number.

The other parameters don't need this, because there is no setting on the fourth picture.

(3) AT+SAPBR=4, 1: Query parameter settings.

(4) AT+SAPBR=5, 1: Save the current parameter settings to RAM. You don't need to set it up next time, just open it.

What is the meaning of the "1" in the four instructions? In fact, I did not make it very clear, even if it is a logo.

(5) AT+SAPBR=1, 1: Open the bearer, my understanding is that you have opened the “data connection”.

(6) AT+SAPBR=2, 1: This command can check the status of the access network and the IP address.

Sim900a http, SIM900A access HTTP method

Ok, now I have access to the network (the second parameter returned is 1 for connection), my IP address is "10.129.8.149" (3rd parameter).

2. Without UC, do I visit the webpage?

Take it easy. First look at the "Chapter 10 HTTP Application AT Command", a total of seven instructions. The basic idea is to initialize, then set the parameters, activate HTTP, wait until the corresponding, then read the returned data, and finally close. Below, I want to visit our college website: http://.

(1) AT+HTTPINIT: Initialize HTTP.

(2) AT+HTTPPARA=“CID”, “1”: Set the bearer context identifier, which is consistent with the above.

(3) AT+HTTPPRAR=“URL”, “http://”: Set the website you want to visit, and add the “http://” protocol.

We will not set other parameters for the time being.

(4) AT+HTTPACTION=0: Activate HTTP request, 0 means get mode, 1 means post mode, 2 means head (this does not know what you mean).

Be patient at this time, and return to the HTTP state after OK. My status is as follows:

Sim900a http, SIM900A access HTTP method

Did you see "200"? This shows that the visit was successful. That "0" means your access method, we just used get to access. What is the last "30188"? Well, it is DataLen, which is the length of the content of the web page in bytes.

Ok, how do you get the content of the webpage? The AT+HTTPREAD command is now available.

(5) AT+HTTPREAD=1, 30188: Read HTTP corresponding data. 1 means reading from the first byte and reading 30188 bytes.

If we operate correctly and we know what HTML is, we will be surprised to find out that the content of the page has been read. Hahahaha!

(6) AT+HTTPTERM: After the visit is over, remember to terminate the HTTP service.

(7) AT+SAPBR=0, 1: Don't forget to turn off the bearer.

OK, in this way, we have realized the problem that SIM900A accesses the webpage through GET.

Of course, this is a very simple operation. We will definitely encounter problems like this, such as:

(1) The AT+HTTPREAD command can read up to 102,400 bytes of data. What if the amount of data returned by a web page exceeds 102,400?

(2) How to submit data through POST?

GET request:

[html] view plain copyAT+HTTPTERM

AT+CSQ

AT+CGATT?

AT+SAPBR=3,1, "CONTYPE", "GPRS"

AT+SAPBR=1,1

AT+HTTPINIT

AT+HTTPPARA="URL", "http://127.0.0.1:3000/v1/test"

AT+HTTPACTION=0 //Send GET request, pay attention to the returned status code

AT+HTTPREAD //read data

POST request:

[html] view plain copyAT+HTTPTERM

AT+CSQ

AT+CGATT?

AT+SAPBR=3,1, "CONTYPE", "GPRS"

AT+SAPBR=1,1

AT+HTTPINIT

AT+HTTPPARA=“URL”, “http://“span style=”font-family: Arial, HelveTIca, sans-serif;”” 127.0.0.1:300 “/span” “span style=”font-family: Arial, HelveTIca, sans-serif; ""0/v1/mbdevices?devsn=12345678&devtype=abc"//span

AT+HTTPACTION=1 //Send POST data, pay attention to the returned status code

AT+HTTPREAD //read data

Automobile Connector

Automobile Connector

Automobile Connector

ATKCONN ELECTRONICS CO., LTD , https://www.atkconn.com