Skip to content

Commit f734774

Browse files
marekmaskarinechubmartin
authored andcommitted
applications: clime: Add soil sensor lrw encoding
Signed-off-by: Marek Maškarinec <[email protected]>
1 parent 43d3531 commit f734774

File tree

9 files changed

+138
-113
lines changed

9 files changed

+138
-113
lines changed

applications/clime/Kconfig

-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ config SHIELD_CTR_S2
1818

1919
config CTR_HYGRO
2020
default y
21-
# SUBSYSTEM-DS18B20
22-
config SHIELD_CTR_DS18B20
23-
bool "Enable SHIELD_CTR_DS18B20"
24-
default y
25-
26-
config CTR_DS18B20
27-
default y
2821
# SUBSYSTEM-LRW
2922
config SHIELD_CTR_LRW
3023
bool "Enable SHIELD_CTR_LRW"

applications/clime/app.overlay

-62
Original file line numberDiff line numberDiff line change
@@ -50,68 +50,6 @@
5050
};
5151
};
5252
};
53-
/* SUBSYSTEM-DS18B20 */
54-
&ds2484 {
55-
ds18b20_0: ds18b20_0 {
56-
compatible = "maxim,ds18b20";
57-
resolution = <12>;
58-
family-code = <0x28>;
59-
};
60-
61-
ds18b20_1: ds18b20_1 {
62-
compatible = "maxim,ds18b20";
63-
resolution = <12>;
64-
family-code = <0x28>;
65-
};
66-
67-
ds18b20_2: ds18b20_2 {
68-
compatible = "maxim,ds18b20";
69-
resolution = <12>;
70-
family-code = <0x28>;
71-
};
72-
73-
ds18b20_3: ds18b20_3 {
74-
compatible = "maxim,ds18b20";
75-
resolution = <12>;
76-
family-code = <0x28>;
77-
};
78-
79-
ds18b20_4: ds18b20_4 {
80-
compatible = "maxim,ds18b20";
81-
resolution = <12>;
82-
family-code = <0x28>;
83-
};
84-
85-
ds18b20_5: ds18b20_5 {
86-
compatible = "maxim,ds18b20";
87-
resolution = <12>;
88-
family-code = <0x28>;
89-
};
90-
91-
ds18b20_6: ds18b20_6 {
92-
compatible = "maxim,ds18b20";
93-
resolution = <12>;
94-
family-code = <0x28>;
95-
};
96-
97-
ds18b20_7: ds18b20_7 {
98-
compatible = "maxim,ds18b20";
99-
resolution = <12>;
100-
family-code = <0x28>;
101-
};
102-
103-
ds18b20_8: ds18b20_8 {
104-
compatible = "maxim,ds18b20";
105-
resolution = <12>;
106-
family-code = <0x28>;
107-
};
108-
109-
ds18b20_9: ds18b20_9 {
110-
compatible = "maxim,ds18b20";
111-
resolution = <12>;
112-
family-code = <0x28>;
113-
};
114-
};
11553
/* SUBSYSTEM-LRW */
11654
&ctr_lrw_if {
11755
status = "okay";

applications/clime/codec/cs-decoder.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function decodeUplink(input) {
4646
}
4747
}
4848

49-
if ((header & 0x04) !== 0 && (header & 0x08) == 0) {
49+
if ((header & 0x04) !== 0) {
5050
data.therm_temperature = s16();
5151
if (data.therm_temperature === 0x7fff) {
5252
data.therm_temperature = null;
@@ -273,8 +273,14 @@ function s32() {
273273
}
274274

275275
if (false) {
276+
<<<<<<< HEAD
276277
var hex = "af01070eda0d23022e094f096d0d2887c4e46400145c0000";
277278
var buf = Buffer.from(hex, "hex");
278279
console.log(decodeUplink({ bytes: buf }));
280+
=======
281+
var hex = "9703ffffffffff0221094c093f000100000000";
282+
var buf = Buffer.from(hex, "hex");
283+
console.log(JSON.stringify(decodeUplink({ bytes: buf })));
284+
>>>>>>> 46a8f6ff (applications: clime: Add soil sensor lrw encoding)
279285
}
280286

applications/clime/prj.conf

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y
4646
CONFIG_CTR_CONFIG=y
4747
# SUBSYSTEM-DEFAULTS
4848
CONFIG_CTR_DEFAULTS=y
49-
# SUBSYSTEM-DS18B20
50-
CONFIG_CTR_DS18B20=y
5149
# SUBSYSTEM-INFO
5250
CONFIG_CTR_INFO=y
5351
# SUBSYSTEM-LED

applications/clime/project.yaml

+81-40
Original file line numberDiff line numberDiff line change
@@ -44,40 +44,80 @@ variants:
4444
fw_version: v3.0.1
4545
features:
4646
- hardware-chester-sps30
47+
=======
48+
- name: CHESTER Clime
49+
fw_bundle: com.hardwario.chester.app.clime
50+
fw_name: hio-chester-clime
51+
fw_version: v3.0.0
52+
features:
53+
- hardware-chester-s2
54+
- name: CHESTER Clime Z
55+
fw_bundle: com.hardwario.chester.app.clime.z
56+
fw_name: hio-chester-clime-z
57+
fw_version: v3.0.0
58+
features:
59+
- hardware-chester-z
60+
- hardware-chester-s2
61+
remark: Support for CHESTER-Z
62+
- name: CHESTER Clime IAQ
63+
fw_bundle: com.hardwario.chester.app.clime.iaq
64+
fw_name: hio-chester-clime-iaq
65+
fw_version: v3.0.0
66+
features:
67+
- hardware-chester-s1
68+
- hardware-chester-x10
69+
- name: CHESTER Clime RTD
70+
fw_bundle: com.hardwario.chester.app.clime.rtd
71+
fw_name: hio-chester-clime-rtd
72+
fw_version: v3.0.0
73+
features:
74+
- hardware-chester-rtd-a
75+
- name: CHESTER Clime 1W
76+
fw_bundle: com.hardwario.chester.app.clime.1w
77+
fw_name: hio-chester-clime-1w
78+
fw_version: v3.0.0
79+
remark:
80+
- name: CHESTER Clime TC
81+
fw_bundle: com.hardwario.chester.app.clime.tc
82+
fw_name: hio-chester-clime-tc
83+
fw_version: v3.0.0
84+
features:
85+
- hardware-chester-tc-a
86+
>>>>>>> 6ab59302 (Add soil sensor lrw encoding support)
4787
project:
4888
variant: Clime
4989
company: 2024 HARDWARIO a.s.
50-
license: 'SPDX-License-Identifier: LicenseRef-HARDWARIO-5-Clause'
90+
license: "SPDX-License-Identifier: LicenseRef-HARDWARIO-5-Clause"
5191
fw_name: CHESTER Clime
5292
fw_bundle: com.hardwario.chester.app.clime
5393
fw_version: v3.0.0
5494
features:
55-
- subsystem-accel
56-
- subsystem-batt
57-
- subsystem-button
58-
- subsystem-ble
59-
- subsystem-ble-tag
60-
- subsystem-bt-filter-accept-list
61-
- subsystem-bt-observer
62-
- subsystem-buf
63-
- subsystem-cloud
64-
- subsystem-config
65-
- subsystem-defaults
66-
- subsystem-info
67-
- subsystem-led
68-
- subsystem-log
69-
- subsystem-rtc
70-
- subsystem-shell
71-
- subsystem-therm
72-
- subsystem-wdog
73-
- subsystem-tinycrypt
74-
- subsystem-tinycrypt-sha256
75-
- subsystem-zcbor
76-
- subsystem-lte-v2
77-
- subsystem-lrw
78-
- subsystem-ds18b20
79-
- subsystem-soil-sensor
80-
- chester-app-report-jitter
95+
- subsystem-accel
96+
- subsystem-batt
97+
- subsystem-button
98+
- subsystem-ble
99+
- subsystem-ble-tag
100+
- subsystem-bt-filter-accept-list
101+
- subsystem-bt-observer
102+
- subsystem-buf
103+
- subsystem-cloud
104+
- subsystem-config
105+
- subsystem-defaults
106+
- subsystem-info
107+
- subsystem-led
108+
- subsystem-log
109+
- subsystem-rtc
110+
- subsystem-shell
111+
- subsystem-therm
112+
- subsystem-wdog
113+
- subsystem-tinycrypt
114+
- subsystem-tinycrypt-sha256
115+
- subsystem-zcbor
116+
- subsystem-lte-v2
117+
- subsystem-lrw
118+
#- subsystem-ds18b20
119+
- subsystem-soil-sensor
120+
- chester-app-report-jitter
81121
#- chester-app-tamper
82122
#- hardware-chester-s1
83123
#- hardware-chester-s2
@@ -91,6 +131,7 @@ features:
91131
#- hardware-chester-tc-a
92132
#- hardware-chester-tc-b
93133
parameters:
134+
<<<<<<< HEAD
94135
- name: interval-sample
95136
type: int
96137
min: 1
@@ -205,17 +246,17 @@ parameters:
205246
help: 'Get/Set hygro low temperature alarm hysteresis'
206247
depends_on: defined(FEATURE_HARDWARE_CHESTER_S2)
207248
commands:
208-
- name: sample
209-
callback: app_work_sample()
210-
help: 'Sample immediately.'
211-
- name: send
212-
callback: app_work_send()
213-
help: 'Send data immediately.'
214-
- name: aggreg
215-
callback: app_work_aggreg()
216-
help: 'Aggregate data immediately'
249+
- name: sample
250+
callback: app_work_sample()
251+
help: "Sample immediately."
252+
- name: send
253+
callback: app_work_send()
254+
help: "Send data immediately."
255+
- name: aggreg
256+
callback: app_work_aggreg()
257+
help: "Aggregate data immediately"
217258
extras:
218-
- CONFIG_ADC_TLA2021_INIT_PRIORITY=60
219-
- CONFIG_ADC_NRFX_SAADC=n
220-
- CONFIG_ADC_SHELL=n
221-
- CONFIG_NEWLIB_LIBC_NANO=n
259+
- CONFIG_ADC_TLA2021_INIT_PRIORITY=60
260+
- CONFIG_ADC_NRFX_SAADC=n
261+
- CONFIG_ADC_SHELL=n
262+
- CONFIG_NEWLIB_LIBC_NANO=n

applications/clime/src/app_data.h

+2
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ struct app_data_soil_sensor_sensor {
268268
int sample_count;
269269
float samples_temperature[APP_DATA_MAX_SAMPLES];
270270
float samples_moisture[APP_DATA_MAX_SAMPLES];
271+
float last_temperature;
272+
float last_moisture;
271273

272274
int measurement_count;
273275
struct app_data_soil_sensor_measurement measurements[APP_DATA_MAX_MEASUREMENTS];

applications/clime/src/app_send.c

+46
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "app_config.h"
99
#include "app_data.h"
1010
#include "app_send.h"
11+
#include "feature.h"
1112

1213
/* CHESTER includes */
1314
#include <chester/ctr_buf.h>
@@ -85,6 +86,11 @@ static int compose_lrw(struct ctr_buf *buf)
8586
header |= BIT(8);
8687
}
8788

89+
if (IS_ENABLED(FEATURE_SUBSYSTEM_SOIL_SENSOR)) {
90+
header |= BIT(7);
91+
header |= BIT(9);
92+
}
93+
8894
ret |= ctr_buf_append_u8(buf, header);
8995

9096
if (header & BIT(7)) {
@@ -290,6 +296,46 @@ static int compose_lrw(struct ctr_buf *buf)
290296

291297
#endif /* defined(FEATURE_SUBSYSTEM_BLE_TAG) */
292298

299+
#if defined(FEATURE_SUBSYSTEM_SOIL_SENSOR)
300+
if (header & BIT(9)) {
301+
int count = 0;
302+
303+
for (int i = 0; i < APP_DATA_SOIL_SENSOR_COUNT; i++) {
304+
struct app_data_soil_sensor_sensor *sensor =
305+
&g_app_data.soil_sensor.sensor[i];
306+
307+
if (sensor->serial_number == 0) {
308+
continue;
309+
}
310+
311+
count++;
312+
}
313+
314+
ret |= ctr_buf_append_u8(buf, count);
315+
316+
for (int i = 0; i < APP_DATA_SOIL_SENSOR_COUNT; i++) {
317+
struct app_data_soil_sensor_sensor *sensor =
318+
&g_app_data.soil_sensor.sensor[i];
319+
320+
if (sensor->serial_number == 0) {
321+
continue;
322+
}
323+
324+
if (isnan(sensor->last_temperature)) {
325+
ret |= ctr_buf_append_s16_le(buf, BIT_MASK(15));
326+
} else {
327+
ret |= ctr_buf_append_s16_le(buf, sensor->last_temperature * 100.f);
328+
}
329+
330+
if (isnan(sensor->last_moisture)) {
331+
ret |= ctr_buf_append_u16(buf, BIT_MASK(16));
332+
} else {
333+
ret |= ctr_buf_append_u16(buf, sensor->last_moisture);
334+
}
335+
}
336+
}
337+
#endif /* defined(FEATURE_SUBSYSTEM_SOIL_SENSOR) */
338+
293339
app_data_unlock();
294340

295341
if (ret) {

applications/clime/src/app_sensor.c

+2
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,8 @@ int app_sensor_soil_sensor_sample(void)
815815
struct app_data_soil_sensor_sensor *sensor =
816816
&g_app_data.soil_sensor.sensor[i];
817817

818+
sensor->last_temperature = temperature;
819+
sensor->last_moisture = moisture;
818820
sensor->samples_temperature[sensor->sample_count] = temperature;
819821
sensor->samples_moisture[sensor->sample_count] = moisture;
820822
sensor->serial_number = serial_number;

applications/clime/src/feature.h

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#define FEATURE_SUBSYSTEM_CLOUD 1
2121
#define FEATURE_SUBSYSTEM_CONFIG 1
2222
#define FEATURE_SUBSYSTEM_DEFAULTS 1
23-
#define FEATURE_SUBSYSTEM_DS18B20 1
2423
#define FEATURE_SUBSYSTEM_INFO 1
2524
#define FEATURE_SUBSYSTEM_LED 1
2625
#define FEATURE_SUBSYSTEM_LOG 1

0 commit comments

Comments
 (0)