Skip to content

separate to library and application - #101

Merged
mniestroj merged 5 commits into
mainfrom
lib
Oct 30, 2025
Merged

separate to library and application#101
mniestroj merged 5 commits into
mainfrom
lib

Conversation

@mniestroj

Copy link
Copy Markdown
Collaborator

No description provided.

@mniestroj
mniestroj force-pushed the lib branch 2 times, most recently from f40d115 to a985902 Compare October 28, 2025 14:28
@mniestroj
mniestroj marked this pull request as ready for review October 28, 2025 14:28
@mniestroj
mniestroj requested a review from sam-golioth October 28, 2025 14:28
@mniestroj
mniestroj force-pushed the lib branch 3 times, most recently from 01b3145 to c2d105b Compare October 28, 2025 18:18

@sam-golioth sam-golioth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome stuff, @mniestroj! Left a few comments on some organizational/docs stuff

Comment thread Kconfig
Comment on lines +3 to +38

config POUCH_GATEWAY_NUM_BLOCKS
int "Number of blocks in downlink/uplink buffer"
default 10
help
The number of blocks available for buffering uplink or downlink
data between a node device and the cloud. Each block is equal
to CONFIG_GOLIOTH_BLOCKWISE_UPLOAD_MAX_BLOCK_SIZE in length.

config POUCH_GATEWAY_DEVICE_CERT_MAX_LEN
int "Device certificate maximum length"
default 1024
help
Maximum length of device certificate.

config POUCH_GATEWAY_SERVER_CERT_MAX_LEN
int "Server certificate maximum length"
default 4096
help
Maximum length of server certificate.

config POUCH_GATEWAY_DOWNLINK_BLOCK_TIMEOUT
int "Downlink timeout"
default 10
help
The time in seconds that the downlink module will wait for a
block to become available in the buffer. This should be larger
than the duration it takes to send one block to the node device.

config POUCH_GATEWAY_CLOUD
bool "Send pouches to cloud"
default y

config POUCH_GATEWAY_SERVER_CERT_BUILTIN
bool
default y if !POUCH_GATEWAY_CLOUD

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we have these guarded by if POUCH_GATEWAY?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good idea, added such guard.

Comment thread include/pouch_gateway/downlink.h Outdated
Comment on lines +51 to +52
* @param dst_len Length of the destination buffer.
* @param is_last true if this is the last chunk.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should denote that dst_len is in/out and is_last is out

Suggested change
* @param dst_len Length of the destination buffer.
* @param is_last true if this is the last chunk.
* @param dst_len[in,out] Length of the destination buffer. Set to the number of bytes written.
* @param is_last[out] Set to true if this is the last chunk.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added those changes.

Comment on lines +6 to +20
config POUCH_GATEWAY_CLOUD
bool "Send pouches to cloud"
default y
help
Disabling cloud communication allows to test Bluetooth gateway
functionality without relying on communication with backend. All
pouches received from Bluetooth nodes are dropped in that case.

config GOLIOTH_COAP_HOST_URI
string "CoAP server URI"
default "coaps://coap.golioth.io"
help
The URI of the CoAP server.

endmenu

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Aren't these options provided by the Gateway lib and the Golioth Firmware SDK?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

GOLIOTH_COAP_HOST_URI is provided by Golioth SDK. Here we move that to sysbuild context, so it can be set by SB_CONFIG_GOLIOTH_COAP_HOST_URI option when using using sysbuild (e.g. west build ... --sysbuild). By having that on sysbuild level, we can adjust all components in sysbuild, which in case of nrf52_bsim are both "bluetooth gateway" as well "pouch peripheral". I case of "bluetooth gateway" we just pass that option to Golioth SDK as is, while in case of "pouch peripheral" we switch to "pouch.golioth.dev" (instead of "pouch.golioth.io") when using "coap.golioth.dev" for CoAP: See https://github.com/golioth/bluetooth-gateway/blob/0a9ce0eee28cc69a750ef7a0e9d7182ff99d6d41/gateway/sysbuild.cmake#L52-L55

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add a README that describes the custom sync and scan logic in this app

#pragma once

/**
* Start Bluetooth scanning for devices.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's describe what criteria this uses to select devices (i.e. the Pouch Service UUID).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added more documentation with select criteria. Please check that is fine now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

Some heaer files were missing it.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
This allows to reuse core gateway functionality and easily build custom
logic around it. Additionally this makes it easy to embed into 3rd party
applications, where gateway will be just one of the implemented roles.

Move parts of (previous) connect.c functionality to application layer,
especially connect/disconnect handlers. Provide APIs:

  * pouch_gateway_scan_start()
  * pouch_gateway_scan_stop()

that allow to pass control of the Bluetooth connection to the library and
then cleanup library resources after being done.

When library is done with BT communication, application specific
pouch_gateway_bt_finished() is called. Library does not disconnect on
error, but instead call pouch_gateway_bt_finished() as well.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
This sample provides following custom functionality:

 * BT scanning is handled by application, with additional
   filters (Bluetooth device name and RSSI)
 * sync pouch 2x during each BT connection with 5s delay between syncs;
   this simulates other BT communication that might happen in application
   code

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
@mniestroj
mniestroj merged commit 4597181 into main Oct 30, 2025
10 checks passed
@mniestroj
mniestroj deleted the lib branch October 30, 2025 19:28
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.

2 participants