Sim900a application, remote file transfer instance based on SIM900A-GPRS module

SIM900A is a more practical GPRS module. It can be used for data transmission with simple configuration. It can be configured to use AT command to interact. When transmitting data remotely with GPRS, there are two ways. One is normal mode and cannot be sent. One time to send 0x1a to open data transmission, another way to transparent transmission mode, after setting, you can send data to the module all the time, the module will automatically send the data in the buffer, but finally send +++ To exit the transparent data mode, return to the normal mode.

Main features of SIM900A module: SMT package: easy for customers to produce and process; small size: 24*24*3mm; low power consumption: standby mode current is lower than 18mA, sleep mode is lower than 2mA; power supply range is wide: 3.2~4.8V; support frequency band : GSM/GPRS 900/1800MHz; voice coding: support half-rate, full-rate, enhanced rate; support echo suppression algorithm, can adjust echo cancellation elimination based on different client devices through AT command.

Remote file transfer instance based on SIM900A-GPRS module

First way

The sim900a module has a power pin and a serial port pin. The host computer interacts with the module through the serial port. The simplest is to use a usb to serial port USB TTL to connect with the usb port of the host computer. The module supports mobile and Unicom SIM cards. . The test is performed in the Linux environment. You can use the command ls /dev/ttyUSB* to check whether the module is properly mounted. If it is mounted, it usually shows ttyUSB0. It is found that the serial port tool under Linux is not as good as the window. To control reading and writing more aspects.

Under Linux, the device is treated as a file and can interact with the device as easily as reading and writing files. It is best to use only "AT+CSQ" and "AT+COPS" to check the signal quality and operator information before use. If the sim card does not recognize it, the next step cannot be made. Normal mode configuration is simple:

Char c, str[BUFFSIZE];

Memset(str, 0, sizeof(str));

Strcpy(str, "AT+CLPORT=\"TCP\",\"4000\"));

i = write(fd, str, strlen(str));

Printf("str= %s", str);

Sleep(1);

Memset(str, 0, sizeof(str));

Strcpy(str, "AT+CIPSTART=\"TCP\",\"115.28.6.76\",\"4000\");//Connect to a remote server

i = write(fd, str, strlen(str));

Printf("str= %s", str);

Sleep(1);

The sending process can be done in the usual file mode:

While((file_block_length=fread(buff,sizeof(char),BUFFSIZE,fs)))0)

{

Printf("file_block_length:%d", file_block_length);

Memset(str, 0, sizeof(str));

Strcpy(str, "AT+CIPSEND");

i = write(fd, str, strlen(str));

Sleep(1);

i = write(fd, buff, strlen(buff));

Sleep(1);

i = write(fd, &ctemp, sizeof(ctemp));//Start send flag, ox1a

Sleep(1);

Memset(buff,0,BUFFSIZE);

}

This method is mechanical, and the maximum byte sent per time is probably no more than 1300 bytes. The serial port rate is 115200. The sending rate is still very slow. The delay in the program is to ensure that the instruction is executed. In fact, it cannot be. For so long, use the usleep() function to use a shorter time delay.

Second way

Compared with the former method, the main improvement is that the data can be written to the serial port, and the module will automatically send the data in the buffer, but the disadvantage is that the configuration method at the beginning is a bit long, and can be directly applied after being set. In this way, the test is not very stable. When jumping from the data transfer mode to the command mode, it may fail.

The configuration process is as follows:

Char c, str[BUFFSIZE];

/ / Transparent mode configuration process

Memset(str, 0, sizeof(str));

Strcpy(str, "AT+IFC=2,2"); //

i = write(fd, str, strlen(str));

Printf("str= %s", str);

Memset(str, 0, sizeof(str));

Strcpy(str, "AT+CIPMODE=1"); //

i = write(fd, str, strlen(str));

Printf("str= %s", str);

Memset(str, 0, sizeof(str));

Strcpy(str, "AT+CSTT=\"CMNET\" ");

i = write(fd, str, strlen(str));

Printf("str= %s", str);

Memset(str, 0, sizeof(str));

Strcpy(str, "AT+CIICR");

i = write(fd, str, strlen(str));

Printf("str= %s", str);

Memset(str, 0, sizeof(str));

Strcpy(str, "AT+CIFSR");

i = write(fd, str, strlen(str));

Printf("str= %s", str);

Memset(str, 0, sizeof(str));

Strcpy(str, "AT+CIPSTART=\"TCP\",\"115.28.6.76\",\"4000\"");

i = write(fd, str, strlen(str));

Printf("str= %s", str);

/ / Omit the send data part

Sleep(2);

Memset(str, 0, sizeof(str));

Strcpy(str, "+++");

i = write(fd, str, strlen(str)); "/span" // from transparent mode back to command mode

M188

Mtb-Cut M188 Intelligent Film Cutting Machine,Intelligent Film Cutting Machine,Film Cutter,Screen Protector Cutter

Mietubl Global Supply Chain (Guangzhou) Co., Ltd. , https://www.mietublmachine.com

This entry was posted in on