Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
id-iot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
id-iot
Commits
bd1dfaf9
Commit
bd1dfaf9
authored
7 years ago
by
Per
Browse files
Options
Downloads
Patches
Plain Diff
fistr real commit
parent
d4ddb68a
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.vscode/tasks.json
+48
-0
48 additions, 0 deletions
.vscode/tasks.json
examples/client_and_server.rs
+5
-3
5 additions, 3 deletions
examples/client_and_server.rs
examples/client_test.rs
+67
-0
67 additions, 0 deletions
examples/client_test.rs
examples/idiot.rs
+87
-0
87 additions, 0 deletions
examples/idiot.rs
with
207 additions
and
3 deletions
.vscode/tasks.json
0 → 100644
+
48
−
0
View file @
bd1dfaf9
{
//
See
https://go.microsoft.com/fwlink/?LinkId=
733558
//
for
the
documentation
about
the
tasks.json
format
"version"
:
"2.0.0"
,
"tasks"
:
[
{
"type"
:
"shell"
,
"label"
:
"cargo build"
,
"command"
:
"cargo"
,
"args"
:
[
"build"
],
"problemMatcher"
:
[
"$rustc"
]
},
{
"type"
:
"shell"
,
"label"
:
"cargo build --example client_test"
,
"command"
:
"cargo"
,
"args"
:
[
"build --example client_test"
],
"problemMatcher"
:
[
"$rustc"
],
"group"
:
{
"kind"
:
"build"
,
"isDefault"
:
true
}
},
{
"type"
:
"shell"
,
"label"
:
"cargo build --example idiot"
,
"command"
:
"cargo"
,
"args"
:
[
"build --example idiot"
],
"problemMatcher"
:
[
"$rustc"
],
"group"
:
{
"kind"
:
"build"
,
"isDefault"
:
true
}
}
]
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
examples/client_and_server.rs
+
5
−
3
View file @
bd1dfaf9
extern
crate
coap
;
use
coap
::{
CoAP
Server
,
CoAPClient
,
CoAPRequest
,
CoAPResponse
,
CoAP
Option
};
use
coap
::{
CoAP
Client
,
CoAPOption
,
CoAPRequest
,
CoAPResponse
,
CoAP
Server
};
use
coap
::
IsMessage
;
fn
request_handler
(
request
:
CoAPRequest
)
->
Option
<
CoAPResponse
>
{
...
...
@@ -23,6 +23,8 @@ fn main() {
println!
(
"Client request: {}"
,
url
);
let
response
:
CoAPResponse
=
CoAPClient
::
request
(
url
)
.unwrap
();
println!
(
"Server reply: {}"
,
String
::
from_utf8
(
response
.message.payload
)
.unwrap
());
println!
(
"Server reply: {}"
,
String
::
from_utf8
(
response
.message.payload
)
.unwrap
()
);
}
This diff is collapsed.
Click to expand it.
examples/client_test.rs
0 → 100644
+
67
−
0
View file @
bd1dfaf9
extern
crate
coap
;
use
std
::
io
::
ErrorKind
;
use
coap
::{
CoAPClient
,
CoAPOption
,
CoAPRequest
,
IsMessage
,
MessageType
};
use
coap
::
message
::
header
::
Requests
;
fn
main
()
{
// let addr = "127.0.0.1:5683";
let
url
=
"127.0.0.1:9683"
;
let
endpoint
=
"servicediscovery/publish"
;
let
client
=
CoAPClient
::
new
(
url
)
.unwrap
();
let
mut
request
=
CoAPRequest
::
new
();
request
.set_code
(
"0.02"
);
// let mut header = request.get_mut_header();
// header = Requests::Post;
request
.set_version
(
1
);
//request.set_type(Requests::Post);
// request.set_code("0.01");
// request.set_message_id(1);
// request.set_token(vec![0x51, 0x55, 0x77, 0xE8]);
//
let
service_description
=
"
{
\"
name
\"
:
\"
crazy-827635ef
\"
,
\"
type
\"
:
\"
kalle._coap-json._udp
\"
,
\"
host
\"
:
\"
[fdfd::ff]
\"
,
\"
port
\"
:
\"
5683
\"
,
\"
domain
\"
:
\"
unknown
\"
,
\"
properties
\"
: {
\"
property
\"
: [
{
\"
name
\"
:
\"
version
\"
,
\"
value
\"
:
\"
1.0
\"
},
{
\"
name
\"
:
\"
path
\"
,
\"
value
\"
:
\"
/palletAvailable
\"
,
\"
loc
\"
:
\"
Station-01
\"
}
]
}
}"
;
request
.set_payload
(
service_description
.to_string
()
.into_bytes
());
request
.add_option
(
CoAPOption
::
UriPath
,
endpoint
.to_string
()
.into_bytes
());
println!
(
"{:?}"
,
request
);
client
.send
(
&
request
)
.unwrap
();
println!
(
"Client request: coap://{}{}"
,
url
,
endpoint
);
match
client
.receive
()
{
Ok
(
response
)
=>
{
println!
(
"Server reply: {}"
,
String
::
from_utf8
(
response
.message.payload
)
.unwrap
()
);
}
Err
(
e
)
=>
{
match
e
.kind
()
{
ErrorKind
::
WouldBlock
=>
println!
(
"Request timeout"
),
// Unix
ErrorKind
::
TimedOut
=>
println!
(
"Request timeout"
),
// Windows
_
=>
println!
(
"Request error: {:?}"
,
e
),
}
}
}
}
This diff is collapsed.
Click to expand it.
examples/idiot.rs
0 → 100644
+
87
−
0
View file @
bd1dfaf9
extern
crate
coap
;
use
std
::
io
::
ErrorKind
;
use
coap
::{
CoAPClient
,
CoAPOption
,
CoAPRequest
,
CoAPResponse
,
CoAPServer
};
use
coap
::
IsMessage
;
fn
request_handler
(
request
:
CoAPRequest
)
->
Option
<
CoAPResponse
>
{
let
uri_path
=
request
.get_option
(
CoAPOption
::
UriPath
)
.unwrap
();
return
match
request
.response
{
Some
(
mut
response
)
=>
{
response
.set_payload
(
uri_path
.front
()
.unwrap
()
.clone
());
Some
(
response
)
}
_
=>
None
,
};
}
fn
register
()
{
let
url
=
"127.0.0.1:9683"
;
let
endpoint
=
"servicediscovery/publish"
;
let
client
=
CoAPClient
::
new
(
url
)
.unwrap
();
let
mut
request
=
CoAPRequest
::
new
();
request
.set_code
(
"0.02"
);
request
.set_version
(
1
);
let
service_description
=
"
{
\"
name
\"
:
\"
crazy-827635ef
\"
,
\"
type
\"
:
\"
kalle._coap-json._udp
\"
,
\"
host
\"
:
\"
127.0.0.1
\"
,
\"
port
\"
:
\"
3400
\"
,
\"
domain
\"
:
\"
unknown
\"
,
\"
properties
\"
: {
\"
property
\"
: [
{
\"
name
\"
:
\"
version
\"
,
\"
value
\"
:
\"
1.0
\"
},
{
\"
name
\"
:
\"
path
\"
,
\"
value
\"
:
\"
/palletAvailable
\"
,
\"
loc
\"
:
\"
Station-01
\"
}
]
}
}"
;
request
.set_payload
(
service_description
.to_string
()
.into_bytes
());
request
.add_option
(
CoAPOption
::
UriPath
,
endpoint
.to_string
()
.into_bytes
());
println!
(
"{:?}"
,
request
);
client
.send
(
&
request
)
.unwrap
();
println!
(
"Client request: coap://{}{}"
,
url
,
endpoint
);
match
client
.receive
()
{
Ok
(
response
)
=>
{
println!
(
"Server reply: {}"
,
String
::
from_utf8
(
response
.message.payload
)
.unwrap
()
);
}
Err
(
e
)
=>
{
match
e
.kind
()
{
ErrorKind
::
WouldBlock
=>
println!
(
"Request timeout"
),
// Unix
ErrorKind
::
TimedOut
=>
println!
(
"Request timeout"
),
// Windows
_
=>
println!
(
"Request error: {:?}"
,
e
),
}
}
}
}
fn
main
()
{
register
();
let
mut
server
=
CoAPServer
::
new
(
"127.0.0.1:3400"
)
.unwrap
();
server
.handle
(
request_handler
)
.unwrap
();
let
url
=
"coap://127.0.0.1:9683/servicediscovery/service/cra"
;
println!
(
"Client request: {}"
,
url
);
let
response
:
CoAPResponse
=
CoAPClient
::
request
(
url
)
.unwrap
();
println!
(
"Server reply: {}"
,
String
::
from_utf8
(
response
.message.payload
)
.unwrap
()
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment