Skip to content

Commit

Permalink
applications: meteo: Improve pyranometer
Browse files Browse the repository at this point in the history
  • Loading branch information
hubpav authored and hubmartin committed Dec 5, 2024
1 parent d621e04 commit 8f26f0f
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 46 deletions.
2 changes: 1 addition & 1 deletion applications/meteo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
cmake_minimum_required(VERSION 3.20.0)

set(ENV{FW_BUNDLE} "com.hardwario.chester.app.meteo")
set(ENV{FW_VERSION} "v3.0.0")
set(ENV{FW_VERSION} "v3.0.2")
set(ENV{FW_NAME} "CHESTER Meteo")

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
Expand Down
2 changes: 1 addition & 1 deletion applications/meteo/VERSION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_MAJOR = 3
VERSION_MINOR = 0
PATCHLEVEL = 0
PATCHLEVEL = 2
VERSION_TWEAK = 0
EXTRAVERSION = dev
27 changes: 17 additions & 10 deletions applications/meteo/codec/cbor-decoder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ schema:
- serial_number:
- network:
- parameter:
- eest:
- ecl:
- rsrp:
- rsrq:
- snr:
- plmn:
- cid:
- band:
- earfcn:
- eest:
- ecl:
- rsrp:
- rsrq:
- snr:
- plmn:
- cid:
- band:
- earfcn:
- thermometer:
- temperature:
- $div: 100
Expand Down Expand Up @@ -280,7 +280,14 @@ schema:
- $div: 100
- $fpp: 2
- pyranometer:
- irradiance:
- irradiance_1:
- measurements:
- $tsp:
- min:
- max:
- avg:
- mdn:
- irradiance_2:
- measurements:
- $tsp:
- min:
Expand Down
2 changes: 1 addition & 1 deletion applications/meteo/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ CONFIG_ZCBOR_STOP_ON_ERROR=y
CONFIG_ADC_TLA2021_INIT_PRIORITY=60

# ### Preserved code "config" (begin)
CONFIG_APP_PYRANOMETER=n
CONFIG_CTR_GPIO=y
# ^^^ Preserved code "config" (end)
15 changes: 10 additions & 5 deletions applications/meteo/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@ variants:
- name: CHESTER Meteo
fw_bundle: com.hardwario.chester.app.meteo
fw_name: hio-chester-meteo
fw_version: v3.0.0
fw_version: v3.0.2
- name: CHESTER Meteo Z
fw_bundle: com.hardwario.chester.app.meteo.z
fw_name: hio-chester-meteo-z
fw_version: v3.0.0
fw_version: v3.0.2
features:
- hardware-chester-z
remark: Support for CHESTER-Z
- name: CHESTER Meteo P
fw_bundle: com.hardwario.chester.app.meteo.p
fw_name: hio-chester-meteo-p
fw_version: v3.0.2
extras:
- CONFIG_APP_PYRANOMETER=y
remark: Support for pyranometer
project:
variant: Meteo
company: 2024 HARDWARIO a.s.
license: "SPDX-License-Identifier: LicenseRef-HARDWARIO-5-Clause"
fw_name: CHESTER Meteo
fw_bundle: com.hardwario.chester.app.meteo
fw_version: v3.0.0
fw_version: v3.0.2
features:
- subsystem-accel
- subsystem-batt
Expand Down Expand Up @@ -154,5 +161,3 @@ commands:
help: "Aggregate data immediately"
extras:
- CONFIG_ADC_TLA2021_INIT_PRIORITY=60


30 changes: 25 additions & 5 deletions applications/meteo/src/app_cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1098,21 +1098,41 @@ static int encode(zcbor_state_t *zs)
{
zcbor_map_start_encode(zs, ZCBOR_VALUE_IS_INDEFINITE_LENGTH);

zcbor_uint32_put(zs, CODEC_KEY_E_PYRANOMETER__IRRADIANCE);
zcbor_uint32_put(zs, CODEC_KEY_E_PYRANOMETER__IRRADIANCE_1);
{
zcbor_map_start_encode(zs, ZCBOR_VALUE_IS_INDEFINITE_LENGTH);

zcbor_uint32_put(zs, CODEC_KEY_E_PYRANOMETER__IRRADIANCE__MEASUREMENTS);
zcbor_uint32_put(zs, CODEC_KEY_E_PYRANOMETER__IRRADIANCE_1__MEASUREMENTS);
{
zcbor_list_start_encode(zs, ZCBOR_VALUE_IS_INDEFINITE_LENGTH);

zcbor_uint64_put(zs, g_app_data.pyranometer.timestamp);
zcbor_uint32_put(zs, g_app_config.interval_aggreg);

for (int i = 0; i < g_app_data.pyranometer.measurement_count; i++) {
put_sample(
zs,
&g_app_data.pyranometer.irradiance_measurements[i]);
put_sample(zs, &g_app_data.pyranometer
.irradiance_1_measurements[i]);
}

zcbor_list_end_encode(zs, ZCBOR_VALUE_IS_INDEFINITE_LENGTH);
}
zcbor_map_end_encode(zs, ZCBOR_VALUE_IS_INDEFINITE_LENGTH);
}

zcbor_uint32_put(zs, CODEC_KEY_E_PYRANOMETER__IRRADIANCE_2);
{
zcbor_map_start_encode(zs, ZCBOR_VALUE_IS_INDEFINITE_LENGTH);

zcbor_uint32_put(zs, CODEC_KEY_E_PYRANOMETER__IRRADIANCE_2__MEASUREMENTS);
{
zcbor_list_start_encode(zs, ZCBOR_VALUE_IS_INDEFINITE_LENGTH);

zcbor_uint64_put(zs, g_app_data.pyranometer.timestamp);
zcbor_uint32_put(zs, g_app_config.interval_aggreg);

for (int i = 0; i < g_app_data.pyranometer.measurement_count; i++) {
put_sample(zs, &g_app_data.pyranometer
.irradiance_2_measurements[i]);
}

zcbor_list_end_encode(zs, ZCBOR_VALUE_IS_INDEFINITE_LENGTH);
Expand Down
34 changes: 22 additions & 12 deletions applications/meteo/src/app_codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
extern "C" {
#endif

#define CODEC_CLOUD_DECODER_HASH ((uint64_t)0xe8aec82e4ae372cc)
#define CODEC_CLOUD_DECODER_HASH ((uint64_t)0x98e8eecd3459fb81)
#define CODEC_CLOUD_ENCODER_HASH ((uint64_t)0x0000000000000000)

enum codec_key_e {
Expand Down Expand Up @@ -107,8 +107,10 @@ enum codec_key_e {
CODEC_KEY_E_LAMBRECHT_WEATHER_STATION__ILLUMINANCE = 93,
CODEC_KEY_E_LAMBRECHT_WEATHER_STATION__ILLUMINANCE__MEASUREMENTS = 94,
CODEC_KEY_E_PYRANOMETER = 95,
CODEC_KEY_E_PYRANOMETER__IRRADIANCE = 96,
CODEC_KEY_E_PYRANOMETER__IRRADIANCE__MEASUREMENTS = 97,
CODEC_KEY_E_PYRANOMETER__IRRADIANCE_1 = 96,
CODEC_KEY_E_PYRANOMETER__IRRADIANCE_1__MEASUREMENTS = 97,
CODEC_KEY_E_PYRANOMETER__IRRADIANCE_2 = 98,
CODEC_KEY_E_PYRANOMETER__IRRADIANCE_2__MEASUREMENTS = 99,
};

#define CODEC_CLOUD_OPTIONS_STATIC(_name) \
Expand All @@ -117,7 +119,7 @@ enum codec_key_e {
.decoder_hash = CODEC_CLOUD_DECODER_HASH, \
.encoder_hash = CODEC_CLOUD_ENCODER_HASH, \
.decoder_buf = _name##_cloud_decoder, \
.decoder_len = 2765, \
.decoder_len = 2828, \
.encoder_buf = NULL, \
.encoder_len = 0, \
}
Expand Down Expand Up @@ -461,14 +463,22 @@ enum codec_key_e {
0x64, 0x69, 0x76, 0x18, 0x64, 0xa1, 0x64, 0x24, \
0x66, 0x70, 0x70, 0x02, 0xa1, 0x6b, 0x70, 0x79, \
0x72, 0x61, 0x6e, 0x6f, 0x6d, 0x65, 0x74, 0x65, \
0x72, 0x81, 0xa1, 0x6a, 0x69, 0x72, 0x72, 0x61, \
0x64, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x81, 0xa1, \
0x6c, 0x6d, 0x65, 0x61, 0x73, 0x75, 0x72, 0x65, \
0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81, 0xa1, 0x64, \
0x24, 0x74, 0x73, 0x70, 0x84, 0xa1, 0x63, 0x6d, \
0x69, 0x6e, 0xf6, 0xa1, 0x63, 0x6d, 0x61, 0x78, \
0xf6, 0xa1, 0x63, 0x61, 0x76, 0x67, 0xf6, 0xa1, \
0x63, 0x6d, 0x64, 0x6e, 0xf6, \
0x72, 0x82, 0xa1, 0x6c, 0x69, 0x72, 0x72, 0x61, \
0x64, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x5f, 0x31, \
0x81, 0xa1, 0x6c, 0x6d, 0x65, 0x61, 0x73, 0x75, \
0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81, \
0xa1, 0x64, 0x24, 0x74, 0x73, 0x70, 0x84, 0xa1, \
0x63, 0x6d, 0x69, 0x6e, 0xf6, 0xa1, 0x63, 0x6d, \
0x61, 0x78, 0xf6, 0xa1, 0x63, 0x61, 0x76, 0x67, \
0xf6, 0xa1, 0x63, 0x6d, 0x64, 0x6e, 0xf6, 0xa1, \
0x6c, 0x69, 0x72, 0x72, 0x61, 0x64, 0x69, 0x61, \
0x6e, 0x63, 0x65, 0x5f, 0x32, 0x81, 0xa1, 0x6c, \
0x6d, 0x65, 0x61, 0x73, 0x75, 0x72, 0x65, 0x6d, \
0x65, 0x6e, 0x74, 0x73, 0x81, 0xa1, 0x64, 0x24, \
0x74, 0x73, 0x70, 0x84, 0xa1, 0x63, 0x6d, 0x69, \
0x6e, 0xf6, 0xa1, 0x63, 0x6d, 0x61, 0x78, 0xf6, \
0xa1, 0x63, 0x61, 0x76, 0x67, 0xf6, 0xa1, 0x63, \
0x6d, 0x64, 0x6e, 0xf6, \
}

#ifdef __cplusplus
Expand Down
7 changes: 5 additions & 2 deletions applications/meteo/src/app_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,11 @@ struct app_data_pyranometer {
int sample_count;
int measurement_count;

float irradiance_samples[APP_DATA_MAX_SAMPLES];
struct app_data_aggreg irradiance_measurements[APP_DATA_MAX_MEASUREMENTS];
float irradiance_1_samples[APP_DATA_MAX_SAMPLES];
struct app_data_aggreg irradiance_1_measurements[APP_DATA_MAX_MEASUREMENTS];

float irradiance_2_samples[APP_DATA_MAX_SAMPLES];
struct app_data_aggreg irradiance_2_measurements[APP_DATA_MAX_MEASUREMENTS];

int64_t timestamp;
};
Expand Down
15 changes: 14 additions & 1 deletion applications/meteo/src/app_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <chester/ctr_button.h>
#include <chester/ctr_ds18b20.h>
#include <chester/ctr_edge.h>
#include <chester/ctr_gpio.h>
#include <chester/ctr_led.h>
#include <chester/ctr_cloud.h>
#include <chester/ctr_soil_sensor.h>
Expand Down Expand Up @@ -168,9 +169,21 @@ int app_init(void)
#endif /* defined(FEATURE_CHESTER_APP_LAMBRECHT) */

#if defined(CONFIG_APP_PYRANOMETER)
ret = ctr_gpio_set_mode(CTR_GPIO_CHANNEL_B3, CTR_GPIO_MODE_OUTPUT);
if (ret) {
LOG_ERR("Call `ctr_gpio_set_mode` failed: %d", ret);
return ret;
}

ret = ctr_adc_init(CTR_ADC_CHANNEL_B0);
if (ret) {
LOG_ERR("Call `ctr_adc_init` failed: %d", ret);
LOG_ERR("Call `ctr_adc_init` failed (0): %d", ret);
return ret;
}

ret = ctr_adc_init(CTR_ADC_CHANNEL_B1);
if (ret) {
LOG_ERR("Call `ctr_adc_init` failed (1): %d", ret);
return ret;
}
#endif /* defined(CONFIG_APP_PYRANOMETER) */
Expand Down
51 changes: 43 additions & 8 deletions applications/meteo/src/app_sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <chester/ctr_adc.h>
#include <chester/ctr_ble_tag.h>
#include <chester/ctr_ds18b20.h>
#include <chester/ctr_gpio.h>
#include <chester/ctr_hygro.h>
#include <chester/ctr_rtc.h>
#include <chester/ctr_soil_sensor.h>
Expand Down Expand Up @@ -1432,33 +1433,63 @@ int app_sensor_pyranometer_sample(void)
{
int ret;

ret = ctr_gpio_write(CTR_GPIO_CHANNEL_B3, 1);
if (ret) {
LOG_ERR("Call `ctr_gpio_write` failed: %d", ret);
return ret;
}

k_sleep(K_MSEC(100));

struct app_data_pyranometer *pyranometer = &g_app_data.pyranometer;

app_data_lock();

if (pyranometer->sample_count >= APP_DATA_MAX_SAMPLES) {
LOG_WRN("Sample buffer full");
app_data_unlock();
ctr_gpio_write(CTR_GPIO_CHANNEL_B3, 0);
return -ENOSPC;
}

uint16_t sample;
ret = ctr_adc_read(CTR_ADC_CHANNEL_B0, &sample);
uint16_t sample_1;
ret = ctr_adc_read(CTR_ADC_CHANNEL_B0, &sample_1);
if (ret) {
LOG_ERR("Call `ctr_adc_read` failed (1): %d", ret);
app_data_unlock();
ctr_gpio_write(CTR_GPIO_CHANNEL_B3, 0);
return ret;
}

pyranometer->irradiance_1_samples[pyranometer->sample_count] = CTR_ADC_MILLIVOLTS(sample_1);

LOG_INF("Irradiance 1 response: %.0f mV",
pyranometer->irradiance_1_samples[pyranometer->sample_count]);

uint16_t sample_2;
ret = ctr_adc_read(CTR_ADC_CHANNEL_B1, &sample_2);
if (ret) {
LOG_ERR("Call `ctr_adc_read` failed: %d", ret);
LOG_ERR("Call `ctr_adc_read` failed (2): %d", ret);
app_data_unlock();
ctr_gpio_write(CTR_GPIO_CHANNEL_B3, 0);
return ret;
}

pyranometer->irradiance_samples[pyranometer->sample_count] = CTR_ADC_MILLIVOLTS(sample);
pyranometer->irradiance_2_samples[pyranometer->sample_count] = CTR_ADC_MILLIVOLTS(sample_2);

LOG_INF("Irradiance response: %.0f mV",
pyranometer->irradiance_samples[pyranometer->sample_count]);
LOG_INF("Irradiance 2 response: %.0f mV",
pyranometer->irradiance_2_samples[pyranometer->sample_count]);

pyranometer->sample_count++;

app_data_unlock();

ret = ctr_gpio_write(CTR_GPIO_CHANNEL_B3, 0);
if (ret) {
LOG_ERR("Call `ctr_gpio_write` failed: %d", ret);
return ret;
}

return 0;
}

Expand All @@ -1479,8 +1510,12 @@ int app_sensor_pyranometer_aggreg(void)
}

aggreg_sample(
pyranometer->irradiance_samples, pyranometer->sample_count,
&pyranometer->irradiance_measurements[pyranometer->measurement_count]);
pyranometer->irradiance_1_samples, pyranometer->sample_count,
&pyranometer->irradiance_1_measurements[pyranometer->measurement_count]);

aggreg_sample(
pyranometer->irradiance_2_samples, pyranometer->sample_count,
&pyranometer->irradiance_2_measurements[pyranometer->measurement_count]);

pyranometer->sample_count = 0;
pyranometer->measurement_count++;
Expand Down

0 comments on commit 8f26f0f

Please sign in to comment.