Skip to content

Conversation

@walidbadar
Copy link
Contributor

@walidbadar walidbadar commented Nov 15, 2025

  • Disable DHCPv4 and use static network configuration for native_sim board. 
@walidbadar walidbadar changed the title samples: ocpp: use BUILD_ASSERT and add native_sim config samples: ocpp: check SNTP and OCPP server config and add native_sim config Nov 16, 2025
CONFIG_NET_DHCPV4=n
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_NEED_IPV4=y
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

no hard coded value please

Copy link
Member

@jukkar jukkar Nov 17, 2025

Choose a reason for hiding this comment

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

This IP address space is reserved for documentation and we are using it in all the network samples, so these are OK to be used here.

Copy link
Contributor

Choose a reason for hiding this comment

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

noted, good to know.

struct timespec tv;
int ret;

if (strlen(CONFIG_NET_SAMPLE_SNTP_SERVER) < 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

run time error will be get down in sntp_init.

Copy link
Contributor Author

@walidbadar walidbadar Nov 17, 2025

Choose a reason for hiding this comment

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

No, ocpp_get_time_from_sntp would return -EINVAL before getting to sntp_init.

Copy link
Contributor

Choose a reason for hiding this comment

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

the change is not needed, if CONFIG_NET_SAMPLE_SNTP_SERVER not configured which will endup with run time error in sntp_init.

struct timespec tv;
int ret;

if (strlen(CONFIG_NET_SAMPLE_SNTP_SERVER) < 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

the change is not needed, if CONFIG_NET_SAMPLE_SNTP_SERVER not configured which will endup with run time error in sntp_init.


ocpp_get_time_from_sntp();
ret = ocpp_get_time_from_sntp();
if (ret < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should not return even sntp unreachable.. e.g system time is maintained in RTC or some other source.


wait_for_network();

if (strlen(CONFIG_NET_SAMPLE_OCPP_SERVER) < 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto, ocpp_getaddrinfo endup runtime error.

Copy link
Contributor Author

@walidbadar walidbadar Nov 17, 2025

Choose a reason for hiding this comment

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

the reason for this logic was to warn the user that ocpp server address was not configured, there could also be other reason why getaddrinfo might get fail.

Copy link
Member

@jukkar jukkar Nov 17, 2025

Choose a reason for hiding this comment

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

We could avoid the call to strlen() here

if (CONFIG_NET_SAMPLE_OCPP_SERVER[0] == '\0') { 
CONFIG_NET_DHCPV4=n
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_NEED_IPV4=y
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

noted, good to know.

Disable DHCPv4 and use static network configuration for native_sim board Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
@walidbadar walidbadar changed the title samples: ocpp: check SNTP and OCPP server config and add native_sim config samples: ocpp: add native_sim config Nov 17, 2025
@walidbadar walidbadar requested a review from jukkar November 18, 2025 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants