Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
cb9ce34d
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cb9ce34d
编写于
5月 24, 2020
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reconnect Mqtt Broker when connection fails
上级
df503b11
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
18 addition
and
10 deletion
+18
-10
src/plugins/mqtt/inc/mqttInit.h
src/plugins/mqtt/inc/mqttInit.h
+1
-1
src/plugins/mqtt/src/mqttPayload.c
src/plugins/mqtt/src/mqttPayload.c
+2
-2
src/plugins/mqtt/src/mqttSystem.c
src/plugins/mqtt/src/mqttSystem.c
+15
-7
未找到文件。
src/plugins/mqtt/inc/mqttInit.h
浏览文件 @
cb9ce34d
...
@@ -30,7 +30,7 @@ extern "C" {
...
@@ -30,7 +30,7 @@ extern "C" {
char
split
(
char
str
[],
char
delims
[],
char
**
p_p_cmd_part
,
int
max
);
char
split
(
char
str
[],
char
delims
[],
char
**
p_p_cmd_part
,
int
max
);
void
mqttConnnectLost
(
void
*
context
,
char
*
cause
);
void
mqttConnnectLost
(
void
*
context
,
char
*
cause
);
int
mqttMessageArrived
(
void
*
context
,
char
*
topicName
,
int
topicLen
,
MQTTAsync_message
*
message
);
int
mqttMessageArrived
(
void
*
context
,
char
*
topicName
,
int
topicLen
,
MQTTAsync_message
*
message
);
void
mqtt
_query_insert_c
allback
(
void
*
param
,
TAOS_RES
*
result
,
int32_t
code
);
void
mqtt
QueryInsertC
allback
(
void
*
param
,
TAOS_RES
*
result
,
int32_t
code
);
void
onDisconnectFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
);
void
onDisconnectFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
);
void
onDisconnect
(
void
*
context
,
MQTTAsync_successData
*
response
);
void
onDisconnect
(
void
*
context
,
MQTTAsync_successData
*
response
);
void
onSubscribe
(
void
*
context
,
MQTTAsync_successData
*
response
);
void
onSubscribe
(
void
*
context
,
MQTTAsync_successData
*
response
);
...
...
src/plugins/mqtt/src/mqttPayload.c
浏览文件 @
cb9ce34d
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
*/
*/
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "mqtt
Uitl
.h"
#include "mqtt
Payload
.h"
#include "cJSON.h"
#include "cJSON.h"
#include "string.h"
#include "string.h"
#include "taos.h"
#include "taos.h"
...
@@ -58,7 +58,7 @@ char* converJsonToSql(char* json, char* _dbname, char* _tablename) {
...
@@ -58,7 +58,7 @@ char* converJsonToSql(char* json, char* _dbname, char* _tablename) {
}
}
}
}
cJSON_free
(
jPlayload
);
cJSON_free
(
jPlayload
);
char
_sql
[
102400
]
=
{
0
}
;
char
*
_sql
=
calloc
(
0
,
strlen
(
_names
)
+
strlen
(
_values
)
+
strlen
(
_dbname
)
+
strlen
(
_tablename
)
+
1024
)
;
sprintf
(
_sql
,
"INSERT INTO %s.%s (%s) VALUES(%s);"
,
_dbname
,
_tablename
,
_names
,
_values
);
sprintf
(
_sql
,
"INSERT INTO %s.%s (%s) VALUES(%s);"
,
_dbname
,
_tablename
,
_names
,
_values
);
return
_sql
;
return
_sql
;
}
}
\ No newline at end of file
src/plugins/mqtt/src/mqttSystem.c
浏览文件 @
cb9ce34d
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
#include "tsocket.h"
#include "tsocket.h"
#include "ttimer.h"
#include "ttimer.h"
#include "mqttInit.h"
#include "mqttInit.h"
#include "mqttP
l
yload.h"
#include "mqttP
a
yload.h"
MQTTAsync
client
;
MQTTAsync
client
;
MQTTAsync_connectOptions
conn_opts
=
MQTTAsync_connectOptions_initializer
;
MQTTAsync_connectOptions
conn_opts
=
MQTTAsync_connectOptions_initializer
;
...
@@ -78,10 +78,12 @@ int mqttMessageArrived(void* context, char* topicName, int topicLen, MQTTAsync_m
...
@@ -78,10 +78,12 @@ int mqttMessageArrived(void* context, char* topicName, int topicLen, MQTTAsync_m
strncpy
(
_tablename
,
p_p_cmd_part
[
3
],
127
);
strncpy
(
_tablename
,
p_p_cmd_part
[
3
],
127
);
mqttPrint
(
"part count=%d,access token:%s,database name:%s, table name:%s"
,
part_index
,
_token
,
_dbname
,
mqttPrint
(
"part count=%d,access token:%s,database name:%s, table name:%s"
,
part_index
,
_token
,
_dbname
,
_tablename
);
_tablename
);
char
*
sql
=
converJsonToSql
((
char
*
)
message
->
payload
,
_dbname
,
_tablename
);
if
(
mqtt_conn
!=
NULL
)
{
if
(
mqtt_conn
!=
NULL
)
{
char
*
_sql
=
converJsonToSql
((
char
*
)
message
->
payload
,
_dbname
,
_tablename
);
mqttPrint
(
"query:%s"
,
_sql
);
mqttPrint
(
"query:%s"
,
_sql
);
taos_query_a
(
mqtt_conn
,
_sql
,
mqttQueryInsertCallback
,
&
client
);
taos_query_a
(
mqtt_conn
,
_sql
,
mqttQueryInsertCallback
,
&
client
);
free
(
_sql
);
}
}
}
}
}
}
...
@@ -100,12 +102,12 @@ void mqttQueryInsertCallback(void* param, TAOS_RES* result, int32_t code) {
...
@@ -100,12 +102,12 @@ void mqttQueryInsertCallback(void* param, TAOS_RES* result, int32_t code) {
}
}
void
onDisconnectFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
void
onDisconnectFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
mqttError
(
"Disconnect failed, rc %d
\n
"
,
response
->
code
);
mqttError
(
"Disconnect failed, rc %d"
,
response
->
code
);
disc_finished
=
1
;
disc_finished
=
1
;
}
}
void
onDisconnect
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
void
onDisconnect
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
mqttError
(
"Successful disconnection
\n
"
);
mqttError
(
"Successful disconnection"
);
if
(
mqtt_conn
!=
NULL
)
{
if
(
mqtt_conn
!=
NULL
)
{
taos_close
(
mqtt_conn
);
taos_close
(
mqtt_conn
);
mqtt_conn
=
NULL
;
mqtt_conn
=
NULL
;
...
@@ -114,18 +116,24 @@ void onDisconnect(void* context, MQTTAsync_successData* response) {
...
@@ -114,18 +116,24 @@ void onDisconnect(void* context, MQTTAsync_successData* response) {
}
}
void
onSubscribe
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
void
onSubscribe
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
mqttPrint
(
"Subscribe succeeded
\n
"
);
mqttPrint
(
"Subscribe succeeded"
);
subscribed
=
1
;
subscribed
=
1
;
}
}
void
onSubscribeFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
void
onSubscribeFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
mqttError
(
"Subscribe failed, rc %d
\n
"
,
response
->
code
);
mqttError
(
"Subscribe failed, rc %d"
,
response
->
code
);
finished
=
1
;
finished
=
1
;
}
}
void
onConnectFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
void
onConnectFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
mqttError
(
"Connect failed, rc %d
\n
"
,
response
->
code
);
mqttError
(
"Connect failed, rc %d
,,Retry later
"
,
response
->
code
);
finished
=
1
;
finished
=
1
;
taosMsleep
(
1000
);
int
rc
=
0
;
if
((
rc
=
MQTTAsync_connect
(
client
,
&
conn_opts
))
!=
MQTTASYNC_SUCCESS
)
{
mqttError
(
"Failed to start connect, return code %d"
,
rc
);
finished
=
1
;
}
}
}
void
onConnect
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
void
onConnect
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录