-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zephyr port #333
Zephyr port #333
Changes from 1 commit
178c051
50530d9
e2201cb
8b345bd
ceee98d
dde03b3
6a4df26
d69c7b5
67e7603
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -699,7 +699,7 @@ int mqttclient_test(MQTTCtx *mqttCtx) | |
} | ||
#endif | ||
|
||
int main(int argc, char** argv) | ||
static int run_client(int argc, char** argv) | ||
{ | ||
int rc; | ||
MQTTCtx mqttCtx; | ||
|
@@ -709,6 +709,21 @@ int main(int argc, char** argv) | |
mqttCtx.app_name = "mqttclient"; | ||
mqttCtx.message = DEFAULT_MESSAGE; | ||
|
||
#ifdef WOLFMQTT_ZEPHYR | ||
#ifdef CONFIG_NET_CONFIG_PEER_IPV4_ADDR | ||
mqttCtx.host = CONFIG_NET_CONFIG_PEER_IPV4_ADDR; | ||
#endif | ||
#ifdef ENABLE_MQTT_TLS | ||
mqttCtx.use_tls = 1; | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can specify TLS with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
#ifdef CONFIG_NET_CONFIG_PEER_PORT | ||
mqttCtx.port = CONFIG_NET_CONFIG_PEER_PORT; | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can specify port with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the default ports that depend on TLS. |
||
#ifdef WOLFMQTT_TOPIC | ||
mqttCtx.topic_name = WOLFMQTT_TOPIC; | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can specify topic name with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This example is for the Zephyr RTOS. I don't know how to pass in command line parameters there. I was also following the way that the Zephyr MQTT example defines the host, port, and topic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about defining You'll need to add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
#endif | ||
|
||
/* parse arguments */ | ||
rc = mqtt_parse_args(&mqttCtx, argc, argv); | ||
if (rc != 0) { | ||
|
@@ -738,4 +753,16 @@ int main(int argc, char** argv) | |
return (rc == 0) ? 0 : EXIT_FAILURE; | ||
} | ||
|
||
#ifdef WOLFMQTT_ZEPHYR | ||
void main(void) | ||
{ | ||
(void)run_client(0, NULL); | ||
} | ||
#else | ||
int main(int argc, char** argv) | ||
{ | ||
return run_client(argc, argv); | ||
} | ||
#endif | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be irrelevant now: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested on the latest release. I'll check with master when I get back. |
||
#endif /* NO_MAIN_DRIVER */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
#include "wolfmqtt/mqtt_client.h" | ||
#include "examples/mqttexample.h" | ||
#include "examples/mqttnet.h" | ||
#include "examples/mqttport.h" | ||
|
||
|
||
/* locals */ | ||
|
@@ -464,7 +465,7 @@ void mqtt_free_ctx(MQTTCtx* mqttCtx) | |
} | ||
} | ||
|
||
#if defined(__GNUC__) && !defined(NO_EXIT) | ||
#if defined(__GNUC__) && !defined(NO_EXIT) && !defined(WOLFMQTT_ZEPHYR) | ||
__attribute__ ((noreturn)) | ||
#endif | ||
int err_sys(const char* msg) | ||
|
@@ -473,6 +474,14 @@ int err_sys(const char* msg) | |
PRINTF("wolfMQTT error: %s", msg); | ||
} | ||
exit(EXIT_FAILURE); | ||
#ifdef WOLFMQTT_ZEPHYR | ||
/* Zephyr compiler produces below warning. Let's silence it. | ||
* warning: 'noreturn' function does return | ||
* 477 | } | ||
* | ^ | ||
*/ | ||
return 0; | ||
#endif | ||
} | ||
|
||
|
||
|
@@ -632,31 +641,31 @@ int mqtt_tls_cb(MqttClient* client) | |
return rc; | ||
} | ||
} | ||
#else | ||
#if 0 | ||
#elif defined(WOLFMQTT_ZEPHYR) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I gated it on |
||
#ifdef WOLFSSL_ENCRYPTED_KEYS | ||
/* Setup password callback for pkcs8 key */ | ||
wolfSSL_CTX_set_default_passwd_cb(client->tls.ctx, | ||
mqtt_password_cb); | ||
#endif | ||
/* Examples for loading buffer directly */ | ||
/* Load CA certificate buffer */ | ||
rc = wolfSSL_CTX_load_verify_buffer(client->tls.ctx, | ||
(const byte*)root_ca, (long)XSTRLEN(root_ca), WOLFSSL_FILETYPE_PEM); | ||
rc = wolfSSL_CTX_load_verify_buffer_ex(client->tls.ctx, | ||
(const byte*)root_ca, (long)sizeof(root_ca), | ||
WOLFSSL_FILETYPE_ASN1, 0, WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY); | ||
|
||
/* Load Client Cert */ | ||
if (rc == WOLFSSL_SUCCESS) | ||
if (rc == WOLFSSL_SUCCESS) { | ||
rc = wolfSSL_CTX_use_certificate_buffer(client->tls.ctx, | ||
(const byte*)device_cert, (long)XSTRLEN(device_cert), | ||
WOLFSSL_FILETYPE_PEM); | ||
|
||
#ifdef WOLFSSL_ENCRYPTED_KEYS | ||
/* Setup password callback for pkcs8 key */ | ||
wolfSSL_CTX_set_default_passwd_cb(client->tls.ctx, | ||
mqtt_password_cb); | ||
#endif | ||
(const byte*)device_cert, (long)sizeof(device_cert), | ||
WOLFSSL_FILETYPE_ASN1); | ||
} | ||
|
||
/* Load Private Key */ | ||
if (rc == WOLFSSL_SUCCESS) | ||
if (rc == WOLFSSL_SUCCESS) { | ||
rc = wolfSSL_CTX_use_PrivateKey_buffer(client->tls.ctx, | ||
(const byte*)device_priv_key, (long)XSTRLEN(device_priv_key), | ||
WOLFSSL_FILETYPE_PEM); | ||
#endif | ||
(const byte*)device_priv_key, (long)sizeof(device_priv_key), | ||
WOLFSSL_FILETYPE_ASN1); | ||
} | ||
#endif /* !NO_FILESYSTEM */ | ||
#endif /* !NO_CERT */ | ||
#ifdef HAVE_SNI | ||
|
@@ -712,7 +721,7 @@ int mqtt_file_load(const char* filePath, byte** fileBuf, int *fileLen) | |
{ | ||
#if !defined(NO_FILESYSTEM) | ||
int rc = 0; | ||
FILE* file = NULL; | ||
XFILE file = NULL; | ||
long int pos = -1L; | ||
|
||
/* Check arguments */ | ||
|
@@ -722,29 +731,29 @@ int mqtt_file_load(const char* filePath, byte** fileBuf, int *fileLen) | |
} | ||
|
||
/* Open file */ | ||
file = fopen(filePath, "rb"); | ||
file = XFOPEN(filePath, "rb"); | ||
if (file == NULL) { | ||
PRINTF("File '%s' does not exist!", filePath); | ||
rc = EXIT_FAILURE; | ||
goto exit; | ||
} | ||
|
||
/* Determine length of file */ | ||
if (fseek(file, 0, SEEK_END) != 0) { | ||
if (XFSEEK(file, 0, XSEEK_END) != 0) { | ||
PRINTF("fseek() failed"); | ||
rc = EXIT_FAILURE; | ||
goto exit; | ||
} | ||
|
||
pos = (int) ftell(file); | ||
pos = (int)XFTELL(file); | ||
if (pos == -1L) { | ||
PRINTF("ftell() failed"); | ||
rc = EXIT_FAILURE; | ||
goto exit; | ||
} | ||
|
||
*fileLen = (int)pos; | ||
if (fseek(file, 0, SEEK_SET) != 0) { | ||
if (XFSEEK(file, 0, XSEEK_SET) != 0) { | ||
PRINTF("fseek() failed"); | ||
rc = EXIT_FAILURE; | ||
goto exit; | ||
|
@@ -762,7 +771,7 @@ int mqtt_file_load(const char* filePath, byte** fileBuf, int *fileLen) | |
} | ||
|
||
/* Load file into buffer */ | ||
rc = (int)fread(*fileBuf, 1, *fileLen, file); | ||
rc = (int)XFREAD(*fileBuf, 1, *fileLen, file); | ||
if (rc != *fileLen) { | ||
PRINTF("Error reading file! %d", rc); | ||
rc = EXIT_FAILURE; | ||
|
@@ -772,7 +781,7 @@ int mqtt_file_load(const char* filePath, byte** fileBuf, int *fileLen) | |
|
||
exit: | ||
if (file) { | ||
fclose(file); | ||
XFCLOSE(file); | ||
} | ||
if (rc != 0) { | ||
if (*fileBuf) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can specify host with
-h
optionmqttclient -h <host_name>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, define
DEFAULT_MQTT_HOST
in user_settings.h. This already has an#ifndef
check inexamples/mqttexample.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
DEFAULT_MQTT_HOST
.