Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
contiki-ng
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NATAF Emmanuel
contiki-ng
Commits
a343f3b9
Commit
a343f3b9
authored
7 years ago
by
George Oikonomou
Browse files
Options
Downloads
Patches
Plain Diff
Easily switch to IBM Watson platform mode
parent
dc453c8a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/mqtt-client/mqtt-client.c
+52
-13
52 additions, 13 deletions
examples/mqtt-client/mqtt-client.c
examples/mqtt-client/project-conf.h
+33
-1
33 additions, 1 deletion
examples/mqtt-client/project-conf.h
with
85 additions
and
14 deletions
examples/mqtt-client/mqtt-client.c
+
52
−
13
View file @
a343f3b9
...
...
@@ -49,21 +49,60 @@
#define LOG_MODULE "mqtt-client"
#define LOG_LEVEL LOG_LEVEL_NONE
/*---------------------------------------------------------------------------*/
/* Controls whether the example will work in IBM Watson IoT platform mode */
#ifdef MQTT_CLIENT_CONF_WITH_IBM_WATSON
#define MQTT_CLIENT_WITH_IBM_WATSON MQTT_CLIENT_CONF_WITH_IBM_WATSON
#else
#define MQTT_CLIENT_WITH_IBM_WATSON 0
#endif
/*---------------------------------------------------------------------------*/
/* MQTT broker address. Ignored in Watson mode */
#ifdef MQTT_CLIENT_CONF_BROKER_IP_ADDR
#define MQTT_CLIENT_BROKER_IP_ADDR MQTT_CLIENT_CONF_BROKER_IP_ADDR
#else
#define MQTT_CLIENT_BROKER_IP_ADDR "fd00::1"
#endif
/*---------------------------------------------------------------------------*/
/*
* IBM server: messaging.quickstart.internetofthings.ibmcloud.com
* (184.172.124.189) mapped in an NAT64 (prefix 64:ff9b::/96) IPv6 address
* Note: If not able to connect; lookup the IP address again as it may change.
* MQTT Org ID.
*
* If it equals "quickstart", the client will connect without authentication.
* In all other cases, the client will connect with authentication mode.
*
* Alternatively, publish to a local MQTT broker (e.g. mosquitto) running on
* the node that hosts your border router
* In Watson mode, the username will be "use-token-auth". In non-Watson mode
* the username will be MQTT_CLIENT_USERNAME.
*
* In all cases, the password will be MQTT_CLIENT_AUTH_TOKEN.
*/
#ifdef MQTT_CLIENT_CONF_BROKER_IP_ADDR
static
const
char
*
broker_ip
=
MQTT_CLIENT_CONF_BROKER_IP_ADDR
;
#define DEFAULT_ORG_ID "contiki-ng"
#ifdef MQTT_CLIENT_CONF_ORG_ID
#define MQTT_CLIENT_ORG_ID MQTT_CLIENT_CONF_ORG_ID
#else
#define MQTT_CLIENT_ORG_ID "quickstart"
#endif
/*---------------------------------------------------------------------------*/
/* MQTT token */
#ifdef MQTT_CLIENT_CONF_AUTH_TOKEN
#define MQTT_CLIENT_AUTH_TOKEN MQTT_CLIENT_CONF_AUTH_TOKEN
#else
#define MQTT_CLIENT_AUTH_TOKEN "AUTHTOKEN"
#endif
/*---------------------------------------------------------------------------*/
#if MQTT_CLIENT_WITH_IBM_WATSON
/* With IBM Watson support */
static
const
char
*
broker_ip
=
"0064:ff9b:0000:0000:0000:0000:b8ac:7cbd"
;
#define DEFAULT_ORG_ID "quickstart"
#define MQTT_CLIENT_USERNAME "use-token-auth"
#else
/* MQTT_CLIENT_WITH_IBM_WATSON */
/* Without IBM Watson support. To be used with other brokers, e.g. Mosquitto */
static
const
char
*
broker_ip
=
MQTT_CLIENT_BROKER_IP_ADDR
;
#ifdef MQTT_CLIENT_CONF_USERNAME
#define MQTT_CLIENT_USERNAME MQTT_CLIENT_CONF_USERNAME
#else
#define MQTT_CLIENT_USERNAME "use-token-auth"
#endif
#endif
/* MQTT_CLIENT_WITH_IBM_WATSON */
/*---------------------------------------------------------------------------*/
#ifdef MQTT_CLIENT_CONF_STATUS_LED
#define MQTT_CLIENT_STATUS_LED MQTT_CLIENT_CONF_STATUS_LED
...
...
@@ -133,7 +172,6 @@ static uint8_t state;
/*---------------------------------------------------------------------------*/
/* Default configuration values */
#define DEFAULT_TYPE_ID "mqtt-client"
#define DEFAULT_AUTH_TOKEN "AUTHZ"
#define DEFAULT_EVENT_TYPE_ID "status"
#define DEFAULT_SUBSCRIBE_CMD_TYPE "+"
#define DEFAULT_BROKER_PORT 1883
...
...
@@ -423,9 +461,10 @@ init_config()
/* Populate configuration with default values */
memset
(
&
conf
,
0
,
sizeof
(
mqtt_client_config_t
));
memcpy
(
conf
.
org_id
,
DEFAUL
T_ORG_ID
,
strlen
(
DEFAUL
T_ORG_ID
));
memcpy
(
conf
.
org_id
,
MQTT_CLIEN
T_ORG_ID
,
strlen
(
MQTT_CLIEN
T_ORG_ID
));
memcpy
(
conf
.
type_id
,
DEFAULT_TYPE_ID
,
strlen
(
DEFAULT_TYPE_ID
));
memcpy
(
conf
.
auth_token
,
DEFAULT_AUTH_TOKEN
,
strlen
(
DEFAULT_AUTH_TOKEN
));
memcpy
(
conf
.
auth_token
,
MQTT_CLIENT_AUTH_TOKEN
,
strlen
(
MQTT_CLIENT_AUTH_TOKEN
));
memcpy
(
conf
.
event_type_id
,
DEFAULT_EVENT_TYPE_ID
,
strlen
(
DEFAULT_EVENT_TYPE_ID
));
memcpy
(
conf
.
broker_ip
,
broker_ip
,
strlen
(
broker_ip
));
...
...
@@ -568,7 +607,7 @@ state_machine(void)
state
=
STATE_ERROR
;
break
;
}
else
{
mqtt_set_username_password
(
&
conn
,
"use-token-auth"
,
mqtt_set_username_password
(
&
conn
,
MQTT_CLIENT_USERNAME
,
conf
.
auth_token
);
}
}
...
...
This diff is collapsed.
Click to expand it.
examples/mqtt-client/project-conf.h
+
33
−
1
View file @
a343f3b9
...
...
@@ -35,8 +35,40 @@
/* Enable TCP */
#define UIP_CONF_TCP 1
/* If undefined, the demo will attempt to connect to IBM's quickstart */
/* Change to 1 to use with the IBM Watson IoT platform */
#define MQTT_CLIENT_CONF_WITH_IBM_WATSON 0
/*
* The IPv6 address of the MQTT broker to connect to.
* Ignored if MQTT_CLIENT_CONF_WITH_IBM_WATSON is 1
*/
#define MQTT_CLIENT_CONF_BROKER_IP_ADDR "fd00::1"
/*
* The Organisation ID.
*
* When in Watson mode, the example will default to Org ID "quickstart" and
* will connect using non-authenticated mode. If you want to use registered
* devices, set your Org ID here and then make sure you set the correct token
* through MQTT_CLIENT_CONF_AUTH_TOKEN.
*/
#define MQTT_CLIENT_CONF_ORG_ID "quickstart"
/*
* The MQTT username.
*
* Ignored in Watson mode: In this mode the username is always "use-token-auth"
*/
#define MQTT_CLIENT_CONF_USERNAME "mqtt-client-username"
/*
* The MQTT auth token (password) used when connecting to the MQTT broker.
*
* Used with as well as without Watson.
*
* Transported in cleartext!
*/
#define MQTT_CLIENT_CONF_AUTH_TOKEN "AUTHTOKEN"
/*---------------------------------------------------------------------------*/
#endif
/* PROJECT_CONF_H_ */
/*---------------------------------------------------------------------------*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment