-
Notifications
You must be signed in to change notification settings - Fork 2.1k
net/unicoap: Unified and Modular CoAP stack: Messaging and Minimal Server (pt 2) #21582
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
Open
carl-tud
wants to merge
114
commits into
RIOT-OS:master
Choose a base branch
from
carl-tud:unicoap-02-server-minimal
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
114 commits
Select commit
Hold shift + click to select a range
602b620
net/unicoap/rfc7252: add config for RFC 7252 messaging
carl-tud c078e80
net/unicoap/rfc7252: implement RFC 7252 messaging
carl-tud 92318c0
net/unicoap: add private messaging interface
carl-tud fde948c
net/unicoap/rfc7252/udp: implement UDP driver
carl-tud dc75bc8
net/unicoap/rfc7252/dtls: implement DTLS driver
carl-tud c0216cf
net/unicoap: add transport abstraction
carl-tud d579ab0
net/unicoap: add sock dependencies
carl-tud ae32c8f
net/unicoap: implement state handling
carl-tud ad8ebd6
net/unicoap: implement basic server functionality
carl-tud 755cdd8
net/unicoap: implement initialization
carl-tud 98120ff
auto_init: enable auto-init for unicoap
carl-tud cc690df
net/unicoap: document server
carl-tud 5503d4f
net/unicoap/rfc7252: add docs for UDP and DTLS drivers
carl-tud 4d00949
examples/unicoap_server: add sample unicoap server application
carl-tud 232a4e3
fixup: examples/unicoap_server: update Makefile.ci
carl-tud 30a7f6e
fixup: net/unicoap: add interface note to server tutorial
carl-tud 8d3db35
fixup: net/unicoap: server tutorial docs: remove trailing whitespace
carl-tud 6e3c37b
fixup: examples/unicoap_server: add README, fix typos
carl-tud 1d7061c
auto_init: fix indent in unicoap prio
carl-tud fd13630
net/unicoap: init: docs
carl-tud d623b0a
fixup: net/unicoap/rfc7252/udp (alongside): config.h: typo
carl-tud f2208cb
fixup: net/unicoap/application.h: docs, typos
carl-tud e848212
fixup: examples/unicoap_server: Add documentation to server example m…
carl-tud cad01e2
fixup: examples/unicoap_server: mind very very weird coding convetion
carl-tud 3882e16
fixup: examples/unicoap_server: conditionally compile UDP-specific co…
carl-tud 88e6d45
fixup: examples/unicoap_server: again, mind terrific coding convention
carl-tud ad68328
fixup: remove listener documentation comment regarding custom matchers
carl-tud 8b9c225
fixup: typo
carl-tud eff8829
fixup: docs debugging logging deffault
carl-tud 51d3a37
fixup: docs
carl-tud 4345b6c
fixup: docs
carl-tud 93d3379
fixup: docs
carl-tud 6bb868c
fixup: docs
carl-tud 5aafac3
remove feature check from preproc
carl-tud ca60a48
fixup: docs
carl-tud fc4ee20
fixup: i love the coding convention
carl-tud 1861b3a
fixup: style and docs
carl-tud 5e9bca9
fixup: remove mention of auto-init config constant
carl-tud 8c69b0b
fixup: typo CONFIG_ in Kconfig
carl-tud 12987d0
fixup: no tabs in makefile
carl-tud 9d2bbdd
fixup: typos
carl-tud 339d9ad
explain black magic
carl-tud 3652c35
fixup: use correct code sample
carl-tud 6a401f6
fixup: typos
carl-tud f0fe642
fixup: typos
carl-tud cc85bba
fixup: docs
carl-tud bff57dd
fixup: docs
carl-tud d4863b5
fixup: preproc indents
carl-tud b8dca8f
fixup: fix long lines in DTLS code
carl-tud 1555fba
fixup: preprocessor indent fixes in drivers
carl-tud 35787c4
fixup: docs
carl-tud 5abe9e7
fixup: docs
carl-tud 1c8483a
fixup: typo
carl-tud 7223cd1
fixup: use _transmission_t instead
carl-tud 17a74e2
fixup: do not indent top-level preprocessor directives
carl-tud 4334c7d
fixup: typo
carl-tud fc5ff18
fixup: typos
carl-tud 44ea8d3
fixup: _packet_get_dtls_session
carl-tud 265f2cb
address messaging.c review comments
carl-tud be62ad8
naming
carl-tud ab2a99d
fixup: typo
carl-tud 4aab839
fixup: preprocessor directive indents at top level
carl-tud 0ffd285
fixup: typo
carl-tud d391e27
fixup: use correct callback type on scheduling fn
carl-tud 9f99d5b
fixup: address review comments in messaging-related parts
carl-tud 4b63e55
fixup: address review comments
carl-tud 20dcf80
fixup: address review comments
carl-tud 35bdd05
fixup: fix path string matching
carl-tud f1dd384
fixup: compile is_multicast helper when UDP support is missing
carl-tud 57123e1
fixup: typos
carl-tud 438ad7f
fixup: clarify atomic usage
carl-tud 2f0e872
fixup: partially fix running loop on any thread
carl-tud 9370c26
main.c
carl-tud 0c5ed49
fixup: add unicoap_loop_enqueue to example app
carl-tud 6a8f77c
fixup: restore unicoap_server config to defaults
carl-tud 0cb5868
fixup: use unicoap_job_t proxy, typecheck macro expr
carl-tud 35a0100
fixup: remove unused typecheck func from unicoap.h
carl-tud 15f49c4
fixup: typo
carl-tud 78e3da3
fixup: docs
carl-tud 277b634
fixup: only use __has_builtin if available
carl-tud 7cd0ff7
fixup: __typeof__?
carl-tud c307339
fixup: forgot to check in util_macros.h
carl-tud eee23ef
fixup: default config for server example
carl-tud a48ee62
fixup: timeout option in client.py (aiocoap issue)
carl-tud cf5df59
fixup: dtls debug logging
carl-tud 95c0be4
fixup: proper asyncio timeout in client.py
carl-tud dc7b68f
docs: remove shell ifconfig hint
carl-tud 20cf4d7
fixup: use event queue's detached init functions
carl-tud a0eacaa
fixup: docs
carl-tud 4b118b1
fixup: remove job example from unicoap_server app
carl-tud 1b7984d
fixup: assist wording sock support
carl-tud 634a5d5
fixup: document dark compiler magic
carl-tud 300f842
fixup: typo
carl-tud c7ad597
fixup: client.py now uses -mt and -to
carl-tud c8f4b65
fixup: use unicoap_message_code_is_* instead of unicoap_message_is_*
carl-tud 0523502
fixup: remove erroneous assert(session) in DTLS transport driver
carl-tud af34573
fixup: add note on multiple consecutive slashes
carl-tud 28ec273
fixup: fix various path matching issues (write tests!)
carl-tud eedc942
fixup: unittests: unicoap path matching
carl-tud cf3818c
fixup: return error when trying to unregister unknown listener
carl-tud fa1e31d
fixup: use packet->message
carl-tud ec11bfb
fixup: example: disable debug logging by default to save space
carl-tud dc097d0
fixup: forgot to check in tests
carl-tud 47b3b00
fixup: typo
carl-tud e343b86
fixup: fix unresponsive CoAP over DTLS server
carl-tud a166aa8
fixup: dtls: style
carl-tud e7b4ef1
fixup: example: docs
carl-tud 53c479e
fixup: client.py tells users that aiocoap DTLS error is expected
carl-tud a09f34a
fixup: naming
carl-tud d5578a3
fixup: comments
carl-tud 01fe535
fixup: client.py: context.shutdown()
carl-tud 3f8c798
fixup: use correct timeouts in CoAP over DTLS driver
carl-tud 89580a5
fixup: WIP: sock->buf_ctx dtls (commented out)
carl-tud 7aa791e
fixup: typo
carl-tud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Default Makefile, for simple unicoap server sample application | ||
|
|
||
| # name of your application | ||
| APPLICATION = unicoap_server | ||
|
|
||
| # If no BOARD is found in the environment, use this default: | ||
| BOARD ?= native | ||
|
|
||
| # This has to be the absolute path to the RIOT base directory: | ||
| RIOTBASE ?= $(CURDIR)/../../../.. | ||
|
|
||
| # Include packages that pull up and auto-init the link layer. | ||
| # NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present | ||
| USEMODULE += netdev_default | ||
|
|
||
| # use GNRC by default | ||
| LWIP_IPV4 ?= 0 | ||
| LWIP_IPV6 ?= 0 | ||
|
|
||
| ifeq (,$(filter 1, $(LWIP_IPV4) $(LWIP_IPV6))) | ||
| USEMODULE += auto_init_gnrc_netif | ||
| # Specify the mandatory networking modules | ||
| USEMODULE += gnrc_ipv6_default | ||
| # Additional networking modules that can be dropped if not needed | ||
| USEMODULE += gnrc_icmpv6_echo | ||
| else | ||
| ifeq (1,$(LWIP_IPV4)) | ||
| USEMODULE += ipv4_addr | ||
|
|
||
| USEMODULE += lwip_arp | ||
| USEMODULE += lwip_ipv4 | ||
| USEMODULE += lwip_dhcp_auto | ||
| CFLAGS += -DETHARP_SUPPORT_STATIC_ENTRIES=1 | ||
| endif | ||
|
|
||
| ifeq (1,$(LWIP_IPV6)) | ||
| USEMODULE += ipv6_addr | ||
|
|
||
| USEMODULE += lwip_ipv6 | ||
| USEMODULE += lwip_ipv6_autoconfig | ||
| endif | ||
| endif | ||
|
|
||
| USEMODULE += unicoap | ||
| USEMODULE += unicoap_resources_xfa | ||
|
|
||
| # This module is needed for CoAP over UDP | ||
| USEMODULE += unicoap_driver_udp | ||
|
|
||
| # This module is needed for CoAP over DTLS | ||
| USEMODULE += unicoap_driver_dtls | ||
|
|
||
| # It is okay to import only either of the CoAP over UDP and CoAP over DTLS drivers. | ||
|
|
||
| # Comment this out to disable code in RIOT that does safety checking | ||
| # which is not needed in a production environment but helps in the | ||
| # development process: | ||
| DEVELHELP ?= 1 | ||
|
|
||
| # Change this to 0 show compiler invocation lines by default: | ||
| QUIET ?= 1 | ||
|
|
||
| include $(RIOTBASE)/Makefile.include |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| BOARD_INSUFFICIENT_MEMORY := \ | ||
| airfy-beacon \ | ||
| arduino-duemilanove \ | ||
| arduino-leonardo \ | ||
| arduino-mega2560 \ | ||
| arduino-nano \ | ||
| arduino-uno \ | ||
| atmega1284p \ | ||
| atmega328p \ | ||
| atmega328p-xplained-mini \ | ||
| atmega8 \ | ||
| atxmega-a3bu-xplained \ | ||
| blackpill-stm32f103c8 \ | ||
| bluepill-stm32f030c8 \ | ||
| bluepill-stm32f103c8 \ | ||
| calliope-mini \ | ||
| derfmega128 \ | ||
| hifive1 \ | ||
| hifive1b \ | ||
| i-nucleo-lrwan1 \ | ||
| im880b \ | ||
| mega-xplained \ | ||
| microbit \ | ||
| microduino-corerf \ | ||
| msb-430 \ | ||
| msb-430h \ | ||
| nrf51dongle \ | ||
| nucleo-c031c6 \ | ||
| nucleo-f030r8 \ | ||
| nucleo-f031k6 \ | ||
| nucleo-f042k6 \ | ||
| nucleo-f070rb \ | ||
| nucleo-f072rb \ | ||
| nucleo-f302r8 \ | ||
| nucleo-f303k8 \ | ||
| nucleo-f334r8 \ | ||
| nucleo-l011k4 \ | ||
| nucleo-l031k6 \ | ||
| nucleo-l053r8 \ | ||
| olimex-msp430-h1611 \ | ||
| olimex-msp430-h2618 \ | ||
| samd10-xmini \ | ||
| saml10-xpro \ | ||
| saml11-xpro \ | ||
| slstk3400a \ | ||
| stk3200 \ | ||
| stm32f030f4-demo \ | ||
| stm32f0discovery \ | ||
| stm32f7508-dk \ | ||
| stm32g0316-disco \ | ||
| stm32l0538-disco \ | ||
| stm32mp157c-dk2 \ | ||
| telosb \ | ||
| weact-g030f6 \ | ||
| yunjia-nrf51822 \ | ||
| z1 \ | ||
| zigduino \ | ||
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Sample Server Application With `unicoap` | ||
|
|
||
| This a sample application demonstrating how you can define CoAP resources using `unicoap`, | ||
| the unified and modular CoAP suite in RIOT. Visit the | ||
| [`unicoap` server tutorial on doc.riot-os.org](http://doc.riot-os.org/group__net__unicoap__server__tutorial.html) | ||
| for a detailed code-level instructions. | ||
|
|
||
| ## Running the Example on RIOT's Native Board | ||
|
|
||
| Create a tap interface (to which RIOT will connect): | ||
|
|
||
| ``` | ||
| $ sudo ip tuntap add tap0 mode tap user ${USER} | ||
| $ sudo ip link set tap0 up | ||
| ``` | ||
|
|
||
| To try this example on your host, run: | ||
| ```sh | ||
| BOARD=native make flash term | ||
| ``` | ||
| This will compile and run the application. | ||
| The application will print a network-layer address. | ||
|
|
||
| In a second terminal session, you can run | ||
|
|
||
| ```sh | ||
| python3 client.py -m GET -u "coap://[fe80::c0:ff:ee%tap0]/greeting?name=RIOTer" | ||
| ``` | ||
|
|
||
| to send a CoAP request through the tap interface to the CoAP server where `fe80::c0:ff:ee` | ||
| is the link-layer address printed by the application. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| CONFIG_UNICOAP_DEBUG_LOGGING=n | ||
| CONFIG_UNICOAP_ASSIST=n | ||
| CONFIG_UNICOAP_CREATE_THREAD=y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import logging | ||
| import asyncio | ||
| from argparse import ArgumentParser | ||
|
|
||
| from aiocoap import CON, NON, GET, PUT, POST, DELETE, PATCH, iPATCH, FETCH, Context, Message | ||
| import aiocoap.resource as resource | ||
| from aiocoap.transports.tinydtls import DTLSClientConnection | ||
|
|
||
| logging.basicConfig(level=logging.DEBUG) | ||
|
|
||
| print( | ||
| "usage: client.py" + | ||
| " -m <GET|PUT|POST|DELETE|PATCH|iPATCH|FETCH>" + | ||
| " -u <URI>" + | ||
| " [--type <NON|CON>] [--observe] [-p <PAYLOAD>]") | ||
|
|
||
|
|
||
| def _get(_list, i, default): | ||
| return _list[i] if len(_list) > i else default | ||
|
|
||
|
|
||
| def message_type(arg): | ||
| return {"CON": CON, "NON": NON}[arg] | ||
|
|
||
|
|
||
| def method(arg): | ||
| return { | ||
| "GET": GET, | ||
| "PUT": PUT, | ||
| "POST": POST, | ||
| "DELETE": DELETE, | ||
| "PATCH": PATCH, | ||
| "iPATCH": iPATCH, | ||
| "FETCH": FETCH | ||
| }[arg] | ||
|
|
||
|
|
||
| async def main(): | ||
| parser = ArgumentParser() | ||
|
|
||
| parser.add_argument( | ||
| "-m", "--method", | ||
| help='GET|PUT|POST|DELETE|PATCH|iPATCH|FETCH', | ||
| required=True) | ||
|
|
||
| parser.add_argument( | ||
| "-u", "--uri", | ||
| help='URI', | ||
| required=True) | ||
|
|
||
| parser.add_argument( | ||
| "-mt", "--type", | ||
| help='NON|CON', | ||
| default="NON") | ||
|
|
||
| parser.add_argument( | ||
| "--observe", | ||
| action="store_true", | ||
| help='Register for notifications', | ||
| default=False) | ||
|
|
||
| parser.add_argument( | ||
| "--observe-cancel", | ||
| action="store_true", | ||
| help='Cancel notifications', | ||
| default=False) | ||
|
|
||
| parser.add_argument( | ||
| "-p", "--payload", | ||
| help='Payload', | ||
| default=None) | ||
|
|
||
| parser.add_argument( | ||
| "-to", "--timeout", | ||
| type=float, | ||
| help='Request timeout', | ||
| default="4") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| observeValue = None | ||
|
|
||
| if args.observe and args.observe_cancel: | ||
| raise ValueError("cannot register for and cancel notifications") | ||
|
|
||
| if args.observe: | ||
| observeValue = 0 | ||
|
|
||
| elif args.observe_cancel: | ||
| observeValue = 1 | ||
|
|
||
| print(f"using {message_type(args.type)} {method(args.method)} request") | ||
| print(f"timeout set to {args.timeout}s") | ||
|
|
||
| port = 5600 | ||
| protocol = await Context.create_server_context(bind=("::", port), site=resource.Site()) | ||
| protocol.client_credentials.load_from_dict({ | ||
carl-tud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| '*': { | ||
| 'dtls': { | ||
| 'psk': b'secretPSK', | ||
| 'client-identity': b'Client_identity', | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| request = Message( | ||
| mtype=message_type(args.type), | ||
| code=method(args.method), | ||
| uri=args.uri, | ||
| payload=bytes(args.payload, 'utf-8') if args.payload else "", | ||
| observe=observeValue | ||
| ) | ||
|
|
||
| try: | ||
| pr = protocol.request(request) | ||
|
|
||
| async with asyncio.timeout(args.timeout): | ||
| r = await pr.response | ||
| print("response: %s\n%r" % (r.code, r.payload)) | ||
|
|
||
| if args.observe: | ||
| print("waiting for resource notifications") | ||
|
|
||
| async for r in pr.observation: | ||
| print("notification: %s\n%r" % (r, r.payload)) | ||
| break | ||
|
|
||
| await protocol.shutdown() | ||
|
|
||
| except TimeoutError: | ||
| print(f"error: timeout exceeded after waiting {args.timeout}s") | ||
|
|
||
| except Exception as e: | ||
| print("error:") | ||
| print(e) | ||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.