-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WiFi location service with sample #708
Conversation
Visit the preview URL for this PR (updated for commit a0996d7): https://golioth-firmware-sdk-doxygen-dev--pr708-location-wifi-mz17ai5t.web.app (expires Fri, 17 Jan 2025 15:22:17 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: a9993e61697a3983f3479e468bcb0b616f9a0578 |
ff80383
to
623ec88
Compare
Codecov ReportAttention: Patch coverage is
|
83f680a
to
1abbd41
Compare
@@ -261,6 +261,34 @@ static enum golioth_status golioth_coap_client_set_internal(struct golioth_clien | |||
return GOLIOTH_OK; | |||
} | |||
|
|||
enum golioth_status golioth_coap_client_post(struct golioth_client *client, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have anywhere else that we use _post
in the user API? I ask because this is a departure from the _set
and _set_block
API naming we currently have. I wonder if _set_payload
or something along those lines would be a good fit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... I was thinking about that myself and considered set_payload
/ set_with_response
/ set_with_rsp
, etc.
- My first implementation was about extending
set
with payload (and payload_size) arguments. This seemed to be obvious choice for internals of our SDK and was the cleanest path forward, without introducing new API (like _post). This turned out to be very verbose for public API that SDK users consume. So... decided to leave those APIs without payload. - Next approach was to implement either
_set()
equivalent with_set_with_rsp()
to describe that payload is provided in that case. That however was very loosely related to our existing_set()
APIs, likelightdb_*_set()
. Then I was thinking about whether_set_*()
is a good choice for API that sends and receives something. More natural is the_post()
nomenclature, which is very well known in case of HTTP, CoAP and in general in the world of RESTful APIs. - Decided to go with
_post()
API, since that maps very good to internal CoAP implementation without introducing new nomenclature. It does what POST method does technically... so it sends data and receives data. It is definitely more than set word describes.
So if we are about changing the (internal) APIs, my bet would be to use _post()
in most places and just expose _set()
for high-level APIs, like lightdb, where it makes sense. Even for stream service which just sends data now... I think it makes more sense to use golioth_stream__push()
or golioth_stream__post()
instead of golioth_stream__set()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also like using _post
because it more closely matches our use of _get
and _delete
elsewhere. I don't love the idea of us now exposing a set_cb
and a post_cb
as part of the public API though. The post_cb
looks very similar to the get_cb
(identical?) and the set_cb
is currently used for POST and DELETE operations. I wonder if moving to something more like "callback with response" and "callback without response" would make more sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good discussion! Here are my thoughts:
- I like the idea of using
_post()
for the internal API. The use ofset()
here always felt a little odd here, since we are doing POST operations and the other APIs also use the CoAP REST operation names (GET, OBSERVE, DELETE, etc.). We can keepset()
for the higher level APIs that don't return a payload like LightDB State and Stream. This change would be out of scope for this PR. - For this PR, I think adding the new API works fine.
- I agree with Dan that we have a lot of overlap in the callbacks. I'm working on a change to proxy the callbacks through the upper half client as part of my hackday / holiday hours project. For that change, I'm using one catch-all callback between the lower and upper-half clients. We could do something similar for user callbacks (i.e. use one callback and set the payload to NULL if it is irrelevant for the operation). Or we could rename the callbacks as Dan suggested. Another idea is proxying all callbacks through the higher level services and then using service-specific callbacks. I think that will be easier for users, but it does add a lot of indirection to the callbacks (lower client => upper client => service => user code).
.content_type = content_type, | ||
.callback_post = callback, | ||
.arg = callback_arg, | ||
.callback_is_post = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps not relevant to this PR, but this callback_is_post
member makes me think of the is_observe
member we have in some other params structs. Perhaps these could be unified in a type
member that all params structs have with an enum that specifies is_post, is_observe, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I would 100% agree if we would have them in the same structure. Do you think it makes sense to introduce type now even if we have 2 types at most for each struct?
Even if we would switch to types, then I think that observe
and post
should be defined in separate enum, i.e. separate namespace. They are just different things, so I would prefer to not put them in single location to prevent confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right about keeping namespaces separate. This is something to think about in future work but I don't think we should make any changes yet.
1abbd41
to
3732f21
Compare
3732f21
to
b300e5f
Compare
3d255a2
to
b95f216
Compare
b95f216
to
ad5601c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @mniestroj! Left a few comments below.
@@ -261,6 +261,34 @@ static enum golioth_status golioth_coap_client_set_internal(struct golioth_clien | |||
return GOLIOTH_OK; | |||
} | |||
|
|||
enum golioth_status golioth_coap_client_post(struct golioth_client *client, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also like using _post
because it more closely matches our use of _get
and _delete
elsewhere. I don't love the idea of us now exposing a set_cb
and a post_cb
as part of the public API though. The post_cb
looks very similar to the get_cb
(identical?) and the set_cb
is currently used for POST and DELETE operations. I wonder if moving to something more like "callback with response" and "callback without response" would make more sense?
7355624
to
8b77188
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @mniestroj! Can we add a twister test for the new sample? I'd like us to get into the habit of adding tests alongside new code rather than adding them retroactively.
@@ -261,6 +261,34 @@ static enum golioth_status golioth_coap_client_set_internal(struct golioth_clien | |||
return GOLIOTH_OK; | |||
} | |||
|
|||
enum golioth_status golioth_coap_client_post(struct golioth_client *client, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good discussion! Here are my thoughts:
- I like the idea of using
_post()
for the internal API. The use ofset()
here always felt a little odd here, since we are doing POST operations and the other APIs also use the CoAP REST operation names (GET, OBSERVE, DELETE, etc.). We can keepset()
for the higher level APIs that don't return a payload like LightDB State and Stream. This change would be out of scope for this PR. - For this PR, I think adding the new API works fine.
- I agree with Dan that we have a lot of overlap in the callbacks. I'm working on a change to proxy the callbacks through the upper half client as part of my hackday / holiday hours project. For that change, I'm using one catch-all callback between the lower and upper-half clients. We could do something similar for user callbacks (i.e. use one callback and set the payload to NULL if it is irrelevant for the operation). Or we could rename the callbacks as Dan suggested. Another idea is proxying all callbacks through the higher level services and then using service-specific callbacks. I think that will be easier for users, but it does add a lot of indirection to the callbacks (lower client => upper client => service => user code).
This allows to pass callback and parse returned payload at application layer. Signed-off-by: Marcin Niestroj <[email protected]>
ccc2394
to
1f49b15
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good @mniestroj! Left a couple comments about using the location request struct while processing the response. Still missing a twister test for the sample as well.
Introduce support for Golioth WiFi location service. Signed-off-by: Marcin Niestroj <[email protected]>
Add a sample with WiFi access points collected over the city trip. Signed-off-by: Marcin Niestroj <[email protected]>
This driver is helpful for testing without access to hardware with WiFi. Add also native_sim overlays with preconfigured wifi_playback driver. Signed-off-by: Marcin Niestroj <[email protected]>
Signed-off-by: Marcin Niestroj <[email protected]>
1f49b15
to
a0996d7
Compare
Working on that :) Which platforms do we want to support? I'm targeting |
I'm good with just native_sim to start 👍 We might be able to test with other platforms later, since we don't actually care that the location data is accurate, just that we are able to use the APIs, and that the sample code compiles and runs as expected. Making sure the location data is accurate is for the cloud team to test 🙂 |
Twister sample test implemented in #725 (it requires dev environment for now due to Location backend service). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @mniestroj!
No description provided.