Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » STM32 & SIM900/800 HTTP Post Request in JSON Format
IoT Projects STM32 Projects

STM32 & SIM900/800 HTTP Post Request in JSON Format

Mamtaz AlamBy Mamtaz AlamUpdated:August 21, 20221 Comment5 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

In this post we will learn how to use SIM800 or SIM900 with STM32 Microcontroller & make HTTP Post Request in JSON format to any API Server.


Overview

Apart from Wifi Module or Ethernet Module, the IoT Projects can also be done through SIM800/900 GSM GPRS Module. The main advantage of Cellular IoT compared to Wifi IoT is the availability of network and signal everywhere. In one of my earlier posts, I explained how you can send the sensor data wirelessly using GSM Module to Thingspeak Server. You can check the post here: Send SIM800/900 GSM/GPRS Data to Thingspeak with STM32

But today we will interface the SIM800/900 GSM GPRS Module with STM32, i.e STM32F103C8T6 and develop a code to send the data to any web address or web server using API. We need to send the data in JSON format as direct sending of a string data looks difficult. The whole process and the final code is explained in this post.


Components Required

Following are the components required to learn and get practical experience of this tutorial. All the components can be easily purchased from Amazon. The components purchase link is given as well.

S.N.Components QuantityPurchase Links
1STM32F103C Microcontroller1Amazon | AliExpress
2SIM800/900 GSM Module1Amazon | AliExpress
3DHT11 Sensor1Amazon | AliExpress
4RTC Module DS32311Amazon | AliExpress
512/9V Power Supply1Amazon | AliExpress
6Connecting Wires10Amazon | AliExpress
7Breadboard1Amazon | AliExpress



What is API?

API is the acronym for Application Programming Interface, which is a software intermediary that allows two applications to talk to each other. Each time you use an app like Facebook, send an instant message or check the weather on your phone, you’re using an API.

Example of an API: When you use an application on your mobile phone, the application connects to the Internet and sends data to a server. The server then retrieves that data, interprets it, performs the necessary actions and sends it back to your phone. The application then interprets that data and presents you with the information you wanted in a readable way. This is what an API is – all of this happens via API.


What is JSON Format?

JSON stands for JavaScript Object Notation. It is a lightweight format for storing and transporting data. It is often used when data is sent from a server to a web page.

For example, the following is an example of a simple User object serialized to XML:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<xml>
   <user>
       <firstName>Jason</firstName>
       <middleName>Alexander</middleName>
       <lastName>Smith</lastName>
       <address>
           <street1>1234 Someplace Avenue</street1>
           <street2>Apt. 302</street2>
           <city>Anytown</city>
           <state>NY</state>
           <postalCode>12345</postalCode>
           <country>US</country>
       </address>
   </user>
</xml>

As you can see, the same data represented in JSON is far more efficient, while retaining all of its human-readability:

1
2
3
4
5
6
7
8
9
10
11
12
13
{
"firstName" : "Jason",
"middleName" : "Alexander",
"lastName" : "Smith",
"address" : {
"street1" : "1234 Someplace Avenue",
"street2" : "Apt. 302",
"city" : "Anytown",
"state" : "NY",
"postalCode" : "12345",
"country" : "US"
}
}

JSON is typically used together with IoT protocols that do not provide native support for data structure serialization such as HTTP/Rest, WebSockets, MQTT, and SMQ.

In JSON, data is structured in a specific way. JSON uses symbols like { } , : ” ” [ ] and it has the following syntax:

Data is represented in key/value pairs
1. The colon (:) assigns a value to key
2. key/value pairs are separated with commas (,)
3. Curly brackets hold objects ({ })
4. Square brackets hold arrays ([ ])


Hardware Setup

Let us do some hardware setup now. I am using 2 modules whose data is to be sent to the server via API in JSON format. I am using DHT11 Humidity & Temperature Sensor as I want to send Humidity & Temperature Data. Similarly, I am also using the DS3231 Real Time Clock (RTC) Module to check the time and send it to Server.

Following is the connection diagram below assemble the circuit as shown in the figure.

STM32 GSM JSON API

So I made the same connection here as shown below. So I have powered GSM Module with 12V and STM32 Board with 5V from computer USB port.

STM32F103C8T6 GSM JSON


Arduino JSON Library

The easiest way to decode and encode JSON strings with the Arduino IDE is using the ArduinoJson library which was designed to be the most intuitive JSON library, with the smallest footprint and most efficient memory management for Arduino. ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).

Features

1. JSON decoding (comments are supported)
2. JSON encoding (with optional indentation)
3. Elegant API, very easy to use
4. Fixed memory allocation (zero mallocs)
5. No data duplication (zero-copy)
6. Portable (written in C++98)
7. Self-contained (no external dependency)
8. Small footprint
9.Header-only library



Source Code: STM32 & SIM900/800 HTTP Post Request in JSON Format

The source code for making HTTP POST in JSON Format with API for STM32 SIM900/800 GSM Module is given below.

Before that you need some libraries. Download the libraries from the following link and add to the Arduino IDE.

1. RTC Lib for DS3231: Download
2. DHT Library for DHT11 Sensor: Download
3. Arduino JSON Library: Download

In the following code, make changes to the APN. I used Airtel APN. Check your Operator APN and make changes. Also make changes to the webserver or add your api webserver address where you want to send the data.

You can learn more about DS3231 here: STM32 & DS3231 Based Real Time Clock with OLED

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <RTClib.h>  // Download the library from https://github.com/adafruit/RTClib
#include <Wire.h>    // Library for I2C Communication with DS3231 Module
#include <DHT.h>
#include <ArduinoJson.h>
StaticJsonBuffer<200> jsonBuffer;
 
#define BOARD_USART3_TX_PIN PB10    // Connect to TX3/RX3
#define BOARD_USART3_RX_PIN PB11    // Connect to TX3/RX3
 
#define DHTPIN PA0
#define DHTTYPE DHT11
 
RTC_DS3231 rtc;
DHT dht(DHTPIN, DHTTYPE);
 
char t[32];
char deviceID[12] = "MYTEST56";
 
 
void setup()
{
  Serial3.begin(9600);        // the GPRS baud rate
  Serial.begin(9600);
  Serial.println("Initializing..........");
  dht.begin();
  Wire.begin();
  DynamicJsonBuffer jsonBuffer;
 
 
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  //rtc.adjust(DateTime(2020, 02, 29, 17, 50, 40));
  delay(5000);
}
 
void loop()
{
  Serial.println("");
  Serial.println("************************************************************");
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();
 
  DateTime now = rtc.now();
 
  sprintf(t, "%02d:%02d:%02d %02d/%02d/%02d",  now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year());
 
  Serial.print("Device ID: ");
  Serial.println(deviceID);
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" °C");
  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.println(" %");
  Serial.print(F("Time/Date: "));
  Serial.println(t);
  delay(1000);
 
 
/********************GSM Communication Starts********************/
 
  if (Serial3.available())
  Serial.write(Serial3.read());
 
  Serial3.println("AT");
  delay(3000);
 
  Serial3.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
  delay(6000);
  ShowSerialData();
 
  Serial3.println("AT+SAPBR=3,1,\"APN\",\"airtelgprs.com\"");//APN
  delay(6000);
  ShowSerialData();
 
  Serial3.println("AT+SAPBR=1,1");
  delay(6000);
  ShowSerialData();
 
  Serial3.println("AT+SAPBR=2,1");
  delay(6000);
  ShowSerialData();
 
 
  Serial3.println("AT+HTTPINIT");
  delay(6000);
  ShowSerialData();
 
  Serial3.println("AT+HTTPPARA=\"CID\",1");
  delay(6000);
  ShowSerialData();
 
  StaticJsonBuffer<200> jsonBuffer;
  JsonObject& object = jsonBuffer.createObject();
  
  object.set("deviceID",deviceID);
  object.set("humidity",humidity);
  object.set("temperature",temperature);
  object.set("timedate",t);
  
  object.printTo(Serial);
  Serial.println(" ");  
  String sendtoserver;
  object.prettyPrintTo(sendtoserver);
  delay(4000);
 
  Serial3.println("AT+HTTPPARA=\"URL\",\"http://192.138.xxxxxxxxxxxxxxxx.php\""); //Server address
  delay(4000);
  ShowSerialData();
 
  Serial3.println("AT+HTTPPARA=\"CONTENT\",\"application/json\"");
  delay(4000);
  ShowSerialData();
 
 
  Serial3.println("AT+HTTPDATA=" + String(sendtoserver.length()) + ",100000");
  Serial.println(sendtoserver);
  delay(6000);
  ShowSerialData();
 
  Serial3.println(sendtoserver);
  delay(6000);
  ShowSerialData;
 
  Serial3.println("AT+HTTPACTION=1");
  delay(6000);
  ShowSerialData();
 
  Serial3.println("AT+HTTPREAD");
  delay(6000);
  ShowSerialData();
 
  Serial3.println("AT+HTTPTERM");
  delay(10000);
  ShowSerialData;
 
  /********************GSM Communication Stops********************/
 
}
 
 
void ShowSerialData()
{
  while (Serial3.available() != 0)
    Serial.write(Serial3.read());
  delay(1000);
 
}




Result & Responses

Once you upload the code to the STM32 and Power on the module, the Module will try connecting to the internet and will send data in JSON format.

Sometimes you might miss data and get some errors. This can be reduced by increasing delays after step by step in the above code. Or if the network connectivity and signal strength is good you can get the data most of the times.

Open your serial monitor and you should get the following results.

So this was all about how to make to use STM32 & SIM900/800 HTTP Post Request for API in JSON Format.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleSIM900/800 HTTP Post Request in JSON Format with Arduino
Next Article Monitor SpO2/BPM with ESP32 & MAX30100 Pulse Oximeter on Blynk

Related Posts

ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

Updated:June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

Updated:June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

Updated:May 10, 20262K
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

Updated:May 2, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

Updated:April 27, 20261K
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

Updated:April 27, 20262K
View 1 Comment

1 Comment

  1. ANICET on August 14, 2024 9:27 AM

    Merci pour ce tuturiel .
    j’ai un projet similaire j’utilise un stm32f407zet6 mais je ne parvient pas au utiliser avec un module GSM sim800l je ne recois aucun retour quand j execute les commande AT

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
    IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.