Skip to content

Cleanup of the 93m1 applications - #29

Merged
SyverHaraldsen merged 2 commits into
mainfrom
applications-93-cleanup
Jun 25, 2026
Merged

Cleanup of the 93m1 applications#29
SyverHaraldsen merged 2 commits into
mainfrom
applications-93-cleanup

Conversation

@SyverHaraldsen

Copy link
Copy Markdown
Collaborator

Making the applications more readable and uniform to our other samples.

@SyverHaraldsen
SyverHaraldsen force-pushed the applications-93-cleanup branch from 8f45573 to 379f687 Compare June 23, 2026 11:16
return;
}

(void)snprintf(cmd, sizeof(cmd),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it guaranteed that it is always okay to void the return value?
snprintk() should be used instead

}
*chg_status = val.val1;

struct sensor_value vbus_val;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can be moved to top of function scope

(enum sensor_channel)SENSOR_CHAN_NPM13XX_CHARGER_VBUS_STATUS,
(enum sensor_attribute)SENSOR_ATTR_NPM13XX_CHARGER_VBUS_PRESENT,
&vbus_val);
*vbus = (err == 0) && (vbus_val.val1 != 0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it fine to return 0 even though this fails?

}

return (int)soc;
LOG_INF("Battery %d%% sent to nRF Cloud", (int)soc);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it intentional to communicate with cloud from battery module?
Anyway, usually want to avoid INF level in modules. Could be DBG instead

uint8_t msg_buf[MAX_MSG_SIZE];
bool connected = false;

err = modem_at_urc_subscribe("%NRFCLOUDLOCATION: ", on_location, NULL);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it safe with multi-thread access to modem APIs?

struct modem_backend_uart uart_backend;
struct modem_pipe *uart_pipe;
struct modem_chat chat;
uint8_t uart_rx_buf[CONFIG_APP_MODEM_AT_UART_RECEIVE_BUF_SIZE] __aligned(4);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Needed to explicitly align this?

}

if (strlen(req) >= sizeof(request_buf)) {
if (snprintf((char *)at_ctx.request_buf, sizeof(at_ctx.request_buf), "%s", req) >=

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if (snprintf((char *)at_ctx.request_buf, sizeof(at_ctx.request_buf), "%s", req) >=
if (snprintk((char *)at_ctx.request_buf, sizeof(at_ctx.request_buf), "%s", req) >=

}

if (strlen(req) >= sizeof(request_buf)) {
if (snprintf((char *)at_ctx.request_buf, sizeof(at_ctx.request_buf), "%s", req) >=

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would do this in two steps, first assign to a variable and then check it

k_sem_give(&cereg_sem);
struct cereg_msg msg = { .stat = atoi(argv[1]) };

(void)zbus_chan_pub(&cereg_chan, &msg, K_NO_WAIT);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would check the return value

while (true) {
bool reg = (atomic_get(&cereg_stat) == 1 || atomic_get(&cereg_stat) == 5);
k_timeout_t wake = (reg && !connected) ? K_MSEC(500) : wait;
bool reg = (cereg_stat == 1 || cereg_stat == 5);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would check return value of network_attach() above

@simensrostad simensrostad left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To make network handling easier and reduce overall complexity I would use zephyr cellular modem driver and net mgmt for basic connectivity control. The rest can be pure AT. IMO its worth the extra overhead.

The 93m1 driver also exposes ip,apn, psm control that can be re-used.

(void)snprintf(cmd, sizeof(cmd),
"AT%%NRFCLOUDMESSAGE={\"appId\":\"BATTERY\",\"data\":\"%d\"}", (int)soc);

err = modem_at_run(cmd, NULL, 0, CONFIG_APP_BATTERY_AT_TIMEOUT_SECONDS);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Make sure that modem_at_run() is thread safe when calling from multiple modules. I think end-goal should be to have one module handle cloud related calls. This would also make it easier for users to attach an aggregator/storage type module. AND you'll worry less about conccurency issues like thread safety.

(void)snprintf(cmd, sizeof(cmd),
"AT%%NRFCLOUDMESSAGE={\"appId\":\"BATTERY\",\"data\":\"%d\"}", soc);
while (true) {
err = zbus_sub_wait_msg(&battery, &chan, msg_buf, K_FOREVER);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Make sure that the latest changes applied to ATT are in here. cc @Trond-F-Christiansen


CHANNEL_LIST(ADD_OBSERVERS)

static bool is_coordinate(const char *s);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
static bool is_coordinate(const char *s);
/* Forward declarations */
static bool is_coordinate(const char *s);

Comment thread applications/93m1_ppp/src/main.c Outdated
{
struct location_msg msg = { .type = LOCATION_FIX_REQUEST, .mode = LOCATION_MODE_ALL };

(void)zbus_chan_pub(&location_chan, &msg, PUB_TIMEOUT);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Make sure that return values are explicitly handled throughout the code to avoid undefined behavior.

}
#endif

#if defined(CONFIG_APP_BATTERY)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider making battery and other modules in the app non-optional to avoid ifdeffing if it makes the code harder to read.

Comment thread applications/93m1_ppp/src/main.c Outdated
LOG_INF("Serial Modem Host 93m1 starting");

#if defined(CONFIG_APP_BATTERY)
k_work_reschedule(&battery_sample_work, K_NO_WAIT);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Easy to miss checking retvals for these. A lot of bad practise in NCS leaving these unchecked.

@SyverHaraldsen
SyverHaraldsen force-pushed the applications-93-cleanup branch 3 times, most recently from 3d943d4 to 5561f83 Compare June 25, 2026 08:46
A general cleanup of the 93m1_ppp application.
This includes removing unused code, and moving logic to be more uniform.

Signed-off-by: Syver Haraldsen <syver.haraldsen@nordicsemi.no>
@SyverHaraldsen
SyverHaraldsen force-pushed the applications-93-cleanup branch from 5561f83 to d3a4129 Compare June 25, 2026 08:46
General cleanup and refactoring of the 93m1_at application.

Signed-off-by: Syver Haraldsen <syver.haraldsen@nordicsemi.no>
@SyverHaraldsen
SyverHaraldsen force-pushed the applications-93-cleanup branch from d3a4129 to ab5c6f8 Compare June 25, 2026 10:33
@sonarqubecloud

Copy link
Copy Markdown

@SyverHaraldsen
SyverHaraldsen merged commit 8e49b20 into main Jun 25, 2026
13 of 22 checks passed
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