Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
k-sdk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈伟灿
k-sdk
Commits
61fa270c
Commit
61fa270c
authored
Jul 24, 2020
by
whmaizmy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改内容】删除common下sample代码
【提交人】陈伟灿
parent
f5741418
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
6 additions
and
304 deletions
+6
-304
common/mqtt/samples/MQTTAsync_publish.c
common/mqtt/samples/MQTTAsync_publish.c
+0
-212
common/mqtt/samples/pubsub_opts.h
common/mqtt/samples/pubsub_opts.h
+0
-88
makefile
makefile
+1
-0
src/samples/MQTTAsync_publish.c
src/samples/MQTTAsync_publish.c
+1
-1
src/samples/iot.mk
src/samples/iot.mk
+4
-3
No files found.
common/mqtt/samples/MQTTAsync_publish.c
deleted
100644 → 0
View file @
f5741418
/*******************************************************************************
* Copyright (c) 2012, 2020 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* https://www.eclipse.org/legal/epl-2.0/
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Ian Craggs - initial contribution
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MQTTAsync.h"
#if !defined(_WIN32)
#include <unistd.h>
#else
#include <windows.h>
#endif
#if defined(_WRS_KERNEL)
#include <OsWrapper.h>
#endif
#define ADDRESS "tcp://mqtt.eclipse.org:1883"
#define CLIENTID "ExampleClientPub"
#define TOPIC "MQTT Examples"
#define PAYLOAD "Hello World!"
#define QOS 1
#define TIMEOUT 10000L
int
finished
=
0
;
void
connlost
(
void
*
context
,
char
*
cause
)
{
MQTTAsync
client
=
(
MQTTAsync
)
context
;
MQTTAsync_connectOptions
conn_opts
=
MQTTAsync_connectOptions_initializer
;
int
rc
;
printf
(
"
\n
Connection lost
\n
"
);
printf
(
" cause: %s
\n
"
,
cause
);
printf
(
"Reconnecting
\n
"
);
conn_opts
.
keepAliveInterval
=
20
;
conn_opts
.
cleansession
=
1
;
if
((
rc
=
MQTTAsync_connect
(
client
,
&
conn_opts
))
!=
MQTTASYNC_SUCCESS
)
{
printf
(
"Failed to start connect, return code %d
\n
"
,
rc
);
finished
=
1
;
}
}
void
onDisconnectFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
printf
(
"Disconnect failed
\n
"
);
finished
=
1
;
}
void
onDisconnect
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
printf
(
"Successful disconnection
\n
"
);
finished
=
1
;
}
void
onSendFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
MQTTAsync
client
=
(
MQTTAsync
)
context
;
MQTTAsync_disconnectOptions
opts
=
MQTTAsync_disconnectOptions_initializer
;
int
rc
;
printf
(
"Message send failed token %d error code %d
\n
"
,
response
->
token
,
response
->
code
);
opts
.
onSuccess
=
onDisconnect
;
opts
.
onFailure
=
onDisconnectFailure
;
opts
.
context
=
client
;
if
((
rc
=
MQTTAsync_disconnect
(
client
,
&
opts
))
!=
MQTTASYNC_SUCCESS
)
{
printf
(
"Failed to start disconnect, return code %d
\n
"
,
rc
);
exit
(
EXIT_FAILURE
);
}
}
void
onSend
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
MQTTAsync
client
=
(
MQTTAsync
)
context
;
MQTTAsync_disconnectOptions
opts
=
MQTTAsync_disconnectOptions_initializer
;
int
rc
;
printf
(
"Message with token value %d delivery confirmed
\n
"
,
response
->
token
);
opts
.
onSuccess
=
onDisconnect
;
opts
.
onFailure
=
onDisconnectFailure
;
opts
.
context
=
client
;
if
((
rc
=
MQTTAsync_disconnect
(
client
,
&
opts
))
!=
MQTTASYNC_SUCCESS
)
{
printf
(
"Failed to start disconnect, return code %d
\n
"
,
rc
);
exit
(
EXIT_FAILURE
);
}
}
void
onConnectFailure
(
void
*
context
,
MQTTAsync_failureData
*
response
)
{
printf
(
"Connect failed, rc %d
\n
"
,
response
?
response
->
code
:
0
);
finished
=
1
;
}
void
onConnect
(
void
*
context
,
MQTTAsync_successData
*
response
)
{
MQTTAsync
client
=
(
MQTTAsync
)
context
;
MQTTAsync_responseOptions
opts
=
MQTTAsync_responseOptions_initializer
;
MQTTAsync_message
pubmsg
=
MQTTAsync_message_initializer
;
int
rc
;
printf
(
"Successful connection
\n
"
);
opts
.
onSuccess
=
onSend
;
opts
.
onFailure
=
onSendFailure
;
opts
.
context
=
client
;
pubmsg
.
payload
=
PAYLOAD
;
pubmsg
.
payloadlen
=
(
int
)
strlen
(
PAYLOAD
);
pubmsg
.
qos
=
QOS
;
pubmsg
.
retained
=
0
;
if
((
rc
=
MQTTAsync_sendMessage
(
client
,
TOPIC
,
&
pubmsg
,
&
opts
))
!=
MQTTASYNC_SUCCESS
)
{
printf
(
"Failed to start sendMessage, return code %d
\n
"
,
rc
);
exit
(
EXIT_FAILURE
);
}
}
int
messageArrived
(
void
*
context
,
char
*
topicName
,
int
topicLen
,
MQTTAsync_message
*
message
)
{
/* not expecting any messages */
printf
(
"onMessageArrived topic:%s,message length:%d.
\n
"
,
topicName
,
message
->
payloadlen
);
MQTTAsync_freeMessage
(
&
message
);
MQTTAsync_free
(
topicName
);
return
1
;
}
static
void
mqttTraceCallback
(
enum
MQTTASYNC_TRACE_LEVELS
level
,
char
*
message
)
{
printf
(
"mqttTraceCallback level:%d,msg:%s.
\n
"
,
level
,
message
);
}
static
void
onDeliveryComplete
(
void
*
context
,
MQTTAsync_token
token
)
{
printf
(
"onDeliveryComplete,token:%d
\n
"
,
token
);
}
static
void
onConnectBuild
(
void
*
context
,
char
*
cause
)
{
printf
(
"onConnectBuild,disconnect cause:%s
\n
"
,
cause
);
}
static
void
onDisConnected
(
void
*
context
,
MQTTProperties
*
properties
,
enum
MQTTReasonCodes
reasonCode
)
{
printf
(
"onDisConnected,maybe kicked by broker.
\n
"
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
MQTTAsync
client
;
MQTTAsync_connectOptions
conn_opts
=
MQTTAsync_connectOptions_initializer
;
int
rc
;
MQTTAsync_createOptions
opts
=
MQTTAsync_createOptions_initializer
;
opts
.
MQTTVersion
=
MQTTVERSION_3_1_1
;
MQTTAsync_setTraceCallback
(
mqttTraceCallback
);
if
((
rc
=
MQTTAsync_createWithOptions
(
&
client
,
ADDRESS
,
CLIENTID
,
MQTTCLIENT_PERSISTENCE_NONE
,
NULL
,
&
opts
))
!=
MQTTASYNC_SUCCESS
)
{
printf
(
"Failed to create client object, return code %d
\n
"
,
rc
);
return
-
1
;
}
if
((
rc
=
MQTTAsync_setCallbacks
(
client
,
NULL
,
connlost
,
messageArrived
,
NULL
))
!=
MQTTASYNC_SUCCESS
)
{
printf
(
"Failed to set callback, return code %d
\n
"
,
rc
);
exit
(
EXIT_FAILURE
);
}
MQTTAsync_setConnectionLostCallback
(
client
,
NULL
,
connlost
);
MQTTAsync_setMessageArrivedCallback
(
client
,
NULL
,
messageArrived
);
MQTTAsync_setDeliveryCompleteCallback
(
client
,
NULL
,
onDeliveryComplete
);
MQTTAsync_setConnected
(
client
,
NULL
,
onConnectBuild
);
MQTTAsync_setDisconnected
(
client
,
NULL
,
onDisConnected
);
conn_opts
.
keepAliveInterval
=
20
;
conn_opts
.
cleansession
=
1
;
conn_opts
.
onSuccess
=
onConnect
;
conn_opts
.
onFailure
=
onConnectFailure
;
conn_opts
.
context
=
client
;
if
((
rc
=
MQTTAsync_connect
(
client
,
&
conn_opts
))
!=
MQTTASYNC_SUCCESS
)
{
printf
(
"Failed to start connect, return code %d
\n
"
,
rc
);
exit
(
EXIT_FAILURE
);
}
printf
(
"Waiting for publication of %s
\n
"
"on topic %s for client with ClientID: %s
\n
"
,
PAYLOAD
,
TOPIC
,
CLIENTID
);
while
(
!
finished
)
#if defined(_WIN32)
Sleep
(
100
);
#else
usleep
(
10000L
);
#endif
MQTTAsync_destroy
(
&
client
);
return
rc
;
}
common/mqtt/samples/pubsub_opts.h
deleted
100644 → 0
View file @
f5741418
/*******************************************************************************
* Copyright (c) 2012, 2018 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* https://www.eclipse.org/legal/epl-2.0/
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Ian Craggs - initial contribution
* Guilherme Maciel Ferreira - add keep alive option
*******************************************************************************/
#if !defined(PUBSUB_OPTS_H)
#define PUBSUB_OPTS_H
#include "MQTTAsync.h"
#include "MQTTClientPersistence.h"
struct
pubsub_opts
{
/* debug app options */
int
publisher
;
/* publisher app? */
int
quiet
;
int
verbose
;
int
tracelevel
;
char
*
delimiter
;
int
maxdatalen
;
/* message options */
char
*
message
;
char
*
filename
;
int
stdin_lines
;
int
stdlin_complete
;
int
null_message
;
/* MQTT options */
int
MQTTVersion
;
char
*
topic
;
char
*
clientid
;
int
qos
;
int
retained
;
char
*
username
;
char
*
password
;
char
*
host
;
char
*
port
;
char
*
connection
;
int
keepalive
;
/* will options */
char
*
will_topic
;
char
*
will_payload
;
int
will_qos
;
int
will_retain
;
/* TLS options */
int
insecure
;
char
*
capath
;
char
*
cert
;
char
*
cafile
;
char
*
key
;
char
*
keypass
;
char
*
ciphers
;
char
*
psk_identity
;
char
*
psk
;
/* MQTT V5 options */
int
message_expiry
;
struct
{
char
*
name
;
char
*
value
;
}
user_property
;
};
typedef
struct
{
const
char
*
name
;
const
char
*
value
;
}
pubsub_opts_nameValue
;
//void usage(struct pubsub_opts* opts, const char* version, const char* program_name);
void
usage
(
struct
pubsub_opts
*
opts
,
pubsub_opts_nameValue
*
name_values
,
const
char
*
program_name
);
int
getopts
(
int
argc
,
char
**
argv
,
struct
pubsub_opts
*
opts
);
char
*
readfile
(
int
*
data_len
,
struct
pubsub_opts
*
opts
);
void
logProperties
(
MQTTProperties
*
props
);
#endif
makefile
View file @
61fa270c
...
...
@@ -12,6 +12,7 @@ COMP_LIB_COMPONENTS := \
SUBDIRS
+=
common/mqtt
$(call
Append_Conditional,
SUBDIRS)
include
$(RULE_DIR)/rules.mk
...
...
src/samples/MQTTAsync_publish.c
View file @
61fa270c
...
...
@@ -143,7 +143,7 @@ int messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_messa
}
static
void
mqttTraceCallback
(
enum
MQTTASYNC_TRACE_LEVELS
level
,
char
*
message
)
{
printf
(
"mqttTraceCallback level:%d,msg:%s.
\n
"
,
level
,
message
);
//
printf("mqttTraceCallback level:%d,msg:%s.\n",level,message);
}
static
void
onDeliveryComplete
(
void
*
context
,
MQTTAsync_token
token
)
{
...
...
src/samples/iot.mk
View file @
61fa270c
LIBA_TARGET
:=
libiot_mqtt_func.a
LIBA_TARGET
:=
libiot_mqtt_func.a
SRCS_example
:=
MQTTAsync_publish.c
#SRCS_example
:= MQTTAsync_publish.c
$(call
Append_Conditional,
TARGET,
MQTTAsync_publish)
#CFLAGS += -I../../work/ssl/include -lrt
#LDFLAGS += -L../../work/ssl/lib
LDFLAGS
+=
-liot_mqtt
-ldl
#DEPENDS += common/mqtt
LDFLAGS
+=
-liot_sdk
-liot_mqtt
-ldl
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment