Skip to content

Commit

Permalink
wip(examples): trying to connect coapclient with riot-coap
Browse files Browse the repository at this point in the history
  • Loading branch information
geonnave committed Nov 29, 2023
1 parent 60d7f4d commit 781f351
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion examples/coap-riot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ CFLAGS += -DTHREAD_STACKSIZE_MAIN=20000

# Basic networking, and gcoap
USEMODULE += gcoap # just here because it pulls some useful depdenencies that enable riot_wrappers::socket_embedded_nal
USEMODULE += netdev_default
# USEMODULE += netdev_default
USEMODULE += usbus_cdc_ecm
USEMODULE += auto_init_gnrc_netif
USEMODULE += gnrc_ipv6_default
USEMODULE += gnrc_icmpv6_echo
Expand Down
21 changes: 19 additions & 2 deletions examples/coap/src/bin/coapclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ const CRED_R: &[u8] = &hex!("A2026008A101A5010202410A2001215820BBC34960526EA4D32
const _G_R: &[u8] = &hex!("bbc34960526ea4d32e940cad2a234148ddc21791a12afbcbac93622046dd44f0");

fn main() {
let url = "coap://127.0.0.1:5683/.well-known/edhoc";
// let url = "coap://127.0.0.1:5683/.well-known/edhoc";
let url = "coap://[fe80::acdb:aaff:fe8e:212c]:5683/.well-known/edhoc";
let timeout = Duration::new(5, 0);
println!("Client request: {}", url);

let mut coap_client = CoAPClient::new_with_specific_source(
"[fe80::ac53:635d:ea1f:b791]:0",
"[fe80::acdb:aaff:fe8e:212c]:5683",
)
.unwrap();

let state = Default::default();
let initiator = EdhocInitiator::new(
state,
Expand All @@ -36,7 +43,17 @@ fn main() {
msg_1_buf.extend_from_slice(message_1.as_slice());
println!("message_1 len = {}", msg_1_buf.len());

let response = CoAPClient::post_with_timeout(url, msg_1_buf, timeout).unwrap();
let response = coap_client
.request_path_with_timeout(
"/.well-known/edhoc",
coap_lite::RequestType::Post,
Some(msg_1_buf),
None,
None,
timeout,
)
.unwrap();
// let response = CoAPClient::post_with_timeout(&coap_client, url, msg_1_buf, timeout).unwrap();
if response.get_status() != &ResponseType::Changed {
panic!("Message 1 response error: {:?}", response.get_status());
}
Expand Down

0 comments on commit 781f351

Please sign in to comment.