Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
embedded-rust-michael-david
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
david.dasilvam2
embedded-rust-michael-david
Commits
f5c27c67
Commit
f5c27c67
authored
1 year ago
by
david
Browse files
Options
Downloads
Patches
Plain Diff
final final
parent
c1c9b6b5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/main.rs
+34
-40
34 additions, 40 deletions
src/main.rs
src/mpl115_a2.rs
+1
-2
1 addition, 2 deletions
src/mpl115_a2.rs
src/rn_131rg.rs
+46
-40
46 additions, 40 deletions
src/rn_131rg.rs
with
81 additions
and
82 deletions
src/main.rs
+
34
−
40
View file @
f5c27c67
...
@@ -22,6 +22,7 @@ struct Data {
...
@@ -22,6 +22,7 @@ struct Data {
#[entry]
#[entry]
fn
main
()
->
!
{
fn
main
()
->
!
{
// Clean terminal and acknowledge the boot
// Clean terminal and acknowledge the boot
hprint!
{
"{}[2J"
,
27
as
char
};
hprint!
{
"{}[2J"
,
27
as
char
};
hprintln!
{
"Nucleo-l476RG is alive !"
};
hprintln!
{
"Nucleo-l476RG is alive !"
};
...
@@ -144,53 +145,46 @@ fn main() -> ! {
...
@@ -144,53 +145,46 @@ fn main() -> ! {
};
};
loop
{
loop
{
rn_131rg
::
wait_http_instant
(
&
mut
rn_con
);
// wait on a request, and return the first letter,
// usefull to know if it is POST or GET
let
c
=
rn_131rg
::
wait_http
(
&
mut
rn_con
);
//
G
et
D
ata
//
g
et
d
ata
from sensors
mpl115_a2
::
get_data
(
&
mut
mp_con
,
&
mut
data
.pression
,
&
mut
data
.temperature
);
mpl115_a2
::
get_data
(
&
mut
mp_con
,
&
mut
data
.pression
,
&
mut
data
.temperature
);
pb200_286
::
get_data
(
&
mut
pb200_286_conn
,
&
mut
pb_cs
,
&
mut
data
.luminosity
);
pb200_286
::
get_data
(
&
mut
pb200_286_conn
,
&
mut
pb_cs
,
&
mut
data
.luminosity
);
if
c
==
b'P'
{
// if POST, send only the sensor
rn_131rg
::
send_fmt
(
rn_131rg
::
send_fmt
(
&
mut
rn_con
,
&
mut
rn_con
,
format_args!
(
format_args!
(
r##
"HTTP/1.1 200 OK
"HTTP/1.1 200 OK
Content-Length:
5138
Content-Length:
17
Content-Type: text/html
Content-Type: text/html
Connection: close
Connection: close
<!DOCTYPE html><html><head> <meta charset='UTF-8'> <link rel='icon' href="data:image/svg+xml,%3Csvg version='1.1' viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cg%3E%3Cpath d='m148.3 484.5c-29.29-5.395-53.49-24.09-65.85-50.87-19.85-43-1.512-95.05 41.01-116.4 12.68-6.37 21.61-8.488 38.01-9.006l15.01-0.4743 3.401-4.934c12.22-17.73 33.87-33.98 55.22-41.46 9.268-3.244 25.23-6.38 32.47-6.38 5.418 0 5.69-0.1398 12.81-6.592 20.26-18.35 42.9-29.81 69.31-35.09 13.25-2.647 38.47-2.374 52.23 0.5663 54.37 11.62 95.49 52.74 107.2 107.2 3.206 14.95 3.206 39.97 0 54.91-11.61 54.11-52.07 94.78-106.6 107.2l-10 2.271-118.5 0.2286c-94.57 0.1824-119.9-0.0377-125.7-1.09z' fill='%23fff'/%3E%3Cg fill='%23fdff09'%3E%3Cpath d='m213.1 104.2c-1.886-0.9616-4.361-3.018-5.5-4.57-1.969-2.682-2.085-4.29-2.348-32.5-0.3134-33.61-0.1357-34.55 7.381-38.97 6.756-3.973 14.51-1.95 19.83 5.174 1.953 2.614 2.077 4.277 2.354 31.45 0.2887 28.35 0.2644 28.74-2.025 33.07-3.943 7.457-12.26 10.13-19.7 6.341z'/%3E%3Cpath d='m321.3 "##
{:02.3}|{:02.3}|{:03}
),
);
rn_131rg
::
send_fmt
(
&
mut
rn_con
,
format_args!
(
r##"149c-5.59-3.409-8.064-9.127-6.835-15.8 0.5846-3.175 3.828-6.899 21.36-24.53 21.91-22.03 24.23-23.68 31.47-22.32 9.303 1.745 14.71 13.02 10.27 21.4-1.719 3.239-39.13 40.51-42.25 42.09-3.439 1.742-10.46 1.317-14.01-0.8495z'/%3E%3Cpath d='m101.4 148.1c-2.145-1.587-11.84-10.92-21.55-20.75-19.72-19.95-21.31-22.52-18.93-30.49 1.567-5.232 4.728-8.392 9.959-9.959 7.963-2.386 10.53-0.7899 30.49 18.93 22.15 21.89 23.64 23.81 23.63 30.55-0.0116 8.947-5.646 14.58-14.59 14.59-4.06 5e-3 -5.895-0.5818-9-2.878z'/%3E%3Cpath d='m9.45 259.6c-8.845-3.853-11.96-14.86-6.404-22.66 3.984-5.595 6.105-5.934 37.1-5.933 25.01 1e-3 28.75 0.2073 31.78 1.75 4.777 2.436 7.278 6.273 7.772 11.92 0.5571 6.371-2 11.03-7.714 14.05-4.181 2.211-5.08 2.274-31.89 2.236-20.67-0.0293-28.36-0.3723-30.64-1.367z'/%3E%3Cpath d='m112.2 281.8c-5.438-16.58-7.153-38.4-4.305-54.8 6.166-35.49 29.23-66.43 61.78-82.86 25.26-12.75 58.85-14.97 86.15-5.681 16.85 5.731 31.76 15.03 44.12 27.53 6.903 6.977 18 21.61 18 23.74 0 0.4964-2.588 1.957-5.75 3.245-15.24 "##
),
);
rn_131rg
::
send_fmt
(
"
,
data
.pression
,
data
.temperature
,
data
.luminosity
&
mut
rn_con
,
format_args!
(
r##"6.209-32.68 16.61-44.86 26.77-6.046 5.041-6.224 5.111-18.33 7.167-30.49 5.179-56.95 19.01-79.06 41.34-9.394 9.485-9.779 9.75-14.2 9.75-9.371 0-27.6 4.308-39.9 9.43-1.26 0.5246-2.027-0.6569-3.659-5.633z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A""> <title>Rust Weather Station</title></head><style>body{{background: radial-gradient(100% 200% at 50% 150%, rgb(255, 255, 255) 0%, rgb(0, 212, 255) 100%); height: 100vh; display: flex; flex-flow: column; justify-content: center; align-items: center; font-family: monospace; font-size: 1rem; margin: 0;}}div{{background: white; max-width: 400px; width: 100%; padding: 1rem; border-radius: 0.3rem; box-shadow: 10px 10px 0 black; border: 1px solid black;}}svg{{width: 200px; filter: drop-shadow(10px 10px 0);}}</style><body> <svg version=" 1.1" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"> <g> <path d="m148.3 484.5c-29.29-5.395-53.49-24.09-65.85-50.87-19.85-43-1.512-95.05 41.01-116.4 12.68-6.37 21.61-8.488 38.01-9.006l15.01-0.4743 3.401-4.934c12.22-17.73 33.87-33.98 "##
),
),
);
)
}
else
{
// if GET, we send full html page
rn_131rg
::
send_fmt
(
rn_131rg
::
send_fmt
(
&
mut
rn_con
,
&
mut
rn_con
,
format_args!
(
format_args!
(
r##"55.22-41.46 9.268-3.244 25.23-6.38 32.47-6.38 5.418 0 5.69-0.1398 12.81-6.592 20.26-18.35 42.9-29.81 69.31-35.09 13.25-2.647 38.47-2.374 52.23 0.5663 54.37 11.62 95.49 52.74 107.2 107.2 3.206 14.95 3.206 39.97 0 54.91-11.61 54.11-52.07 94.78-106.6 107.2l-10 2.271-118.5 0.2286c-94.57 0.1824-119.9-0.0377-125.7-1.09z" fill="#fff"/> <g fill="#fdff09"> <path d="m213.1 104.2c-1.886-0.9616-4.361-3.018-5.5-4.57-1.969-2.682-2.085-4.29-2.348-32.5-0.3134-33.61-0.1357-34.55 7.381-38.97 6.756-3.973 14.51-1.95 19.83 5.174 1.953 2.614 2.077 4.277 2.354 31.45 0.2887 28.35 0.2644 28.74-2.025 33.07-3.943 7.457-12.26 10.13-19.7 6.341z"/> <path d="m321.3 149c-5.59-3.409-8.064-9.127-6.835-15.8 0.5846-3.175 3.828-6.899 21.36-24.53 21.91-22.03 24.23-23.68 31.47-22.32 9.303 1.745 14.71 13.02 10.27 21.4-1.719 3.239-39.13 40.51-42.25 42.09-3.439 1.742-10.46 1.317-14.01-0.8495z"/> <path d="m101.4 148.1c-2.145-1.587-11.84-10.92-21.55-20.75-19.72-19.95-21.31-22.52-18.93-30.49 1.567-5.232 4.728-8.392 9.959-9.959 7.963-2.386 10.53-0.7899 "##
r##"HTTP/1.1 200 OK
),
Content-Length: 5406
);
Content-Type: text/html
Connection: close
rn_131rg
::
send_fmt
(
<!DOCTYPE html><html><head><meta charset='UTF-8'><link rel='icon' href="data:image/svg+xml,%3Csvg version='1.1' viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cg%3E%3Cpath d='m148.3 484.5c-29.29-5.395-53.49-24.09-65.85-50.87-19.85-43-1.512-95.05 41.01-116.4 12.68-6.37 21.61-8.488 38.01-9.006l15.01-0.4743 3.401-4.934c12.22-17.73 33.87-33.98 55.22-41.46 9.268-3.244 25.23-6.38 32.47-6.38 5.418 0 5.69-0.1398 12.81-6.592 20.26-18.35 42.9-29.81 69.31-35.09 13.25-2.647 38.47-2.374 52.23 0.5663 54.37 11.62 95.49 52.74 107.2 107.2 3.206 14.95 3.206 39.97 0 54.91-11.61 54.11-52.07 94.78-106.6 107.2l-10 2.271-118.5 0.2286c-94.57 0.1824-119.9-0.0377-125.7-1.09z' fill='%23fff'/%3E%3Cg fill='%23fdff09'%3E%3Cpath d='m213.1 104.2c-1.886-0.9616-4.361-3.018-5.5-4.57-1.969-2.682-2.085-4.29-2.348-32.5-0.3134-33.61-0.1357-34.55 7.381-38.97 6.756-3.973 14.51-1.95 19.83 5.174 1.953 2.614 2.077 4.277 2.354 31.45 0.2887 28.35 0.2644 28.74-2.025 33.07-3.943 7.457-12.26 10.13-19.7 6.341z'/%3E%3Cpath d='m321.3 149c-5.59-3.409-8.064-9.127-6.835-15.8 0.5846-3.175 3.828-6.899 21.36-24.53 21.91-22.03 24.23-23.68 31.47-22.32 9.303 1.745 14.71 13.02 10.27 21.4-1.719 3.239-39.13 40.51-42.25 42.09-3.439 1.742-10.46 1.317-14.01-0.8495z'/%3E%3Cpath d='m101.4 148.1c-2.145-1.587-11.84-10.92-21.55-20.75-19.72-19.95-21.31-22.52-18.93-30.49 1.567-5.232 4.728-8.392 9.959-9.959 7.963-2.386 10.53-0.7899 30.49 18.93 22.15 21.89 23.64 23.81 23.63 30.55-0.0116 8.947-5.646 14.58-14.59 14.59-4.06 5e-3 -5.895-0.5818-9-2.878z'/%3E%3Cpath d='m9.45 259.6c-8.845-3.853-11.96-14.86-6.404-22.66 3.984-5.595 6.105-5.934 37.1-5.933 25.01 1e-3 28.75 0.2073 31.78 1.75 4.777 2.436 7.278 6.273 7.772 11.92 0.5571 6.371-2 11.03-7.714 14.05-4.181 2.211-5.08 2.274-31.89 2.236-20.67-0.0293-28.36-0.3723-30.64-1.367z'/%3E%3Cpath d='m112.2 281.8c-5.438-16.58-7.153-38.4-4.305-54.8 6.166-35.49 29.23-66.43 61.78-82.86 25.26-12.75 58.85-14.97 86.15-5.681 16.85 5.731 31.76 15.03 44.12 27.53 6.903 6.977 18 21.61 18 23.74 0 0.4964-2.588 1.957-5.75 3.245-15.24 6.209-32.68 16.61-44.86 26.77-6.046 5.041-6.224 5.111-18.33 7.167-30.49 5.179-56.95 19.01-79.06 41.34-9.394 9.485-9.779 9.75-14.2 9.75-9.371 0-27.6 4.308-39.9 9.43-1.26 0.5246-2.027-0.6569-3.659-5.633z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A""> <title>Rust Weather Station</title></head><style>body{{background: radial-gradient(100% 200% at 50% 150%, rgb(255, 255, 255) 0%, rgb(0, 212, 255) 100%); height: 100vh; display: flex; flex-flow: column; justify-content: center; align-items: center; font-family: monospace; font-size: 1rem; margin: 0;}}div{{background: white; max-width: 400px; width: 100%; padding: 1rem; border-radius: 0.3rem; box-shadow: 10px 10px 0 black; border: 1px solid black;}}svg{{width: 200px; filter: drop-shadow(10px 10px 0);}}</style><body> <svg version="1.1" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><g><path d="m148.3 484.5c-29.29-5.395-53.49-24.09-65.85-50.87-19.85-43-1.512-95.05 41.01-116.4 12.68-6.37 21.61-8.488 38.01-9.006l15.01-0.4743 3.401-4.934c12.22-17.73 33.87-33.98 55.22-41.46 9.268-3.244 25.23-6.38 32.47-6.38 5.418 0 5.69-0.1398 12.81-6.592 20.26-18.35 42.9-29.81 69.31-35.09 13.25-2.647 38.47-2.374 52.23 0.5663 54.37 11.62 95.49 52.74 107.2 107.2 3.206 14.95 3.206 39.97 0 54.91-11.61 54.11-52.07 94.78-106.6 107.2l-10 2.271-118.5 0.2286c-94.57 0.1824-119.9-0.0377-125.7-1.09z" fill="#fff" /><g fill="#fdff09"><path d="m213.1 104.2c-1.886-0.9616-4.361-3.018-5.5-4.57-1.969-2.682-2.085-4.29-2.348-32.5-0.3134-33.61-0.1357-34.55 7.381-38.97 6.756-3.973 14.51-1.95 19.83 5.174 1.953 2.614 2.077 4.277 2.354 31.45 0.2887 28.35 0.2644 28.74-2.025 33.07-3.943 7.457-12.26 10.13-19.7 6.341z" /><path d="m321.3 149c-5.59-3.409-8.064-9.127-6.835-15.8 0.5846-3.175 3.828-6.899 21.36-24.53 21.91-22.03 24.23-23.68 31.47-22.32 9.303 1.745 14.71 13.02 10.27 21.4-1.719 3.239-39.13 40.51-42.25 42.09-3.439 1.742-10.46 1.317-14.01-0.8495z" /><path d="m101.4 148.1c-2.145-1.587-11.84-10.92-21.55-20.75-19.72-19.95-21.31-22.52-18.93-30.49 1.567-5.232 4.728-8.392 9.959-9.959 7.963-2.386 10.53-0.7899 30.49 18.93 22.15 21.89 23.64 23.81 23.63 30.55-0.0116 8.947-5.646 14.58-14.59 14.59-4.06 5e-3 -5.895-0.5818-9-2.878z" /><path d="m9.45 259.6c-8.845-3.853-11.96-14.86-6.404-22.66 3.984-5.595 6.105-5.934 37.1-5.933 25.01 1e-3 28.75 0.2073 31.78 1.75 4.777 2.436 7.278 6.273 7.772 11.92 0.5571 6.371-2 11.03-7.714 14.05-4.181 2.211-5.08 2.274-31.89 2.236-20.67-0.0293-28.36-0.3723-30.64-1.367z" /><path d="m112.2 281.8c-5.438-16.58-7.153-38.4-4.305-54.8 6.166-35.49 29.23-66.43 61.78-82.86 25.26-12.75 58.85-14.97 86.15-5.681 16.85 5.731 31.76 15.03 44.12 27.53 6.903 6.977 18 21.61 18 23.74 0 0.4964-2.588 1.957-5.75 3.245-15.24 6.209-32.68 16.61-44.86 26.77-6.046 5.041-6.224 5.111-18.33 7.167-30.49 5.179-56.95 19.01-79.06 41.34-9.394 9.485-9.779 9.75-14.2 9.75-9.371 0-27.6 4.308-39.9 9.43-1.26 0.5246-2.027-0.6569-3.659-5.633z" /></g></g></svg><h1>Rust Weather Station</h1><div><p>Pression: <span id="p">...</span> [kPa]</p><p>Température: <span id="t">...</span> [°C] (±5 °C)</p><p>Luminosité: <span id="l">...</span>/125</p></div></body><script>setInterval(async () => {{let r = await fetch( "192.168.120.103" ,{{method: "POST"}});let d = (await r.text()).split("|");document.querySelector("#p").textContent = d[0];document.querySelector("#t").textContent = d[1];document.querySelector("#l").textContent = d[2];}},3000);</script></html>
&
mut
rn_con
,
format_args!
(
r##"30.49 18.93 22.15 21.89 23.64 23.81 23.63 30.55-0.0116 8.947-5.646 14.58-14.59 14.59-4.06 5e-3 -5.895-0.5818-9-2.878z"/> <path d="m9.45 259.6c-8.845-3.853-11.96-14.86-6.404-22.66 3.984-5.595 6.105-5.934 37.1-5.933 25.01 1e-3 28.75 0.2073 31.78 1.75 4.777 2.436 7.278 6.273 7.772 11.92 0.5571 6.371-2 11.03-7.714 14.05-4.181 2.211-5.08 2.274-31.89 2.236-20.67-0.0293-28.36-0.3723-30.64-1.367z"/> <path d="m112.2 281.8c-5.438-16.58-7.153-38.4-4.305-54.8 6.166-35.49 29.23-66.43 61.78-82.86 25.26-12.75 58.85-14.97 86.15-5.681 16.85 5.731 31.76 15.03 44.12 27.53 6.903 6.977 18 21.61 18 23.74 0 0.4964-2.588 1.957-5.75 3.245-15.24 6.209-32.68 16.61-44.86 26.77-6.046 5.041-6.224 5.111-18.33 7.167-30.49 5.179-56.95 19.01-79.06 41.34-9.394 9.485-9.779 9.75-14.2 9.75-9.371 0-27.6 4.308-39.9 9.43-1.26 0.5246-2.027-0.6569-3.659-5.633z"/> </g> </g> </svg> <h1>Rust Weather Station</h1> <div> <p>Pression: {:.3} [kPa]</p><p>Température: {:.3} [°C] (±5 °C)</p><p>Luminosité: {:0>3}/125 %</p></div></body> <script>setTimeout(()=>{{location.reload()}}, 10000); </script></html>
"##
,
"##
data
.pression
,
data
.temperature
,
data
.luminosity
),
),
);
);
}
}
}
}
}
This diff is collapsed.
Click to expand it.
src/mpl115_a2.rs
+
1
−
2
View file @
f5c27c67
...
@@ -67,7 +67,7 @@ pub fn get_data(
...
@@ -67,7 +67,7 @@ pub fn get_data(
.unwrap
();
.unwrap
();
let
coeffs
=
coeff
(
buffer_8
);
let
coeffs
=
coeff
(
buffer_8
);
asm
::
delay
(
1_000
_000
);
//
asm::delay(1_000);
// Start Pressure and Temperature Conversion
// Start Pressure and Temperature Conversion
i2c
.write
(
MPL115A2_ADDR
,
&
[
0x12
,
0x00
])
.unwrap
();
i2c
.write
(
MPL115A2_ADDR
,
&
[
0x12
,
0x00
])
.unwrap
();
...
@@ -78,7 +78,6 @@ pub fn get_data(
...
@@ -78,7 +78,6 @@ pub fn get_data(
i2c
.write_read
(
MPL115A2_ADDR
,
&
[
0x00
],
&
mut
buffer_4
)
i2c
.write_read
(
MPL115A2_ADDR
,
&
[
0x00
],
&
mut
buffer_4
)
.unwrap
();
.unwrap
();
asm
::
delay
(
1_000_000
);
// Calculate Pressure Compensation
// Calculate Pressure Compensation
let
pcomp
=
pcomp
(
buffer_4
,
coeffs
);
let
pcomp
=
pcomp
(
buffer_4
,
coeffs
);
...
...
This diff is collapsed.
Click to expand it.
src/rn_131rg.rs
+
46
−
40
View file @
f5c27c67
...
@@ -4,15 +4,17 @@ use stm32l4xx_hal::prelude::*;
...
@@ -4,15 +4,17 @@ use stm32l4xx_hal::prelude::*;
use
stm32l4xx_hal
::
rcc
::
*
;
use
stm32l4xx_hal
::
rcc
::
*
;
use
stm32l4xx_hal
::
serial
::
*
;
use
stm32l4xx_hal
::
serial
::
*
;
use
stm32l4xx_hal
::
stm32
::
*
;
use
stm32l4xx_hal
::
stm32
::
*
;
// use cortex_m_semihosting::hprint;
// use core::str::from_utf8;
use
core
::
fmt
::
Write
;
use
core
::
fmt
::
Write
;
use
cortex_m
::
asm
;
pub
struct
RnCon
{
pub
struct
RnCon
{
pub
tx
:
Tx
<
stm32l4xx_hal
::
pac
::
UART4
>
,
pub
tx
:
Tx
<
stm32l4xx_hal
::
pac
::
UART4
>
,
pub
rx
:
Rx
<
stm32l4xx_hal
::
pac
::
UART4
>
,
pub
rx
:
Rx
<
stm32l4xx_hal
::
pac
::
UART4
>
,
}
}
/// Helper function to get a struct used by other function
/// to communicate over UART with the wifi (RN-131g)
pub
fn
get_connexion
(
pub
fn
get_connexion
(
tx
:
Pin
<
Alternate
<
PushPull
,
8
>
,
L8
,
'A'
,
0
>
,
tx
:
Pin
<
Alternate
<
PushPull
,
8
>
,
L8
,
'A'
,
0
>
,
rx
:
Pin
<
Alternate
<
PushPull
,
8
>
,
L8
,
'A'
,
1
>
,
rx
:
Pin
<
Alternate
<
PushPull
,
8
>
,
L8
,
'A'
,
1
>
,
...
@@ -20,8 +22,8 @@ pub fn get_connexion(
...
@@ -20,8 +22,8 @@ pub fn get_connexion(
apb1r1
:
&
mut
APB1R1
,
apb1r1
:
&
mut
APB1R1
,
clocks
:
Clocks
,
clocks
:
Clocks
,
)
->
RnCon
{
)
->
RnCon
{
// create connexion struct
// create connexion struct
let
(
uart_tx
,
uart_rx
)
=
Serial
::
uart4
(
let
(
uart_tx
,
uart_rx
)
=
Serial
::
uart4
(
uart4
,
uart4
,
(
tx
,
rx
),
(
tx
,
rx
),
...
@@ -39,17 +41,26 @@ pub fn get_connexion(
...
@@ -39,17 +41,26 @@ pub fn get_connexion(
const
BUFFER_SIZE
:
usize
=
3
;
const
BUFFER_SIZE
:
usize
=
3
;
let
mut
buffer
:
[
u8
;
BUFFER_SIZE
]
=
[
0
;
BUFFER_SIZE
];
let
mut
buffer
:
[
u8
;
BUFFER_SIZE
]
=
[
0
;
BUFFER_SIZE
];
// start command mode
send
(
&
mut
uart
,
"$$$"
);
send
(
&
mut
uart
,
"$$$"
);
// check communication between microcontroller and wifi module, and start command mode
// check communication between microcontroller and wifi module
// (should receive <CMD> and only that)
wait_serial
(
&
mut
uart
,
&
mut
buffer
,
BUFFER_SIZE
);
wait_serial
(
&
mut
uart
,
&
mut
buffer
,
BUFFER_SIZE
);
assert_eq!
(
buffer
,
"CMD"
.as_bytes
());
assert_eq!
(
buffer
,
"CMD"
.as_bytes
());
// necessary to avoid "*HELLO*" string at connexion start
// necessary to avoid "*HELLO*" and "*OPEN*" string at connexion start
send
(
&
mut
uart
,
"set comm open 0
\r\n
"
);
send
(
&
mut
uart
,
"set comm remote 0
\r\n
"
);
send
(
&
mut
uart
,
"set comm remote 0
\r\n
"
);
send
(
&
mut
uart
,
"set comm match 1
\r\n
"
);
// create access point
// in case of probleme auto kill tcp connexion to avoid to stay stuck
send
(
&
mut
uart
,
"set comm idle 2
\r\n
"
);
// set port to avoid having to set it manually in the browser
send
(
&
mut
uart
,
"set ip localport 80
\r\n
"
);
send
(
&
mut
uart
,
"set ip localport 80
\r\n
"
);
// join wifi
send
(
&
mut
uart
,
"join RustWeatherStation
\r\n
"
);
send
(
&
mut
uart
,
"join RustWeatherStation
\r\n
"
);
// stop command mode, making connexion available for data transfer
// stop command mode, making connexion available for data transfer
...
@@ -58,21 +69,27 @@ pub fn get_connexion(
...
@@ -58,21 +69,27 @@ pub fn get_connexion(
return
uart
;
return
uart
;
}
}
/// Send plain str over the uart connexion to wifi module
pub
fn
send
(
con
:
&
mut
RnCon
,
s
:
&
str
)
{
pub
fn
send
(
con
:
&
mut
RnCon
,
s
:
&
str
)
{
con
.tx
.write_str
(
s
)
.unwrap
();
con
.tx
.write_str
(
s
)
.unwrap
();
}
}
/// Send str over the uart connexion to wifi module
/// This version allow for formatting through format_args! macro
/// # Examples
/// ```
/// format_args!(
/// "My name is {}", "David"
/// ),
/// ```
pub
fn
send_fmt
(
con
:
&
mut
RnCon
,
args
:
Arguments
<
'_
>
)
{
pub
fn
send_fmt
(
con
:
&
mut
RnCon
,
args
:
Arguments
<
'_
>
)
{
con
.tx
.write_fmt
(
args
)
.unwrap
();
con
.tx
.write_fmt
(
args
)
.unwrap
();
}
}
// pub fn print(buffer: &[u8]) {
/// Read on the uart connexion continuously,
// hprint!("{}", from_utf8(buffer).unwrap());
/// stopping on CRLF or buffer filed
// }
/// read on the uart connexion
///
pub
fn
wait_serial
(
con
:
&
mut
RnCon
,
buffer
:
&
mut
[
u8
],
buffer_size
:
usize
)
{
pub
fn
wait_serial
(
con
:
&
mut
RnCon
,
buffer
:
&
mut
[
u8
],
buffer_size
:
usize
)
{
let
mut
i
=
0
;
// char index
let
mut
i
=
0
;
// char index
...
@@ -96,38 +113,27 @@ pub fn wait_serial(con: &mut RnCon, buffer: &mut [u8], buffer_size: usize) {
...
@@ -96,38 +113,27 @@ pub fn wait_serial(con: &mut RnCon, buffer: &mut [u8], buffer_size: usize) {
}
}
}
}
pub
fn
wait_http_instant
(
con
:
&
mut
RnCon
)
{
/// Read the uart and wait until 'G' or 'P' is received
/// then return if it's 'G' or 'P' that was received
/// Knowing that will allow us to send only the data or
/// the full page based on browser request
pub
fn
wait_http
(
con
:
&
mut
RnCon
)
->
u8
{
let
c
;
loop
{
loop
{
match
con
.rx
.read
()
{
match
con
.rx
.read
()
{
Ok
(
x
)
=>
{
Ok
(
x
)
=>
{
if
x
==
b'G'
{
if
x
==
b'G'
{
c
=
b'G'
;
break
;
}
if
x
==
b'P'
{
c
=
b'P'
;
break
;
break
;
}
}
}
}
Err
(
_x
)
=>
{}
Err
(
_x
)
=>
{}
}
}
}
}
return
c
;
}
}
\ No newline at end of file
// pub fn wait_http(con: &mut RnCon, buffer: &mut [u8], buffer_size: usize) {
// let mut i = 0; // char index
// loop {
// match con.rx.read() {
// Ok(x) => {
// buffer[i] = x;
// if i > 3 && buffer[i - 3] == 13 && buffer[i] == 10 {
// // end of message, we flush
// break;
// }
// i += 1;
// if i >= buffer_size {
// break;
// }
// }
// Err(_x) => {}
// }
// }
// }
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