Skip to content

Commit

Permalink
Prepared for handing over (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: Sercan Uzun <sercan.uzun@campus.tu-berlin.de>
  • Loading branch information
srcnuzn and Sercan Uzun committed May 27, 2021
1 parent 55ba541 commit 650737c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 14 deletions.
12 changes: 12 additions & 0 deletions STM32CubeIDE/Application/includes/mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ void MqttClient_PublishInteger(const char* description, const int value);

void MqttClient_PublishString(const char* description, const char* value);

void MqttClient_PublishDouble(const char* description, const double value);

void MqttClient_PublishBoolean(const char* description, const int oneOrZero);

int MqttClient_ReadInteger(const char* description, const int value);

char* MqttClient_ReadString(const char* description, const char* value);

double MqttClient_ReadDouble(const char* description, const double value);

int MqttClient_ReadBoolean(const char* description, const int value);

/*********************************************************************************************/

#endif /* INCLUDES_MQTT_H_ */
2 changes: 2 additions & 0 deletions STM32CubeIDE/Application/includes/mqtt_required.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ extern void MqttClient_HandleSystemResetRequest();
* To write the JSON-message, following functions can be used:
* - MqttClient_PublishInteger
* - MqttClient_PublishString
* - MqttClient_PublishBoolean
* - MqttClient_PublishDouble
* @note This function is called periodically in MqttClient_Process(), when
* a connection to the broker is established. The publish period can be
* specified by the user-specific definition MQTT_PUBLISH_INTERVAL.
Expand Down
8 changes: 8 additions & 0 deletions STM32CubeIDE/Application/src/app/mqtt_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ static void TestTopicReceived(char* message);
* @note To adapt the JSON-message, following functions can be used:
* - MqttClient_PublishInteger
* - MqttClient_PublishString
* - MqttClient_PublishBoolean
* - MqttClient_PublishDouble
* @note This function is called periodically in MqttClient_Process(), when
* a connection to the broker is established. The publish period can be
* specified by the user-specific definition MQTT_PUBLISH_INTERVAL.
Expand Down Expand Up @@ -59,11 +61,17 @@ void MqttClient_RegisterCallbacks()
/*
* @brief Callback is fired, when MQTT_SUBTOPIC_1 is received.
* @note This is an example function to demonstrate how the callback registration works.
* @note To read the JSON-message, following functions can be used:
* - MqttClient_ReadInteger
* - MqttClient_ReadString
* - MqttClient_ReadBoolean
* - MqttClient_ReadDouble
* @param message string-paramater: The message that is being received with MQTT_SUBTOPIC_1.
* @retval None
*/
static void TestTopicReceived(char* message)
{
// int a = MqttClient_ReadInteger(message, description);
__NOP();
}

Expand Down
72 changes: 58 additions & 14 deletions STM32CubeIDE/Application/src/mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
#ifndef MQTT_PUBTOPIC
#define MQTT_PUBTOPIC ""
#endif
#ifndef MQTT_SUBTOPIC_1
#define MQTT_SUBTOPIC_1 ""
#ifndef MQTT_SUBTOPIC_FILTER_1
#define MQTT_SUBTOPIC_FILTER_1 ""
#endif
#ifndef MQTT_SUBTOPIC_2
#define MQTT_SUBTOPIC_2 ""
#ifndef MQTT_SUBTOPIC_FILTER_2
#define MQTT_SUBTOPIC_FILTER_2 ""
#endif
#ifndef MQTT_SUBTOPIC_3
#define MQTT_SUBTOPIC_3 ""
#ifndef MQTT_SUBTOPIC_FILTER_3
#define MQTT_SUBTOPIC_FILTER_3 ""
#endif

/*********************************************************************************************/
Expand Down Expand Up @@ -173,13 +173,57 @@ void MqttClient_PublishString(const char* description, const char* value)


/**
* @brief Associates a user defined callback function with a subscribe-topic.
* @note - The topic parameter must be a full topic path (without wildcards)
* - The callback is called, when the subscribe-topic is received.
* - This function should be called in MqttClient_RegisterCallbacks.
* @param topic The topic, that we subscribe to. (must be a '\0' terminated string!)
* @param func Pointer to the user-defined callback function.
* @retval none
* TODO: Comment on MqttClient_PublishDouble
*/
void MqttClient_PublishDouble(const char* description, const double value)
{
jwObj_double( (char*) description, value);
}

/**
* TODO: Comment on MqttClient_PublishBoolean
*/
void MqttClient_PublishBoolean(const char* description, const int oneOrZero)
{
jwObj_bool( (char*) description, oneOrZero);
}

/**
* TODO: Comment on MqttClient_ReadInteger
*/
int MqttClient_ReadInteger(const char* description, const int value)
{
return 0;
}

/**
* TODO: Comment on MqttClient_ReadString
*/
char* MqttClient_ReadString(const char* description, const char* value)
{
return NULL;
}

/**
* TODO: Comment on MqttClient_ReadDouble
*/
double MqttClient_ReadDouble(const char* description, const double value)
{
return 0.0;
}


/**
* TODO: Comment on MqttClient_ReadBoolean
*/
int MqttClient_ReadBoolean(const char* description, const int value)
{
return 0;
}


/**
* TODO: Comment on MqttClient_ReadBoolean
*/
void MqttClient_RegisterSubscribeCallback(const char* topic, void (*func)(char*))
{
Expand Down Expand Up @@ -249,7 +293,7 @@ static void mqttClientStatemachine_react_to_events()
MQTT_CLIENT_ID, MQTT_ALIVE_TIME);

else if (mqttClientStatemachine_WizFi360_is_raised_setTopic(&sm))
WIZFI360_AT_MqttSetTopic(MQTT_PUBTOPIC, MQTT_SUBTOPIC_1, NULL, NULL);
WIZFI360_AT_MqttSetTopic(MQTT_PUBTOPIC, MQTT_SUBTOPIC_FILTER_1, NULL, NULL);

else if (mqttClientStatemachine_WizFi360_is_raised_connectToBroker(&sm))
WIZFI360_AT_MqttConnectToBroker(WIZFI360_MQTT_AUTH_DISABLE,
Expand Down
1 change: 1 addition & 0 deletions STM32CubeIDE/Application/src/wizfi360.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ static void ScanBufferForMqttTopics(uint8_t tmpChar, int i)
== strlen(wizfi360.SubTopics[topicId]))
{
// The length of the topic string.
// TODO: What happens, if uart buffer has unhandled bytes?
const int length = strlen(wizfi360.SubTopics[topicId]);

// A dummy storage for the topic string
Expand Down

0 comments on commit 650737c

Please sign in to comment.