Skip to content
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

Merged
merged 9 commits into from
May 17, 2023
Merged

Zephyr port #333

merged 9 commits into from
May 17, 2023

Conversation

julek-wolfssl
Copy link
Member

@julek-wolfssl julek-wolfssl commented Apr 28, 2023

@julek-wolfssl julek-wolfssl self-assigned this Apr 28, 2023
Copy link
Member

@embhorn embhorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I have not tested yet, but please check out comments / questions.

zephyr/README.md Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for overriding the normal "user_settings.h"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following the same approach as in the wolfSSL Zephyr support. We usually have dedicated user settings for each use case. Is there anything missing that you think should go in here too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually the file named user_settings.h is picked up from the project include path when WOLFMQTT_USER_SETTINGS in CFLAGS. By using a different file name, you had to add this in mqtt_types.h

#ifdef CONFIG_WOLFMQTT_SETTINGS_FILE
#include CONFIG_WOLFMQTT_SETTINGS_FILE
#endif

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Zephyr both wolfSSL and wolfMQTT are compiled at the same time and linked into one executable. Is there any worry of accidentally including the wolfSSL user_settings.h file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build options do not conflict. Usually we use a single user_settings.h for both libraries.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dgarske. I'll change the defaults accordingly. I'll leave the wolfSSL user_settings.h stuff as is since it may be used by users.

Comment on lines 756 to 767
#ifdef WOLFMQTT_ZEPHYR
void main(void)
{
(void)run_client(0, NULL);
}
#else
int main(int argc, char** argv)
{
return run_client(argc, argv);
}
#endif

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be irrelevant now:
zephyrproject-rtos/zephyr#54628

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Comment on lines 722 to 724
#ifdef WOLFMQTT_TOPIC
mqttCtx.topic_name = WOLFMQTT_TOPIC;
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can specify topic name with -n option
mqttclient -n <topic_name>

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

@embhorn embhorn May 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about defining WOLFMQTT_TOPIC_NAME in user_settings.h ?

You'll need to add a #ifndef check in examples/mqttexample.h around the default definition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using WOLFMQTT_TOPIC_NAME.

Comment on lines 716 to 718
#ifdef ENABLE_MQTT_TLS
mqttCtx.use_tls = 1;
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can specify TLS with -t option
mqttclient -t

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using WOLFMQTT_DEFAULT_TLS in user settings.

Comment on lines 713 to 715
#ifdef CONFIG_NET_CONFIG_PEER_IPV4_ADDR
mqttCtx.host = CONFIG_NET_CONFIG_PEER_IPV4_ADDR;
#endif
Copy link
Member

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 option
mqttclient -h <host_name>

Copy link
Member

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 in examples/mqttexample.h

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using DEFAULT_MQTT_HOST.

Comment on lines 719 to 721
#ifdef CONFIG_NET_CONFIG_PEER_PORT
mqttCtx.port = CONFIG_NET_CONFIG_PEER_PORT;
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can specify port with -p option
mqttclient -p <port_number>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the default ports that depend on TLS.

@dgarske dgarske assigned dgarske and unassigned dgarske Apr 28, 2023
@julek-wolfssl
Copy link
Member Author

Forgot to add new files to include.am

Comment on lines 73 to 75
#ifdef CONFIG_WOLFMQTT_SETTINGS_FILE
#include CONFIG_WOLFMQTT_SETTINGS_FILE
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you renamed the file to user_settings.h, it could be picked up from line 64 above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed.

Comment on lines 68 to 72
#define WOLFMQTT_ZEPHYR
#ifdef CONFIG_WOLFMQTT_TLS
#undef ENABLE_MQTT_TLS
#define ENABLE_MQTT_TLS
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this go into user_settings.h?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it so that users can conveniently configure wolfMQTT from Zephyr's menuconfig. I can move it if you prefer it user settings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you used the magic words "configure wolfMQTT", so this belongs in user_settings.h

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to user_settings.h.

- Use macros in user settings to configure connection settings
- Fix `main()` signature
- Add note with link in main README
- Add debugging info to README
@julek-wolfssl julek-wolfssl requested a review from embhorn May 10, 2023 16:08
Copy link
Member

@embhorn embhorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Please see comments.

@@ -632,31 +644,31 @@ int mqtt_tls_cb(MqttClient* client)
return rc;
}
}
#else
#if 0
#elif defined(WOLFMQTT_ZEPHYR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for #if !defined(NO_FILESYSTEM). Would it make sense to have it be #else instead of #elif defined(WOLFMQTT_ZEPHYR) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gated it on WOLFMQTT_ZEPHYR due to the #if 0 that was in there. It achieves the same and new configurations that want this section to be active can add the configs here.

@@ -34,8 +34,6 @@
/* Windows uses the vs_settings.h file included vis mqtt_types.h */
#if !defined(WOLFMQTT_USER_SETTINGS) && \
!defined(_WIN32) && !defined(USE_WINDOWS_API)
/* If options.h is missing use the "./configure" script. Otherwise, copy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not a problem for VS builds anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding comment back in. Not sure why I deleted it.

Comment on lines 742 to 744
/* In zephyr commit 0b90fd5adf1f01625412efadba4331b5041fb828 the main signature
* was changed from void main(void) to int main(void). Zephyr doesn't provide a
* way to check the version of Zephyr at compile time so support the latest. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was really hoping to not have port specific code in here. After that commit is in a release can we revisit this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can go the NO_MAIN_DRIVER route if you prefer that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use NO_MAIN_DRIVER.

@julek-wolfssl julek-wolfssl requested a review from embhorn May 10, 2023 20:55
embhorn
embhorn previously approved these changes May 12, 2023
Copy link
Member

@embhorn embhorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, @julek-wolfssl ! Thanks for adding bwrap to the tests, that is a huge improvement in itself.

Dla mnie wygląda dobrze!

@julek-wolfssl
Copy link
Member Author

@embhorn @dgarske
Added a github action to build and run tests against zephyr. Had to modify the user settings include in mqtt_types.h.

@julek-wolfssl julek-wolfssl requested a review from embhorn May 15, 2023 20:42
@julek-wolfssl julek-wolfssl assigned dgarske and unassigned embhorn May 17, 2023
@dgarske dgarske merged commit b5cead7 into wolfSSL:master May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants