Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
0bb14abb
Commit
0bb14abb
authored
Jul 14, 2017
by
Sergey Lyubka
Committed by
Cesanta Bot
Jul 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Nitpick for MQTT example
PUBLISHED_FROM=a0dd26c00b41363f1cc58c28f530fbdf272ed146
parent
4c37e492
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
11 deletions
+17
-11
Makefile
examples/mqtt_broker/Makefile
+1
-1
mqtt_broker.c
examples/mqtt_broker/mqtt_broker.c
+15
-6
mqtt_client.c
examples/mqtt_client/mqtt_client.c
+1
-4
No files found.
examples/mqtt_broker/Makefile
View file @
0bb14abb
PROG
=
mqtt_broker
MODULE_CFLAGS
=
-DMG_ENABLE_MQTT_BROKER
-DMG_ENABLE_HTTP
=
0
SSL_LIB
=
openssl
#
SSL_LIB=openssl
include
../examples.mk
examples/mqtt_broker/mqtt_broker.c
View file @
0bb14abb
...
...
@@ -17,22 +17,31 @@
#include "../../mongoose.h"
static
const
char
*
s_listening_address
=
"0.0.0.0:1883"
;
static
void
ev_handler
(
struct
mg_connection
*
c
,
int
ev
,
void
*
ev_data
)
{
if
(
ev
!=
MG_EV_POLL
)
printf
(
"USER HANDLER GOT EVENT %d
\n
"
,
ev
);
/* Do your custom event processing here */
mg_mqtt_broker
(
c
,
ev
,
ev_data
);
}
int
main
(
void
)
{
struct
mg_mgr
mgr
;
const
char
*
address
=
"0.0.0.0:1883"
;
struct
mg_connection
*
nc
;
struct
mg_connection
*
c
;
struct
mg_mqtt_broker
brk
;
mg_mgr_init
(
&
mgr
,
NULL
);
mg_mqtt_broker_init
(
&
brk
,
NULL
);
if
((
nc
=
mg_bind
(
&
mgr
,
address
,
mg_mqtt_brok
er
))
==
NULL
)
{
fprintf
(
stderr
,
"mg_bind(%s) failed
\n
"
,
address
);
if
((
c
=
mg_bind
(
&
mgr
,
s_listening_address
,
ev_handl
er
))
==
NULL
)
{
fprintf
(
stderr
,
"mg_bind(%s) failed
\n
"
,
s_listening_
address
);
exit
(
EXIT_FAILURE
);
}
nc
->
user_data
=
&
brk
;
mg_mqtt_broker_init
(
&
brk
,
NULL
);
c
->
user_data
=
&
brk
;
mg_set_protocol_mqtt
(
c
);
printf
(
"MQTT broker started on %s
\n
"
,
address
);
printf
(
"MQTT broker started on %s
\n
"
,
s_listening_
address
);
/*
* TODO: Add a HTTP status page that shows current sessions
...
...
examples/mqtt_client/mqtt_client.c
View file @
0bb14abb
...
...
@@ -27,10 +27,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
struct
mg_mqtt_message
*
msg
=
(
struct
mg_mqtt_message
*
)
p
;
(
void
)
nc
;
#if 0
if (ev != MG_EV_POLL)
printf("USER HANDLER GOT %d\n", ev);
#endif
if
(
ev
!=
MG_EV_POLL
)
printf
(
"USER HANDLER GOT EVENT %d
\n
"
,
ev
);
switch
(
ev
)
{
case
MG_EV_CONNECT
:
{
...
...
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