Skip to content

Commit 5cb168c

Browse files
committed
Merge upstream reference-design-template
Signed-off-by: Marko Puric <marko@golioth.io>
2 parents 42d2a13 + 7e05fd2 commit 5cb168c

File tree

22 files changed

+778
-743
lines changed

22 files changed

+778
-743
lines changed

.github/workflows/build_zephyr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
6161
- name: Build with West
6262
run: |
63-
west build -p -b ${{ inputs.BOARD }} app -- -DCONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION=\"0.0.0\"
63+
west build -p -b ${{ inputs.BOARD }} app
6464
6565
- name: Prepare artifacts
6666
if: inputs.ARTIFACT == true && inputs.TAG != ''

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- Added support for Adafruit Feather nRF52840 Express board
1616
- Based on the [Reference Design Template](https://github.com/golioth/reference-design-template)
1717
- Added a CHANGELOG.md to track changes moving forward.
18+

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ target_sources(app PRIVATE src/main.c)
1111
target_sources(app PRIVATE src/app_rpc.c)
1212
target_sources(app PRIVATE src/app_settings.c)
1313
target_sources(app PRIVATE src/app_state.c)
14-
target_sources(app PRIVATE src/app_work.c)
15-
target_sources(app PRIVATE src/dfu/app_dfu.c)
16-
target_sources_ifdef(CONFIG_BOOTLOADER_MCUBOOT app PRIVATE src/dfu/flash.c)
14+
target_sources(app PRIVATE src/app_sensors.c)
15+
16+
add_subdirectory_ifdef(CONFIG_ALUDEL_BATTERY_MONITOR src/battery_monitor)

README.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,26 @@ This firmware can be built for a variety of supported hardware platforms.
4444
:width: 240
4545
- ``nrf52840dk_nrf52840``
4646

47+
<<<<<<< HEAD
4748
.. list-table:: **Adafruit Hardware**
4849
:header-rows: 1
50+
=======
51+
Prior to building, update ``CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION`` in the ``prj.conf`` file to
52+
reflect the firmware version number you want to assign to this build. Then run the following
53+
commands to build and program the firmware onto the device.
54+
>>>>>>> upstream/main
4955

5056
* - Development Board
5157
- Zephyr Board
5258

59+
<<<<<<< HEAD
5360
* - .. image:: images/Adafurit_nRF52840_Feather.png
5461
:width: 240
5562
- ``adafruit_feather_nrf52840``
63+
=======
64+
$ (.venv) west build -p -b aludel_mini_v1_sparkfun9160_ns app
65+
$ (.venv) west flash
66+
>>>>>>> upstream/main
5667

5768

5869
Firmware Overview
@@ -182,6 +193,7 @@ Install ``west`` meta-tool
182193

183194
.. code-block:: shell
184195
196+
<<<<<<< HEAD
185197
pip install wheel west
186198

187199
Use ``west`` to initialize the workspace and install dependencies
@@ -232,6 +244,15 @@ Flash the firmware
232244

233245
.. code-block:: text
234246
247+
=======
248+
Prior to building, update ``CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION`` in the ``prj.conf`` file to
249+
reflect the firmware version number you want to assign to this build. Then run the following
250+
commands to build and program the firmware onto the device.
251+
252+
.. code-block:: text
253+
254+
$ (.venv) west build -p -b nrf9160dk_nrf9160_ns app
255+
>>>>>>> upstream/main
235256
$ (.venv) west flash
236257

237258
Provision the device

prj.conf

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
11
# Copyright (c) 2022-2023 Golioth, Inc.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
CONFIG_GOLIOTH_SAMPLES_COMMON=y
4+
# Enable Golioth Firmware SDK
5+
CONFIG_GOLIOTH_FIRMWARE_SDK=y
56

6-
# Application
7+
# Golioth services used in this app
8+
CONFIG_GOLIOTH_FW_UPDATE=y
9+
CONFIG_GOLIOTH_LIGHTDB_STATE=y
710
CONFIG_LOG_BACKEND_GOLIOTH=y
8-
CONFIG_MAIN_STACK_SIZE=4096
11+
CONFIG_GOLIOTH_RPC=y
12+
CONFIG_GOLIOTH_SETTINGS=y
13+
CONFIG_GOLIOTH_STREAM=y
14+
15+
# Enable common sample library
16+
CONFIG_GOLIOTH_SAMPLE_COMMON=y
917

10-
CONFIG_GOLIOTH_FW=y
18+
# Configure Golioth SDK dependencies
19+
CONFIG_EVENTFD_MAX=14
20+
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=1536
21+
CONFIG_MBEDTLS_ENABLE_HEAP=y
22+
CONFIG_MBEDTLS_HEAP_SIZE=10240
23+
CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=2048
24+
CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=2048
25+
CONFIG_NETWORKING=y
26+
CONFIG_NET_IPV4=y
27+
CONFIG_POSIX_MAX_FDS=23
1128

29+
# Application
30+
CONFIG_MAIN_STACK_SIZE=2048
31+
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
32+
CONFIG_NET_LOG=y
33+
CONFIG_NET_SHELL=y
34+
CONFIG_REBOOT=y
35+
36+
# Flash memory (etc.) for firmware upgrade
1237
CONFIG_FLASH=y
1338
CONFIG_FLASH_MAP=y
1439
CONFIG_NVS=y
@@ -17,25 +42,28 @@ CONFIG_IMG_MANAGER=y
1742
CONFIG_IMG_ERASE_PROGRESSIVELY=y
1843
CONFIG_REBOOT=y
1944

20-
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
21-
22-
CONFIG_JSON_LIBRARY=y
23-
45+
# The rest of the runtime credentials config
2446
CONFIG_SETTINGS=y
25-
CONFIG_GOLIOTH_SETTINGS=y
2647
CONFIG_SETTINGS_RUNTIME=y
2748
CONFIG_GOLIOTH_SAMPLE_PSK_SETTINGS=y
2849
CONFIG_GOLIOTH_SAMPLE_SETTINGS_AUTOLOAD=y
2950
CONFIG_GOLIOTH_SAMPLE_SETTINGS_SHELL=y
3051

31-
CONFIG_GOLIOTH_RPC=y
32-
CONFIG_I2C=y
52+
# Misc.
53+
CONFIG_JSON_LIBRARY=y
54+
CONFIG_NETWORK_INFO=y
55+
# Longer response length needed for network info
56+
CONFIG_GOLIOTH_RPC_MAX_RESPONSE_LEN=512
3357

3458
# Generate MCUboot compatible images
3559
CONFIG_BOOTLOADER_MCUBOOT=y
3660

61+
# Firmware version used in DFU process
62+
CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION="2.1.0"
63+
3764
# IMPORTANT: Change the Thread network credentials to match your Thread network setup
3865
CONFIG_OPENTHREAD_NORDIC_LIBRARY_MASTER=y
3966
CONFIG_OPENTHREAD_CHANNEL=26
4067
CONFIG_OPENTHREAD_NETWORKKEY="00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff"
4168
CONFIG_OPENTHREAD_NETWORK_NAME="OpenThreadDemo"
69+

src/app_rpc.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
#include <zephyr/logging/log_ctrl.h>
99
LOG_MODULE_REGISTER(app_rpc, LOG_LEVEL_DBG);
1010

11-
#include <net/golioth/system_client.h>
12-
#include <net/golioth/rpc.h>
11+
#include <golioth/client.h>
12+
#include <golioth/rpc.h>
1313
#include <zephyr/logging/log_ctrl.h>
1414
#include <zephyr/sys/reboot.h>
1515

1616
#include "app_rpc.h"
1717

18-
static struct golioth_client *client;
19-
2018
static void reboot_work_handler(struct k_work *work)
2119
{
2220
for (int8_t i = 5; i >= 0; i--) {
@@ -95,31 +93,15 @@ static void rpc_log_if_register_failure(int err)
9593
}
9694
}
9795

98-
int app_rpc_init(struct golioth_client *state_client)
96+
void app_rpc_register(struct golioth_client *client)
9997
{
100-
client = state_client;
101-
int err = app_rpc_register(client);
102-
return err;
103-
}
98+
struct golioth_rpc *rpc = golioth_rpc_init(client);
10499

105-
int app_rpc_observe(void)
106-
{
107-
int err = golioth_rpc_observe(client);
108-
if (err) {
109-
LOG_ERR("Failed to observe RPC: %d", err);
110-
}
111-
return err;
112-
}
113-
114-
int app_rpc_register(struct golioth_client *rpc_client)
115-
{
116100
int err;
117101

118-
err = golioth_rpc_register(rpc_client, "reboot", on_reboot, NULL);
102+
err = golioth_rpc_register(rpc, "reboot", on_reboot, NULL);
119103
rpc_log_if_register_failure(err);
120104

121-
err = golioth_rpc_register(rpc_client, "set_log_level", on_set_log_level, NULL);
105+
err = golioth_rpc_register(rpc, "set_log_level", on_set_log_level, NULL);
122106
rpc_log_if_register_failure(err);
123-
124-
return err;
125107
}

src/app_rpc.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
#ifndef __APP_RPC_H__
2121
#define __APP_RPC_H__
2222

23-
#include <net/golioth/system_client.h>
23+
#include <golioth/client.h>
2424

25-
int app_rpc_init(struct golioth_client *state_client);
26-
int app_rpc_observe(void);
27-
int app_rpc_register(struct golioth_client *rpc_client);
25+
void app_rpc_register(struct golioth_client *client);
2826

2927
#endif /* __APP_RPC_H__ */

src/app_work.c renamed to src/app_sensors.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
*/
66

77
#include <zephyr/logging/log.h>
8-
LOG_MODULE_REGISTER(app_work, LOG_LEVEL_DBG);
8+
LOG_MODULE_REGISTER(app_sensors, LOG_LEVEL_DBG);
99

10-
#include <net/golioth/system_client.h>
10+
#include <golioth/client.h>
11+
#include <golioth/stream.h>
1112
#include <zephyr/drivers/gpio.h>
13+
#include <zephyr/kernel.h>
1214

13-
#include "app_work.h"
15+
#include "app_sensors.h"
1416

1517
static struct golioth_client *client;
1618
/* Add Sensor structs here */
@@ -19,47 +21,47 @@ static struct golioth_client *client;
1921
#define JSON_FMT "{\"counter\":%d}"
2022

2123
/* Callback for LightDB Stream */
22-
static int async_error_handler(struct golioth_req_rsp *rsp)
24+
25+
static void async_error_handler(struct golioth_client *client,
26+
const struct golioth_response *response,
27+
const char *path,
28+
void *arg)
2329
{
24-
if (rsp->err) {
25-
LOG_ERR("Async task failed: %d", rsp->err);
26-
return rsp->err;
30+
if (response->status != GOLIOTH_OK) {
31+
LOG_ERR("Async task failed: %d", response->status);
32+
return;
2733
}
28-
return 0;
2934
}
3035

3136
/* This will be called by the main() loop */
3237
/* Do all of your work here! */
33-
void app_work_sensor_read(void)
38+
void app_sensors_read_and_stream(void)
3439
{
3540
int err;
3641
char json_buf[256];
3742

38-
/* For this demo, we just send Hello to Golioth */
3943
static uint8_t counter;
4044

41-
LOG_INF("Sending hello! %d", counter);
42-
43-
err = golioth_send_hello(client);
44-
if (err) {
45-
LOG_WRN("Failed to send hello!");
46-
}
47-
4845
/* Send sensor data to Golioth */
4946
/* For this demo we just fake it */
5047
snprintk(json_buf, sizeof(json_buf), JSON_FMT, counter);
5148
LOG_DBG("%s", json_buf);
5249

53-
err = golioth_stream_push_cb(client, "sensor", GOLIOTH_CONTENT_FORMAT_APP_JSON, json_buf,
54-
strlen(json_buf), async_error_handler, NULL);
50+
err = golioth_stream_set_async(client,
51+
"sensor",
52+
GOLIOTH_CONTENT_TYPE_JSON,
53+
json_buf,
54+
strlen(json_buf),
55+
async_error_handler,
56+
NULL);
5557
if (err) {
5658
LOG_ERR("Failed to send sensor data to Golioth: %d", err);
5759
}
5860

5961
++counter;
6062
}
6163

62-
void app_work_init(struct golioth_client *work_client)
64+
void app_sensors_set_client(struct golioth_client *sensors_client)
6365
{
64-
client = work_client;
66+
client = sensors_client;
6567
}

src/app_sensors.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2022-2023 Golioth, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef __APP_SENSORS_H__
8+
#define __APP_SENSORS_H__
9+
10+
/** The `app_sensors.c` file performs the important work of this application
11+
* which is to read sensor values and report them to the Golioth LightDB Stream
12+
* as time-series data.
13+
*
14+
* For this demonstration, a `counter` value is periodically logged and pushed
15+
* to the Golioth time-series database. This simulated sensor reading occurs
16+
* when the loop in `main.c` calls `app_sensors_read_and_stream()`. The
17+
* frequency of this loop is determined by values received from the Golioth
18+
* Settings Service (see app_settings.h).
19+
*
20+
* https://docs.golioth.io/firmware/zephyr-device-sdk/light-db-stream/
21+
*/
22+
23+
#include <golioth/client.h>
24+
25+
void app_sensors_set_client(struct golioth_client *sensors_client);
26+
void app_sensors_read_and_stream(void);
27+
28+
#endif /* __APP_SENSORS_H__ */

0 commit comments

Comments
 (0)