• Stars
    star
    135
  • Rank 269,297 (Top 6 %)
  • Language
    C
  • License
    Do What The F*ck ...
  • Created almost 5 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

STM32 HAL library for SIM800 release MQTT client over AT command

STM32 HAL library for SIM800 (GPRS) release MQTT client over AT command

Simple C library (STM32 HAL) for working with the MQTT protocol through AT commands of the SIM800 (GPRS) module https://aliexpress.ru/item/32284560394.html?spm=a2g0s.9042311.0.0.34a833edF2cSsx

Configure STM32CubeMX by setting "General peripheral Initalizion as a pair of '.c / .h' file per peripheral" in the project settings. photo Remember to enable global interrupts for your UART. photo Copy the library header and source file to the appropriate project directories (Inc, Src). Configure the UART port where your module is connected in the MQTTSim800.h file.

#define UART_SIM800 &huart2
#define FREERTOS 0
#define CMD_DELAY 2000

In the head file of your project (main.c), include the header file

/ * USER CODE BEGIN Includes * /
#include "MQTTSim800.h"
/ * USER CODE END Includes * /

In the head file of your project (main.c), create SIM800 structure

/* USER CODE BEGIN PV */
SIM800_t SIM800;
/* USER CODE END PV */

add function call Sim800_RxCallBack () to interrupt UART

/ * USER CODE BEGIN 0 * /
void HAL_UART_RxCpltCallback(UART_HandleTypeDef * huart) {
    if (huart == UART_SIM800) {
        Sim800_RxCallBack();
    }
}
/ * USER CODE END 0 * /

Fill structure in the main (void) function section

/* USER CODE BEGIN 2 */
    SIM800.sim.apn = "internet";
    SIM800.sim.apn_user = "";
    SIM800.sim.apn_pass = "";
    SIM800.mqttServer.host = "mqtt.mqtt.ru";
    SIM800.mqttServer.port = 1883;
    SIM800.mqttClient.username = "user";
    SIM800.mqttClient.pass = "pass";
    SIM800.mqttClient.clientID = "TestSub";
    SIM800.mqttClient.keepAliveInterval = 120;
/* USER CODE END 2 */

add the module initialization code in the main (void) function section

/ * USER CODE BEGIN 2 * /
    MQTT_Init();
/ * USER CODE END 2 * /

add Subscription status

/ * USER CODE BEGIN 2 * /
    uint8_t sub = 0;
/ * USER CODE END 2 * /

add a send topic "STM32" and value "test" to the server in an infinite while (1) loop, for example every 1 seconds. add subscribe to topic "test"

 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1) {
     if (SIM800.mqttServer.connect == 0) {
         MQTT_Init();
         sub = 0;
     }
     if (SIM800.mqttServer.connect == 1) {
         if(sub == 0){
             MQTT_Sub("test");
             sub = 1;
         }
         MQTT_Pub("STM32", "test");

         if(SIM800.mqttReceive.newEvent) {
             unsigned char *topic = SIM800.mqttReceive.topic;
             int payload = atoi(SIM800.mqttReceive.payload);
             SIM800.mqttReceive.newEvent = 0;
         }
     }
     HAL_Delay(1000);
     /* USER CODE END WHILE */

This completes the setup. Check in loop SIM800.mqttReceive.newEvent for new publish events. Set to 0 (zero) while use new data.

The library also supports sending zero messages to the server to maintain a connection.

MQTT_PingReq();

The library is implemented based on the code for generating MQTT packages of the project https://github.com/eclipse/paho.mqtt.embedded-c/tree/master/MQTTPacket

The library testing with https://github.com/r2axz/bluepill-serial-monster

More Repositories

1

MPU6050

STM32 HAL library for GY-521 (MPU6050) with Kalman filter
C
333
star
2

gps

STM32 HAL library for GPS module NEO-6M
C
56
star
3

hass-mqtt-discovery

Python class library for generate and send to Home Assistant over MQTT (AutoDiscovery) device data
Python
32
star
4

RF-BARRIER

STM32 HAL library for reading and sending code for Radio frequency (RF) barrier (Came, Nice) simple code 12, 24 bit and HCS301 with keeloq 66 bit.
C
28
star
5

HCS301

STM32 HAL library for reading code from HCS301 433Mhz Keeloq
C
19
star
6

micros

STM32 HAL library for release function micros() and delay_us().
C
18
star
7

SimpleKalman

A project to implement a one-dimensional Kalman filter in Dart language
Dart
13
star
8

TempControl-ESP8266

Temp control on ESP8266
Python
6
star
9

OpenOCD-CS32

OpenOCD config for CS32F103C8T6 (CKSF103C8T6)
6
star
10

MotoBoard

Auto oiler for lube on moto chain
C
5
star
11

NRF24L01

HAL library for NRF24L01 on STM32
C
5
star
12

Temp_control

Orange PI temp control (ds18b20, GPIO, Telegram, telepot)
Python
4
star
13

HTTPyCheck

The Python HTTP(S) - PING check availability sites over Telegram bot project
Python
4
star
14

process_metrics_exporter

Prometheus process metrics exporter
Go
4
star
15

Security-fire-alarm-ESP8266

Security fire alarm on ESP8266
Python
3
star
16

rf-leak-module

Leak module based on STM32G030F6P6 and NRF24L01
C
3
star
17

STM32-FreeRTOS-float

Support for working with float in STM32 in conjunction with FreeRTOS
C
3
star
18

SIM800-StatsD

STM32 HAL library for SIM800 (GPRS) release send metric StatsD over AT command
C
2
star
19

MQ9

Micropython MQ9 library for ESP8266
Python
2
star
20

LeakControlESP8266

Leak control on ESP8266 ( MQTT ) and Orange PI
Python
1
star
21

blackmagic-docker

Docker image to build BlackMagic binary
Shell
1
star
22

SIM800-RTT

STM32 HAL library for SIM800 (GPRS) release send GPS metric to RTT server over AT command
C
1
star