Send data to server using stm32 and GSM/800/900/M66 module With thingspeak

Hi everyone, this blog is to send a data to ThingSpeak server using the STM32 microcontroller.

What are AT commands?

AT commands are commands which are used to control the modems where AT stands for Attention. These commands were derived from Hayes commands which were used by the Hayes smart modems. Every wireless, as well as the dial up modems, require an AT command to interact with a computer machine. These AT commands along with other extended commands also require Hayes command set as a subset.


  • STM32F303 Discovery board – 1
  • GSM 800/900/M66/M60
  • ST-Link Debugger – 1
  • FTDI – 1
  • Breadboard – 1
  • Jumper wires


The AT commands can be used with GSM module and GPRS MODEMs or phone to access these services and information:

  • SMS
  • MMS
  • Fax
  • Voice link and other data over mobile network
  • Information and configuration concerning the mobile devices or MODEM and SIM card.

Types of AT Commands:

There are four types of AT commands:

Fig. 1: Image Showing Classification of AT Commands

1)      Test commands – used to check whether a command is supported or not by the MODEM.

SYNTAX:                    AT<command name>=? 

For example:              ATD=?

2)      Read command – used to get mobile phone or MODEM settings for an operation.

SYNTAX:                    AT<command name>?

For example:              AT+CBC?

3)      Set commands – used to modify mobile phone or MODEM settings for an operation.

SYNTAX:                    AT<command name>=value1, value2, …, valueN

Some values in set commands can be optional.

For example:              AT+CSCA=”+xxxxxxxxxx”, 120

4)      Execution commands – used to carry out an operation.

SYNTAX:                    AT<command name>=parameter1, parameter2, …, parameterN

The read commands are not available to get value of last parameter assigned in execution commands because parameters of execution commands are not stored.

For example:               AT+CMSS=1,”+ 9876543210”, 120

1)           AT – This command is used to check communication between the module and the computer.

For example,



The command returns a result code OK if the computer (serial port) and module are connected properly. If any of module or SIM is not working, it would return a result code ERROR.

2)            +CMGF – This command is used to set the SMS mode. Either text or PDU mode can be selected by assigning 1 or 0 in the command.  

SYNTAX:         AT+CMGF=<mode>

0: for PDU mode

1: for text mode

The text mode of SMS is easier to operate but it allows limited features of SMS. The PDU      (protocol data unit) allows more access to SMS services but the operator requires bit level knowledge of TPDUs. The headers and body of SMS are accessed in hex format in PDU mode so it allows availing more features.

For example,  



3)            +CMGW – This command is used to store message in the SIM.

SYNTAX:         AT+CMGW=” Phone number”> Message to be stored Ctrl+z

As one types AT+CMGW and phone number, ‘>’ sign appears on next line where one can type the message. Multiple line messages can be typed in this case. This is why the message is terminated by providing a ‘Ctrl+z’ combination. As Ctrl+z is pressed, the following information response is displayed on the screen.

+CMGW: Number on which message has been stored

4)            +CMGS – This command is used to send a SMS message to a phone number.

SYNTAX:         AT+CMGS= serial number of message to be send.

As the command AT+CMGS and serial number of message are entered, SMS is sent to the particular SIM.

            For example,



5)            ATD – This command is used to dial or call a number.

SYNTAX:         ATD<Phone number>;(Enter)

For example,


6)            ATA – This command is used to answer a call. An incoming call is indicated by a message ‘RING’ which is repeated for every ring of the call. When the call ends ‘NO CARRIER’ is displayed on the screen. 

SYNTAX:         ATA(Enter)

As ATA followed by enter key is pressed, incoming call is answered.

For example,




The AT commands for both, GSM module and the mobile phone, are listed below. Some of these commands may not be supported by all the GSM modules available. Also there might be some commands which won’t be supported by some mobile handsets.

List of AT commands:

Testing :

ATChecking communication between the module and computer.

Call control :

ATAAnswer command
ATDDial command
ATHHang up call
ATLMonitor speaker loudness
ATMMonitor speaker mode
ATOGo on-line
ATPSet pulse dial as default
ATTSet tone dial as default
AT+CSTASelect type of address
AT+CRCCellular result codes

Data card Control :

ATSSelect an S-register
ATZRecall stored profile
AT&FRestore factory settings
AT&VView active configuration
AT&WStore parameters in given profile
AT&YSelect Set as power up option
AT+CLCKFacility lock command
AT+COLPConnected line identification presentation
AT+GCAPRequest complete capabilities list
AT+GMIRequest manufacturer identification
AT+GMMRequest model identification
AT+GMRRequest revision identification
AT+GSNRequest product serial number identification (IMEI)

Phone control :

AT+CBCBattery charge
AT+CGMIRequest manufacturer identification
AT+CGMMRequest model identification
AT+CGMRRequest revision identification
AT+CGSNRequest product serial number identification
AT+CMEEReport mobile equipment error
AT+CPASPhone activity status
AT+CPBFFind phone book entries
AT+CPBRRead phone book entry
AT+CPBSSelect phone book memory storage
AT+CPBWWrite phone book entry
AT+CSCSSelect TE character set
AT+CSQSignal quality

Computer data interface :

ATECommand Echo
ATQResult code suppression
ATVDefine response format
ATXResponse range selection
AT&CDefine DCD usage
AT&DDefine DTR usage
AT&KSelect flow control
AT&QDefine communications mode option
AT&SDefine DSR option
AT+ICFDTE-DCE character framing
AT+IFCDTE-DCE Local flow control
AT+IPRFixed DTE rate

Service :

AT+CLIPCalling line identification presentation
AT+CRService reporting control
AT+DRData compression reporting
AT+ILRRDTE-DCE local rate reporting

Network Communication parameter :

ATBCommunications standard option
AT+CBSTSelect bearer service type
AT+CEERExtended error report
AT+CRLPRadio link protocol
AT+DSData compression

Miscellaneous :

A/Re-execute command line
AT?Command help
AT*CStart SMS interpreter
AT*TEnter SMS block mode protocol
AT*VActivate V.25bis mode
AT*NOKIATESTTest command
AT+CESPEnter SMS block mode protocol

SMS Text mode :

AT+CSMSSelect message service
AT+CPMSPreferred message storage
AT+CMGFMessage format
AT+CSCAService centre address
AT+CSMPSet text mode parameters
AT+CSDHShow text mode parameters
AT+CSCBSelect cell broadcast message types
AT+CSASSave settings
AT+CRESRestore settings
AT+CNMINew message indications to TE
AT+CMGLList messages
AT+CMGRRead message
AT+CMGSSend message
AT+CMSSSend message from storage
AT+CMGWWrite message to memory
AT+CMGDDelete message

SMS PDU mode :

AT+CMGLList Messages
AT+CMGRRead message
AT+CMGSSend message
AT+CMGWWrite message to memory

List of commands used in this project and their description





AT+QIFGCNT Select a Context as Foreground Context

AT+QICSGP Select CSD or GPRS as the Bearer

HAL_UART_Transmit(&huart1, (uint8_t *)”AT+QICSGP=1,\”\”\r\n”, sizeof(“AT+QICSGP=1,\”\”\r\n”), 300);

If you are using any other network add related network name.


HAL_UART_Transmit(&huart1, (uint8_t *)”AT+QIREGAPP\r\n”, sizeof(“AT+QIREGAPP\r\n”), 300);

AT+QIACT Activate GPRS/CSD Context

HAL_UART_Transmit(&huart1, (uint8_t *)”AT+QIACT\r\n”, sizeof(“AT+QIACT\r\n”), 300);

AT+QHTTPGET  //Send GET Request to HTTP server

HAL_UART_Transmit(&huart1, (uint8_t *)”AT+QHTTPGET=40\r\n”, sizeof(“AT+QHTTPGET=80\r\n”), 300);

AT+QHTTPREAD//Read the response of HTTP server

HAL_UART_Transmit(&huart1, (uint8_t *)”AT+QHTTPREAD=60\r\n”, sizeof(“AT+QHTTPREAD=60\r\n”), 300);

AT+QIDEACT //Deactivate PDP context.

HAL_UART_Transmit(&huart1, (uint8_t *)”AT+QIDEACT\r\n”, sizeof(“AT+QIDEACT\r\n”), 300);


1 st turn on the gsm module

void gsm_on()


Create GSM SEND function

void gsm_cmd(char *cmd, int gsm_delay)
		HAL_UART_Transmit(&huart1,(uint8_t*) cmd, strlen(cmd),1000);
		HAL_UART_Transmit(&huart3, (uint8_t *)gsm_buffer, strlen(gsm_buffer), 300);

Write code to execute the function at commands

while (1)
  HAL_UART_Transmit(&huart1, (uint8_t *)"AT\r\n", sizeof("AT\r\n"), 300);
  HAL_UART_Transmit(&huart3, (uint8_t *)gsm_buffer, sizeof(gsm_buffer), 300);

  HAL_UART_Transmit(&huart1, (uint8_t *)"AT+QIFGCNT=0\r\n", sizeof("AT+QIFGCNT=0\r\n"), 300);
  HAL_UART_Transmit(&huart3, (uint8_t *)gsm_buffer, sizeof(gsm_buffer), 300);

  HAL_UART_Transmit(&huart1, (uint8_t *)"AT+QICSGP=1,\"\"\r\n", sizeof("AT+QICSGP=1,\"\"\r\n"), 300);
  HAL_UART_Transmit(&huart3, (uint8_t *)gsm_buffer, sizeof(gsm_buffer), 300);

  HAL_UART_Transmit(&huart1, (uint8_t *)"AT+QIREGAPP\r\n", sizeof("AT+QIREGAPP\r\n"), 300);
  HAL_UART_Transmit(&huart3, (uint8_t *)gsm_buffer, sizeof(gsm_buffer), 300);

  HAL_UART_Transmit(&huart1, (uint8_t *)"AT+QIACT\r\n", sizeof("AT+QIACT\r\n"), 300);
  HAL_UART_Transmit(&huart3, (uint8_t *)gsm_buffer, sizeof(gsm_buffer), 300);


  HAL_UART_Transmit(&huart1, (uint8_t *)url, strlen(url), 300);

  HAL_UART_Transmit(&huart1, (uint8_t *)http, strlen(http), 300);

  HAL_UART_Transmit(&huart1, (uint8_t *)"AT+QHTTPGET=40\r\n", sizeof("AT+QHTTPGET=80\r\n"), 300);
  HAL_UART_Transmit(&huart3, (uint8_t *)gsm_buffer, sizeof(gsm_buffer), 300);

  HAL_UART_Transmit(&huart1, (uint8_t *)"AT+QHTTPREAD=60\r\n", sizeof("AT+QHTTPREAD=60\r\n"), 300);
  HAL_UART_Transmit(&huart3, (uint8_t *)gsm_buffer, sizeof(gsm_buffer), 300);

  HAL_UART_Transmit(&huart1, (uint8_t *)"AT+QIDEACT\r\n", sizeof("AT+QIDEACT\r\n"), 300);
  HAL_UART_Transmit(&huart3, (uint8_t *)gsm_buffer, sizeof(gsm_buffer), 300);

You may also like...

13 Responses

  1. Really enjoyed this post, can you make it so I receive an email every time you publish a new article?

  2. Beauty says:

    Its like you learn my mind! You seem to grasp a lot approximately this, such as you wrote the e-book in it or something. I believe that you simply could do with some p.c. to force the message house a little bit, but other than that, this is fantastic blog. An excellent read. I will certainly be back.

  3. Hairstyles says:

    great post, very informative. I ponder why the other specialists of this sector do not realize this. You should continue your writing. I’m confident, you’ve a huge readers’ base already!

  4. Gilberto says:

    This is a topic that is near to my heart… Best wishes!
    Exactly where are your contact details though?

  5. It is in reality a nice and useful piece of information. I am happy that you just shared this useful info with us. Please keep us up to date like this. Thanks for sharing.

  6. Hairstyles says:

    I just could not depart your site prior to suggesting that I actually enjoyed the standard info a person provide for your visitors? Is gonna be back often in order to check up on new posts

  7. I like the helpful information you provide in your articles. I抣l bookmark your blog and check again here frequently. I’m quite certain I抣l learn plenty of new stuff right here! Best of luck for the next!

  8. Noreen says:

    Great delivery. Great arguments. Keep up the great spirit.

  9. Good blog! I truly love how it is simple on my eyes and the data are well written. I’m wondering how I might be notified when a new post has been made. I have subscribed to your feed which must do the trick! Have a great day!

  10. Hey I am so glad I found your website, I really found you by mistake, while I was browsing on Google for something else, Anyways I am here now and would just like to say thanks for a marvelous post and a all round entertaining blog (I also love the theme/design), I don抰 have time to read through it all at the minute but I have book-marked it and also included your RSS feeds, so when I have time I will be back to read more, Please do keep up the awesome work.

  11. Hairstyles says:

    Thanks for your publication. One other thing is that often individual states in the United states of america have their unique laws that affect house owners, which makes it extremely tough for the the legislature to come up with a whole new set of guidelines concerning foreclosed on homeowners. The problem is that every state has own laws which may interact in a negative manner on the subject of foreclosure policies.

  12. Hairstyles says:

    Whoa! This blog looks just like my old one! It’s on a completely different topic but it has pretty much the same page layout and design. Outstanding choice of colors!

  13. Heike says:

    Wonderful beat ! I would like to apprentice whilst you
    amend your site, how could i subscribe for a weblog web
    site? The account aided me a appropriate deal. I have been a little bit acquainted of this your broadcast
    offered bright clear idea

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: