Skip to content

Commit

Permalink
Added publishing functions for numeric types
Browse files Browse the repository at this point in the history
Corrected delay on PUB SUB functions
  • Loading branch information
leech001 committed May 6, 2021
1 parent 7e469f2 commit 06738ae
Show file tree
Hide file tree
Showing 37 changed files with 3,194 additions and 1,068 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## [2.1.0] - 2021-05-06
- Corrected delay on PUB SUB functions;
- Added publishing functions (MQTT_PubUint8, MQTT_PubUint16, MQTT_PubDouble, etc ) for numeric types:
- uint8_t;
- uint16_t;
- uint32_t;
- float;
- double;

## [2.0.0] - 2021-01-26
- Added support for MQTT subscriptions.
- work is performed through the transparent mode;
- increased the buffer size to the maximum for SIM800 and now is 1460 bytes.
- Small bugfixes by code.
68 changes: 35 additions & 33 deletions examples/MQTTSUB/.cproject

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/MQTTSUB/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Debug/
24 changes: 12 additions & 12 deletions examples/MQTTSUB/.mxproject
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ CDefines=USE_HAL_DRIVER;STM32F401xC;USE_HAL_DRIVER;USE_HAL_DRIVER;
[PreviousGenFiles]
AdvancedFolderStructure=true
HeaderFileListSize=5
HeaderFiles#0=C:/Project/STM32/MQTTSUB/Core/Inc/gpio.h
HeaderFiles#1=C:/Project/STM32/MQTTSUB/Core/Inc/usart.h
HeaderFiles#2=C:/Project/STM32/MQTTSUB/Core/Inc/stm32f4xx_it.h
HeaderFiles#3=C:/Project/STM32/MQTTSUB/Core/Inc/stm32f4xx_hal_conf.h
HeaderFiles#4=C:/Project/STM32/MQTTSUB/Core/Inc/main.h
HeaderFiles#0=C:/Project/GIT/STM32/SIM800MQTT/examples/MQTTSUB/Core/Inc/gpio.h
HeaderFiles#1=C:/Project/GIT/STM32/SIM800MQTT/examples/MQTTSUB/Core/Inc/usart.h
HeaderFiles#2=C:/Project/GIT/STM32/SIM800MQTT/examples/MQTTSUB/Core/Inc/stm32f4xx_it.h
HeaderFiles#3=C:/Project/GIT/STM32/SIM800MQTT/examples/MQTTSUB/Core/Inc/stm32f4xx_hal_conf.h
HeaderFiles#4=C:/Project/GIT/STM32/SIM800MQTT/examples/MQTTSUB/Core/Inc/main.h
HeaderFolderListSize=1
HeaderPath#0=C:/Project/STM32/MQTTSUB/Core/Inc
HeaderPath#0=C:/Project/GIT/STM32/SIM800MQTT/examples/MQTTSUB/Core/Inc
HeaderFiles=;
SourceFileListSize=5
SourceFiles#0=C:/Project/STM32/MQTTSUB/Core/Src/gpio.c
SourceFiles#1=C:/Project/STM32/MQTTSUB/Core/Src/usart.c
SourceFiles#2=C:/Project/STM32/MQTTSUB/Core/Src/stm32f4xx_it.c
SourceFiles#3=C:/Project/STM32/MQTTSUB/Core/Src/stm32f4xx_hal_msp.c
SourceFiles#4=C:/Project/STM32/MQTTSUB/Core/Src/main.c
SourceFiles#0=C:/Project/GIT/STM32/SIM800MQTT/examples/MQTTSUB/Core/Src/gpio.c
SourceFiles#1=C:/Project/GIT/STM32/SIM800MQTT/examples/MQTTSUB/Core/Src/usart.c
SourceFiles#2=C:/Project/GIT/STM32/SIM800MQTT/examples/MQTTSUB/Core/Src/stm32f4xx_it.c
SourceFiles#3=C:/Project/GIT/STM32/SIM800MQTT/examples/MQTTSUB/Core/Src/stm32f4xx_hal_msp.c
SourceFiles#4=C:/Project/GIT/STM32/SIM800MQTT/examples/MQTTSUB/Core/Src/main.c
SourceFolderListSize=1
SourcePath#0=C:/Project/STM32/MQTTSUB/Core/Src
SourcePath#0=C:/Project/GIT/STM32/SIM800MQTT/examples/MQTTSUB/Core/Src
SourceFiles=;

73 changes: 49 additions & 24 deletions examples/MQTTSUB/.settings/language.settings.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,52 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.1192067357" name="Debug">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1250421421883281287" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
<configuration id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.release.908143241" name="Release">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1250421421883281287" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>

<configuration id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.1192067357" name="Debug">

<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">

<provider-reference id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" ref="shared-provider"/>

<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>

<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>

<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>

<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1612723618780122445" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">

<language-scope id="org.eclipse.cdt.core.gcc"/>

<language-scope id="org.eclipse.cdt.core.g++"/>

</provider>

</extension>

</configuration>

<configuration id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.release.908143241" name="Release">

<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">

<provider-reference id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" ref="shared-provider"/>

<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>

<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>

<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>

<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1612723618780122445" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">

<language-scope id="org.eclipse.cdt.core.gcc"/>

<language-scope id="org.eclipse.cdt.core.g++"/>

</provider>

</extension>

</configuration>

</project>
5 changes: 2 additions & 3 deletions examples/MQTTSUB/.settings/stm32cubeide.project.prefs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
2F62501ED4689FB349E356AB974DBE57=E24C9EBCC94E6138E15A49E403E37579
8DF89ED150041C4CBC7CB9A9CAA90856=E24C9EBCC94E6138E15A49E403E37579
DC22A860405A8BF2F2C095E5B6529F12=13823638991BFFA9BC1619F1AF325BB4
8DF89ED150041C4CBC7CB9A9CAA90856=0C86D7ED0DEBF412462B3FA7A4E6C7D0
DC22A860405A8BF2F2C095E5B6529F12=7B750BFCB298F2EA884A9B0F68E5D3E5
eclipse.preferences.version=1
10 changes: 10 additions & 0 deletions examples/MQTTSUB/Core/Inc/MQTTSim800.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ void MQTT_Connect(void);

void MQTT_Pub(char *topic, char *payload);

void MQTT_PubUint8(char *topic, uint8_t data);

void MQTT_PubUint16(char *topic, uint16_t data);

void MQTT_PubUint32(char *topic, uint32_t data);

void MQTT_PubFloat(char *topic, float payload);

void MQTT_PubDouble(char *topic, double data);

void MQTT_PingReq(void);

void MQTT_Sub(char *topic);
Expand Down
2 changes: 1 addition & 1 deletion examples/MQTTSUB/Core/Inc/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
Expand Down
34 changes: 20 additions & 14 deletions examples/MQTTSUB/Core/Inc/stm32f4xx_hal_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
/* #define HAL_QSPI_MODULE_ENABLED */
/* #define HAL_CEC_MODULE_ENABLED */
/* #define HAL_FMPI2C_MODULE_ENABLED */
/* #define HAL_FMPSMBUS_MODULE_ENABLED */
/* #define HAL_SPDIFRX_MODULE_ENABLED */
/* #define HAL_DFSDM_MODULE_ENABLED */
/* #define HAL_LPTIM_MODULE_ENABLED */
Expand All @@ -94,11 +95,11 @@
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)25000000U) /*!< Value of the External oscillator in Hz */
#define HSE_VALUE 25000000U /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */

#if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
#define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */

/**
Expand All @@ -114,19 +115,19 @@
* @brief Internal Low Speed oscillator (LSI) value.
*/
#if !defined (LSI_VALUE)
#define LSI_VALUE ((uint32_t)32000U) /*!< LSI Typical Value in Hz*/
#define LSI_VALUE 32000U /*!< LSI Typical Value in Hz*/
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations
in voltage and temperature.*/
/**
* @brief External Low Speed oscillator (LSE) value.
*/
#if !defined (LSE_VALUE)
#define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External Low Speed oscillator in Hz */
#define LSE_VALUE 32768U /*!< Value of the External Low Speed oscillator in Hz */
#endif /* LSE_VALUE */

#if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */
#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
#endif /* LSE_STARTUP_TIMEOUT */

/**
Expand All @@ -135,7 +136,7 @@
* frequency, this source is inserted directly through I2S_CKIN pad.
*/
#if !defined (EXTERNAL_CLOCK_VALUE)
#define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000U) /*!< Value of the External audio frequency in Hz*/
#define EXTERNAL_CLOCK_VALUE 12288000U /*!< Value of the External audio frequency in Hz*/
#endif /* EXTERNAL_CLOCK_VALUE */

/* Tip: To avoid modifying this file each time you need to use different HSE,
Expand All @@ -145,8 +146,8 @@
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE ((uint32_t)3300U) /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY ((uint32_t)0U) /*!< tick interrupt priority */
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY 0U /*!< tick interrupt priority */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 1U
#define INSTRUCTION_CACHE_ENABLE 1U
Expand All @@ -166,6 +167,7 @@
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */
#define USE_HAL_FMPI2C_REGISTER_CALLBACKS 0U /* FMPI2C register callback disabled */
#define USE_HAL_FMPSMBUS_REGISTER_CALLBACKS 0U /* FMPSMBUS register callback disabled */
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U /* LPTIM register callback disabled */
Expand Down Expand Up @@ -213,20 +215,20 @@
/* Definition of the Ethernet driver buffers size and count */
#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
#define ETH_RXBUFNB ((uint32_t)4U) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
#define ETH_TXBUFNB ((uint32_t)4U) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
#define ETH_RXBUFNB 4U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
#define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */

/* Section 2: PHY configuration section */

/* DP83848_PHY_ADDRESS Address*/
#define DP83848_PHY_ADDRESS 0x01U
/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
#define PHY_RESET_DELAY ((uint32_t)0x000000FFU)
#define PHY_RESET_DELAY 0x000000FFU
/* PHY Configuration delay */
#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFFU)
#define PHY_CONFIG_DELAY 0x00000FFFU

#define PHY_READ_TO ((uint32_t)0x0000FFFFU)
#define PHY_WRITE_TO ((uint32_t)0x0000FFFFU)
#define PHY_READ_TO 0x0000FFFFU
#define PHY_WRITE_TO 0x0000FFFFU

/* Section 3: Common PHY Registers */

Expand Down Expand Up @@ -444,6 +446,10 @@
#include "stm32f4xx_hal_fmpi2c.h"
#endif /* HAL_FMPI2C_MODULE_ENABLED */

#ifdef HAL_FMPSMBUS_MODULE_ENABLED
#include "stm32f4xx_hal_fmpsmbus.h"
#endif /* HAL_FMPSMBUS_MODULE_ENABLED */

#ifdef HAL_SPDIFRX_MODULE_ENABLED
#include "stm32f4xx_hal_spdifrx.h"
#endif /* HAL_SPDIFRX_MODULE_ENABLED */
Expand Down
2 changes: 1 addition & 1 deletion examples/MQTTSUB/Core/Inc/usart.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
Expand Down
71 changes: 68 additions & 3 deletions examples/MQTTSUB/Core/Src/MQTTSim800.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,71 @@ void MQTT_Pub(char *topic, char *payload) {
int mqtt_len = MQTTSerialize_publish(buf, sizeof(buf), 0, 0, 0, 0,
topicString, (unsigned char *) payload, (int) strlen(payload));
HAL_UART_Transmit_IT(UART_SIM800, buf, mqtt_len);
#if FREERTOS == 1
osDelay(100);
#else
HAL_Delay(100);
#endif
}

/**
* Public on the MQTT broker of the message in a topic
* @param topic (uint8_t) to be used to the set topic
* @param payload to be used to the set message for topic
* @return NONE
*/
void MQTT_PubUint8(char *topic, uint8_t payload) {
char str[32] = { 0 };
sprintf(str, "%d", payload);
MQTT_Pub(topic, str);
}

/**
* Public on the MQTT broker of the message in a topic
* @param topic (uint16_t) to be used to the set topic
* @param payload to be used to the set message for topic
* @return NONE
*/
void MQTT_PubUint16(char *topic, uint16_t payload) {
char str[32] = { 0 };
sprintf(str, "%d", payload);
MQTT_Pub(topic, str);
}

/**
* Public on the MQTT broker of the message in a topic
* @param topic (uint32_t) to be used to the set topic
* @param payload to be used to the set message for topic
* @return NONE
*/
void MQTT_PubUint32(char *topic, uint32_t payload) {
char str[32] = { 0 };
sprintf(str, "%ld", payload);
MQTT_Pub(topic, str);
}

/**
* Public on the MQTT broker of the message in a topic
* @param topic (float) to be used to the set topic
* @param payload to be used to the set message for topic
* @return NONE
*/
void MQTT_PubFloat(char *topic, float payload) {
char str[32] = { 0 };
sprintf(str, "%f", payload);
MQTT_Pub(topic, str);
}

/**
* Public on the MQTT broker of the message in a topic
* @param topic (double) to be used to the set topic
* @param payload to be used to the set message for topic
* @return NONE
*/
void MQTT_PubDouble(char *topic, double payload) {
char str[32] = { 0 };
sprintf(str, "%f", payload);
MQTT_Pub(topic, str);
}

/**
Expand Down Expand Up @@ -253,9 +318,9 @@ void MQTT_Sub(char *topic) {
&topicString, 0);
HAL_UART_Transmit_IT(UART_SIM800, buf, mqtt_len);
#if FREERTOS == 1
osDelay(5000);
osDelay(100);
#else
HAL_Delay(5000);
HAL_Delay(100);
#endif
}

Expand All @@ -277,4 +342,4 @@ void MQTT_Receive(unsigned char *buf) {
SIM800.mqttReceive.topicLen = receivedTopic.lenstring.len;
memcpy(SIM800.mqttReceive.payload, payload, SIM800.mqttReceive.payloadLen);
SIM800.mqttReceive.newEvent = 1;
}
}
2 changes: 1 addition & 1 deletion examples/MQTTSUB/Core/Src/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
Expand Down
Loading

0 comments on commit 06738ae

Please sign in to comment.