gprs/ stm32/ std

Posted by millikan at 2020-03-03


Continue with GSM modem and STM32 description. Last article discussed interaction with modem as a phone)(

As shown in the previous example, two USART A's, a timer and an LED output are used here. That is to say, there is no new control relay except one - add output) PA0), through which the module is locked

This is necessary, with the board, the module will be shut down and all settings will be discarded.

The working mode is as follows:

At startup, it automatically sets the speed of USART to a-57600 and starts to send configuration instructions.

Gprs.c.) When these commands are sent, the program will check the response of the module, and if the program fails, the program will pause and start flashing(

Pre tune is at the beginning of the program, block

All that happens) and successful commands, and errors) appear on the terminal.

In error handling unit

while(1) // мигаем 5 секунд и ресетим плату { count_err++; HAL_GPIO_TogglePin(ER_LED_GPIO_Port, ER_LED_Pin); HAL_Delay(100); //if(count_err 49) HAL_NVIC_SystemReset(); }

... has a comment function, you can recalculate the fee) and its modules. Error handling is not only in the initial configuration, but in the future work.

About As an example, two numbers are sent to the get request server

Now, parameter queries have been commented on and provide a simple test site. If you download a program, you will get the page you want

To send data to the server, you must have the server and create a file to check your work.


?php $today = date("Y.m.d H:i:s"); //получаем текущие дату и время $argument_a = $_REQUEST['a']; //получаем значение посланной переменной "а" $argument_b = $_REQUEST['b']; //получаем значение посланной переменной "b" echo "Hello, reciv - "." $argument_a "." $argument_b ".", date - ". "$today"; ?

Cancel the previous line and fill in your address. Parameters may be more, but you have to make sure that the string) does not exceed 64 characters from at.

If a string is larger, then send its part, only the last part contains characters


I mean, if you have a line like this

Then send looks like this

When they come back, what they sent and the date

Then test the function and send the data command if everything is OK





Then test again, if successful, send a read command from the server -

The whole process is described in a little more detail below.

The data is read 1024 bytes (can be enlarged to USART: / u ring. H) and output to the terminal. The place to process the data says, "you can ask a question.

///////////////////////////////// чтение ответа сервера ///////////////////////////////////// if(flag) { flag = 0; HAL_Delay(500); char read_buf[GPRS_RX_BUFFER_SIZE] = {0,}; while(gsm_available()) { uint16_t i = 0; memset(read_buf, 0, GPRS_RX_BUFFER_SIZE); while(gsm_available()) { read_buf[i++] = gsm_read(); if(i GPRS_RX_BUFFER_SIZE - 1) break; } HAL_UART_Transmit(DEBUG, (uint8_t*)"\n----------\nREAD_BUF:\n----------\n", strlen("\n----------\nREAD_BUF:\n----------\n"), 1000); HAL_UART_Transmit(DEBUG, (uint8_t*)read_buf, strlen(read_buf), 1000); // тут можно парсить ответ } }

I have some comments and I don't know what to do. On the one hand, this may be a one-time error). Suppose you send data regularly, and the server fails to accept the request for some reason, and will continue to work normally, On the other hand, it may be a long-term problem.)( The simplest solution is to add a bug counter there, such as "if you have ten times, then rebate the fee."

Let me see what happened, let me command at the terminal

Return to good

0 - get data received - query. 200 - server response code 1270 - Cole - bytes received.

When the command is sent through the terminal, the data will be read to a function that is available in for an infinite period).

If nothing is sent to the server for a period of time (about 4 hours), the GPRS connection will be interrupted and the module will send a notification

About To restore the connection, issue a command

About One in the code deals with this situation

else if(strstr(buf, "+SAPBR") != NULL) { if(strstr(buf, "DEACT") != NULL) { set_comand(ATSAPBR11); // установить соединение } }

All commands are described in the file

, in the "Internet" section.

If the function is cancelled in an infinite loop

Data will be sent every minute


This is almost the same, only in the way of querying the server. Start with adjustments, checks and error handling

Add function

All comments in the code are for checking various states). In file


All work with the network is in function


The request contains the following commands

Send to a port and address module, then send to "connected". If you don't specify ip-at + cipstart = "," TCP, "" "" 80 ", then you can not configure DNS server (command set. U command) atcdnskfg update; / / install DNS server at the beginning of the program

-This command tells the module that data will now be entered( a=33b=55。” The module will send an invitation token. " Then you can enter the data. In order for the module to realize that the data input is over, you can send it to the server, and you must send a character.

Next page)

If you give a command like this - at + cipend = 23) number is a number of bytes sent to the specified number of characters, the module will send data to the server

There is no need to introduce.

Data rows (usually get queries) look like this:

Confirm that the data sending module returns "send OK". Then you can retrieve the response from the server

When we have finished receiving data, we send a connection closing command "+" cipclose. However, it may happen that when we read the data, the module itself will automatically close the connection, and then the command will return an error-

It's no big deal. By the way, all bad modules are responded to by operation not allowed.


There is no doubt about it, but nothing can stop you from giving her what you want.

If you don't send anything for a long time, the module will disable GPRS and send the message "deact" - an infinite cycle of processing.

In the example, it provides an opportunity to call a module when you are sure what you want to do, such as reboot. Other features can be added to the first part.

Using this module as a server, you must have a white IP of the SIM card (APN settings will be different) and a small initialization change. replace

To issue a command

Where 1 is the boot server and 80 is the port. When someone connects to the server, the module sends a message

About I don't know what to do next, because I haven't tried, but obviously, the answer you need is like TCP example. Disable server command


And, more importantly, an example of data transfer and reading from thingspeak.

Thank you.

chat room

STM32 TV chat room