the final test
This commit is contained in:
@@ -49,10 +49,8 @@ void MQTTCB_reply(char* topic, char* payload){
|
||||
if(!replyListen)
|
||||
return;
|
||||
|
||||
//if(handshakeRequestAcrive){
|
||||
sprintf(&msg, "%s heeft je hand geschud.", payload);
|
||||
//udpSend(msg, strlen(msg));
|
||||
//}
|
||||
sprintf(&msg, "%s heeft je hand geschud.", payload);
|
||||
UDPSend(msg, strlen(msg));
|
||||
}
|
||||
|
||||
void MQTTCB_request(char* topic, char* payload){
|
||||
@@ -72,7 +70,7 @@ void MQTTCB_request(char* topic, char* payload){
|
||||
|
||||
requestTimeout = timestamp + TIME_TO_RESPAN_ON_REQUEST;
|
||||
sprintf(&msg, "%s bied je een handdruk aan.", payload);
|
||||
//udpSend(msg, strlen(msg));
|
||||
UDPSend(msg, strlen(msg));
|
||||
}
|
||||
|
||||
void handshake(){
|
||||
@@ -92,7 +90,7 @@ void handshake(){
|
||||
GPIO_write(CONFIG_LED_R, 1);
|
||||
MQTTPublish(&requestTopic[0], &yourName[0]);
|
||||
}
|
||||
//udpSend("Handshake aangeboden", strlen("Handshake aangeboden"));
|
||||
UDPSend("Handshake aangeboden", strlen("Handshake aangeboden"));
|
||||
}
|
||||
|
||||
void * handshakeTask(void *arg0){
|
||||
@@ -107,9 +105,6 @@ void * handshakeTask(void *arg0){
|
||||
|
||||
GPIO_write(CONFIG_LED_R, 0);
|
||||
|
||||
// MQTTSubscribe("ems20/handshake/0964590/reply", &MQTTCB_reply);
|
||||
// MQTTSubscribe("ems20/handshake/0123456/request", &MQTTCB_request);
|
||||
|
||||
gsensorMsgQueue queueElement;
|
||||
double replyTimeout = -1;
|
||||
|
||||
|
||||
@@ -111,6 +111,9 @@ int longPress = 0;
|
||||
/* the ClientID parameter. */
|
||||
char ClientId[13] = {'\0'};
|
||||
|
||||
extern void MQTTCB_reply(char* topic, char* payload);
|
||||
extern void MQTTCB_request(char* topic, char* payload);
|
||||
|
||||
enum{
|
||||
APP_MQTT_PUBLISH,
|
||||
APP_MQTT_CON_TOGGLE,
|
||||
@@ -288,71 +291,6 @@ int32_t SetClientIdNamefromMacAddress()
|
||||
return(ret);
|
||||
}
|
||||
|
||||
// void timerCallback(Timer_Handle myHandle)
|
||||
// {
|
||||
// longPress = 1;
|
||||
// }
|
||||
|
||||
// this timer callback toggles the LED once per second until the device connects to an AP
|
||||
// void timerLEDCallback(Timer_Handle myHandle)
|
||||
// {
|
||||
// GPIO_toggle(CONFIG_GPIO_LED_0);
|
||||
// }
|
||||
|
||||
// void pushButtonPublishHandler(uint_least8_t index)
|
||||
// {
|
||||
// int ret;
|
||||
// struct msgQueue queueElement;
|
||||
|
||||
// GPIO_disableInt(CONFIG_GPIO_BUTTON_0);
|
||||
|
||||
// queueElement.event = APP_MQTT_PUBLISH;
|
||||
// ret = mq_send(appQueue, (const char*)&queueElement, sizeof(struct msgQueue), 0);
|
||||
// if(ret < 0){
|
||||
// LOG_ERROR("msg queue send error %d", ret);
|
||||
// }
|
||||
// }
|
||||
|
||||
// void pushButtonConnectionHandler(uint_least8_t index)
|
||||
// {
|
||||
// int ret;
|
||||
// struct msgQueue queueElement;
|
||||
|
||||
// GPIO_disableInt(CONFIG_GPIO_BUTTON_1);
|
||||
|
||||
// ret = Timer_start(timer0);
|
||||
// if(ret < 0){
|
||||
// LOG_ERROR("failed to start the timer\r\n");
|
||||
// }
|
||||
|
||||
// queueElement.event = APP_BTN_HANDLER;
|
||||
|
||||
// ret = mq_send(appQueue, (const char*)&queueElement, sizeof(struct msgQueue), 0);
|
||||
// if(ret < 0){
|
||||
// LOG_ERROR("msg queue send error %d", ret);
|
||||
// }
|
||||
// }
|
||||
|
||||
// int detectLongPress(){
|
||||
|
||||
// int buttonPressed;
|
||||
|
||||
// do{
|
||||
// buttonPressed = GPIO_read(CONFIG_GPIO_BUTTON_1);
|
||||
// }while(buttonPressed && !longPress);
|
||||
|
||||
// // disabling the timer in case the callback has not yet triggered to avoid updating longPress
|
||||
// Timer_stop(timer0);
|
||||
|
||||
// if(longPress == 1){
|
||||
// longPress = 0;
|
||||
// return 1;
|
||||
// }
|
||||
// else{
|
||||
// return 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
void MQTT_EventCallback(int32_t event){
|
||||
|
||||
@@ -421,30 +359,6 @@ void MQTT_EventCallback(int32_t event){
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Subscribe topic callbacks
|
||||
* Topic and payload data is deleted after topic callbacks return.
|
||||
* User must copy the topic or payload data if it needs to be saved.
|
||||
*/
|
||||
void BrokerCB(char* topic, char* payload){
|
||||
LOG_INFO("TOPIC: %s \tPAYLOAD: %s", topic, payload);
|
||||
}
|
||||
|
||||
// void ToggleLED1CB(char* topic, char* payload){
|
||||
// GPIO_toggle(CONFIG_GPIO_LED_0);
|
||||
// LOG_INFO("TOPIC: %s \tPAYLOAD: %s\r\n", topic, payload);
|
||||
// }
|
||||
|
||||
// void ToggleLED2CB(char* topic, char* payload){
|
||||
// GPIO_toggle(CONFIG_GPIO_LED_1);
|
||||
// LOG_INFO("TOPIC: %s \tPAYLOAD: %s\r\n", topic, payload);
|
||||
// }
|
||||
|
||||
// void ToggleLED3CB(char* topic, char* payload){
|
||||
// GPIO_toggle(CONFIG_GPIO_LED_2);
|
||||
// LOG_INFO("TOPIC: %s \tPAYLOAD: %s\r\n", topic, payload);
|
||||
// }
|
||||
|
||||
int32_t DisplayAppBanner(char* appName, char* appVersion){
|
||||
|
||||
int32_t ret = 0;
|
||||
@@ -553,9 +467,9 @@ void MQTTPublish(char * topic, char * payload){
|
||||
int res = mq_send(appQueue, (const char*)&queueElement, sizeof(struct msgQueue), 0);
|
||||
}
|
||||
|
||||
void MQTTSubscribe(char* topic, void *cb(char* topic, char* payload)){
|
||||
uint8_t ret = MQTT_IF_Subscribe(0, topic, MQTT_QOS_2, cb);
|
||||
}
|
||||
// void MQTTSubscribe(char* topic, void *cb(char* topic, char* payload)){
|
||||
// uint8_t ret = MQTT_IF_Subscribe(0, topic, MQTT_QOS_2, cb);
|
||||
// }
|
||||
|
||||
void MQTTTask(void * args){
|
||||
|
||||
@@ -605,18 +519,15 @@ void MQTTTask(void * args){
|
||||
* of the topic callbacks. The user may still call subscribe after connect but have to be aware of this.
|
||||
*/
|
||||
ret = 0;
|
||||
// ret |= MQTT_IF_Subscribe(mqttClientHandle, "Broker/To/cc32xx", MQTT_QOS_2, BrokerCB);
|
||||
// ret |= MQTT_IF_Subscribe(mqttClientHandle, "cc32xx/ToggleLED1", MQTT_QOS_2, ToggleLED1CB);
|
||||
// ret |= MQTT_IF_Subscribe(mqttClientHandle, "cc32xx/ToggleLED2", MQTT_QOS_2, ToggleLED2CB);
|
||||
// ret |= MQTT_IF_Subscribe(mqttClientHandle, "cc32xx/ToggleLED3", MQTT_QOS_2, ToggleLED3CB);
|
||||
// ret |= MQTT_IF_Subscribe(mqttClientHandle, "ems20/handshake/0964590/reply", MQTT_QOS_2, BrokerCB);
|
||||
// ret |= MQTT_IF_Subscribe(mqttClientHandle, "ems20/handshake/0971472/request", MQTT_QOS_2, BrokerCB);
|
||||
// if(ret < 0){
|
||||
// while(1);
|
||||
// }
|
||||
// else{
|
||||
// LOG_INFO("Subscribed to all topics successfully\r\n");
|
||||
// }
|
||||
ret |= MQTT_IF_Subscribe(mqttClientHandle, "ems20/handshake/0964590/reply", MQTT_QOS_2, &MQTTCB_reply);
|
||||
ret |= MQTT_IF_Subscribe(mqttClientHandle, "ems20/handshake/0971472/request", MQTT_QOS_2, &MQTTCB_request);
|
||||
if(ret < 0){
|
||||
LOG_ERROR("Faild to Subscribed to topics\r\n");
|
||||
while(1);
|
||||
}
|
||||
else{
|
||||
LOG_INFO("Subscribed to all topics successfully\r\n");
|
||||
}
|
||||
|
||||
mqttClientHandle = MQTT_IF_Connect(mqttClientParams, mqttConnParams, MQTT_EventCallback);
|
||||
if(mqttClientHandle < 0){
|
||||
|
||||
Reference in New Issue
Block a user