Skip to content

Commit f8daabc

Browse files
committed
modules: environmental: Cleanup
Cleanup, update manifest to fix bug. Signed-off-by: Simen S. Røstad <simen.rostad@nordicsemi.no>
1 parent a04bb77 commit f8daabc

11 files changed

+201
-66
lines changed

app/boards/thingy91x_nrf9151_ns.conf

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@
44
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
#
66

7-
CONFIG_BME680=n
8-
CONFIG_BME68X_IAQ=y
9-
CONFIG_BME68X_IAQ_THREAD_STACK_SIZE=2048
10-
CONFIG_BME68X_IAQ_SAMPLE_RATE_ULTRA_LOW_POWER=y
7+
CONFIG_BME680=y

app/boards/thingy91x_nrf9151_ns.overlay

-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
};
1212

1313
/ {
14-
aliases {
15-
gas-sensor = &bme680;
16-
};
17-
1814
chosen {
1915
nordic,modem-trace-uart = &uart1;
2016
zephyr,wifi = &nordic_wlan0;

app/prj.conf

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ CONFIG_DK_LIBRARY=y
1313
CONFIG_ZVFS_OPEN_MAX=10
1414
CONFIG_PWM=y
1515

16-
# Disable UART NRFX legacy shim to make the device boot.
17-
CONFIG_UART_NRFX_UARTE_LEGACY_SHIM=n
18-
1916
# Heap and stacks
2017
CONFIG_MAIN_STACK_SIZE=4096
2118
# Extended AT host/monitor stack/heap sizes since some nrf_cloud credentials are longer than 1024 bytes.
@@ -122,7 +119,6 @@ CONFIG_FOTA_DOWNLOAD=y
122119
CONFIG_FOTA_DOWNLOAD_PROGRESS_EVT=y
123120
CONFIG_FOTA_DL_TIMEOUT_MIN=30
124121
CONFIG_DFU_TARGET=y
125-
CONFIG_BUILD_S1_VARIANT=y
126122
# COAP client
127123
CONFIG_COAP_CLIENT_THREAD_PRIORITY=0
128124
CONFIG_COAP_CLIENT_BLOCK_SIZE=1024
@@ -163,6 +159,7 @@ CONFIG_LTE_NETWORK_MODE_LTE_M_NBIOT_GPS=y
163159
CONFIG_WIFI=y
164160
CONFIG_WIFI_NRF70=y
165161
CONFIG_WIFI_NRF70_SKIP_LOCAL_ADMIN_MAC=y
162+
CONFIG_WIFI_NRF70_LOG_LEVEL_ERR=y
166163
CONFIG_NRF70_BH_WQ_STACK_SIZE=1024
167164
CONFIG_NRF70_IRQ_WQ_STACK_SIZE=1024
168165

app/src/common/message_channel.c

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ ZBUS_CHAN_DEFINE(TRIGGER_CHAN,
1818
ZBUS_MSG_INIT(0)
1919
);
2020

21+
ZBUS_CHAN_DEFINE(ENVIRONMENTAL_CHAN,
22+
struct environmental_msg,
23+
NULL,
24+
NULL,
25+
ZBUS_OBSERVERS_EMPTY,
26+
ZBUS_MSG_INIT(0)
27+
);
28+
2129
ZBUS_CHAN_DEFINE(ERROR_CHAN,
2230
enum error_type,
2331
NULL,

app/src/common/message_channel.h

+34
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,39 @@ extern "C" {
4848
k_sleep(K_SECONDS(10)); \
4949
} while (0)
5050

51+
/** ENVIRONMENTAL MODULE */
52+
53+
enum environmental_msg_type {
54+
/* Output message types */
55+
56+
/* Response message to a request for current environmental sensor values.
57+
* The sampled values are found in the respective fields of the message structure.
58+
*/
59+
ENVIRONMENTAL_SENSOR_SAMPLE_RESPONSE = 0x1,
60+
61+
/* Input message types */
62+
63+
/* Request to sample the current environmental sensor values.
64+
* The response is sent as a ENVIRONMENTAL_SENSOR_SAMPLE_RESPONSE message.
65+
*/
66+
ENVIRONMENTAL_SENSOR_SAMPLE_REQUEST,
67+
};
68+
69+
struct environmental_msg {
70+
enum environmental_msg_type type;
71+
72+
/** Contains the current temperature in celsius. */
73+
double temperature;
74+
75+
/** Contains the current humidity in percentage. */
76+
double humidity;
77+
78+
/** Contains the current pressure in Pa. */
79+
double pressure;
80+
};
81+
82+
#define MSG_TO_ENVIRONMENTAL_MSG(_msg) (*(const struct environmental_msg *)_msg)
83+
5184
enum trigger_type {
5285
TRIGGER_POLL_SHADOW = 0x1,
5386
TRIGGER_FOTA_POLL,
@@ -91,6 +124,7 @@ ZBUS_CHAN_DECLARE(
91124
CONFIG_CHAN,
92125
ERROR_CHAN,
93126
TIME_CHAN,
127+
ENVIRONMENTAL_CHAN,
94128
TRIGGER_CHAN
95129
);
96130

app/src/modules/app/app.c

+10
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ static void triggers_send(void)
120120
struct battery_msg battery_msg = {
121121
.type = BATTERY_PERCENTAGE_SAMPLE_REQUEST,
122122
};
123+
struct battery_msg environmental_msg = {
124+
.type = ENVIRONMENTAL_SENSOR_SAMPLE_REQUEST,
125+
};
123126
enum trigger_type poll_trigger = TRIGGER_FOTA_POLL;
124127

125128
err = zbus_chan_pub(&NETWORK_CHAN, &network_msg, K_SECONDS(1));
@@ -136,6 +139,13 @@ static void triggers_send(void)
136139
return;
137140
}
138141

142+
err = zbus_chan_pub(&ENVIRONMENTAL_CHAN, &environmental_msg, K_SECONDS(1));
143+
if (err) {
144+
LOG_ERR("zbus_chan_pub, error: %d", err);
145+
SEND_FATAL_ERROR();
146+
return;
147+
}
148+
139149
/* Send FOTA poll trigger */
140150
err = zbus_chan_pub(&TRIGGER_CHAN, &poll_trigger, K_SECONDS(1));
141151
if (err) {

app/src/modules/cloud/cloud_module.c

+37-3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ LOG_MODULE_REGISTER(cloud, CONFIG_APP_CLOUD_LOG_LEVEL);
2828
#define CUSTOM_JSON_APPID_VAL_CONEVAL "CONEVAL"
2929
#define CUSTOM_JSON_APPID_VAL_BATTERY "BATTERY"
3030
#define MAX_MSG_SIZE (MAX(sizeof(struct cloud_payload), \
31-
MAX(sizeof(struct network_msg), sizeof(struct battery_msg))))
31+
MAX(sizeof(struct network_msg), \
32+
MAX(sizeof(struct battery_msg), sizeof(struct environmental_msg)))))
3233

3334
BUILD_ASSERT(CONFIG_APP_CLOUD_WATCHDOG_TIMEOUT_SECONDS >
34-
CONFIG_APP_CLOUD_EXEC_TIME_SECONDS_MAX,
35-
"Watchdog timeout must be greater than maximum execution time");
35+
CONFIG_APP_CLOUD_EXEC_TIME_SECONDS_MAX,
36+
"Watchdog timeout must be greater than maximum execution time");
3637

3738
/* Register subscriber */
3839
ZBUS_MSG_SUBSCRIBER_DEFINE(cloud);
@@ -42,6 +43,7 @@ ZBUS_CHAN_ADD_OBS(PAYLOAD_CHAN, cloud, 0);
4243
ZBUS_CHAN_ADD_OBS(NETWORK_CHAN, cloud, 0);
4344
ZBUS_CHAN_ADD_OBS(BATTERY_CHAN, cloud, 0);
4445
ZBUS_CHAN_ADD_OBS(TRIGGER_CHAN, cloud, 0);
46+
ZBUS_CHAN_ADD_OBS(ENVIRONMENTAL_CHAN, cloud, 0);
4547

4648
/* Define channels provided by this module */
4749

@@ -546,6 +548,38 @@ static void state_connected_ready_run(void *o)
546548
}
547549
}
548550

551+
if (state_object->chan == &ENVIRONMENTAL_CHAN) {
552+
struct environmental_msg msg = MSG_TO_ENVIRONMENTAL_MSG(state_object->msg_buf);
553+
554+
if (msg.type == ENVIRONMENTAL_SENSOR_SAMPLE_RESPONSE) {
555+
err = nrf_cloud_coap_sensor_send(NRF_CLOUD_JSON_APPID_VAL_TEMP,
556+
msg.temperature,
557+
NRF_CLOUD_NO_TIMESTAMP, true);
558+
if (err) {
559+
LOG_ERR("nrf_cloud_coap_sensor_send, error: %d", err);
560+
SEND_FATAL_ERROR();
561+
}
562+
563+
err = nrf_cloud_coap_sensor_send(NRF_CLOUD_JSON_APPID_VAL_AIR_PRESS,
564+
msg.pressure,
565+
NRF_CLOUD_NO_TIMESTAMP, true);
566+
if (err) {
567+
LOG_ERR("nrf_cloud_coap_sensor_send, error: %d", err);
568+
SEND_FATAL_ERROR();
569+
}
570+
571+
err = nrf_cloud_coap_sensor_send(NRF_CLOUD_JSON_APPID_VAL_HUMID,
572+
msg.humidity,
573+
NRF_CLOUD_NO_TIMESTAMP, true);
574+
if (err) {
575+
LOG_ERR("nrf_cloud_coap_sensor_send, error: %d", err);
576+
SEND_FATAL_ERROR();
577+
}
578+
579+
return;
580+
}
581+
}
582+
549583
if (state_object->chan == &PAYLOAD_CHAN) {
550584
struct cloud_payload *payload = MSG_TO_PAYLOAD(state_object->msg_buf);
551585

app/src/modules/environmental/Kconfig.environmental

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
menuconfig APP_ENVIRONMENTAL
88
bool "Environmental module"
9-
depends on BME68X_IAQ
9+
depends on BME680
1010
default y
1111

1212
if APP_ENVIRONMENTAL

0 commit comments

Comments
 (0)