ring
This commit is contained in:
parent
eb4b23ade9
commit
8c61dbeaea
3 changed files with 42 additions and 5 deletions
27
Cargo.lock
generated
27
Cargo.lock
generated
|
|
@ -119,6 +119,26 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "const_format"
|
||||||
|
version = "0.2.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e3a214c7af3d04997541b18d432afaff4c455e79e2029079647e72fc2bd27673"
|
||||||
|
dependencies = [
|
||||||
|
"const_format_proc_macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "const_format_proc_macros"
|
||||||
|
version = "0.2.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c7f6ff08fd20f4f299298a28e2dfa8a8ba1036e6cd2460ac1de7b425d76f2500"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-xid",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-isa-parser"
|
name = "core-isa-parser"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
|
@ -1077,6 +1097,7 @@ checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47"
|
||||||
name = "rusty-bell"
|
name = "rusty-bell"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"const_format",
|
||||||
"embassy-executor",
|
"embassy-executor",
|
||||||
"embassy-net",
|
"embassy-net",
|
||||||
"embassy-net-driver",
|
"embassy-net-driver",
|
||||||
|
|
@ -1301,6 +1322,12 @@ version = "1.0.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-xid"
|
||||||
|
version = "0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vcell"
|
name = "vcell"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ static_cell = { version = "2.0.0", features = ["nightly"] }
|
||||||
embassy-net = { version = "0.4.0", features = ["dhcpv4", "proto-ipv4", "tcp"] }
|
embassy-net = { version = "0.4.0", features = ["dhcpv4", "proto-ipv4", "tcp"] }
|
||||||
embedded-io-async = "0.6.1"
|
embedded-io-async = "0.6.1"
|
||||||
embassy-net-driver = "0.2.0"
|
embassy-net-driver = "0.2.0"
|
||||||
|
const_format = "0.2.32"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
# Rust debug is too slow.
|
# Rust debug is too slow.
|
||||||
|
|
|
||||||
19
src/main.rs
19
src/main.rs
|
|
@ -7,6 +7,7 @@ use embassy_net::tcp::TcpSocket;
|
||||||
use embassy_net::{Config, Ipv4Address, Stack, StackResources};
|
use embassy_net::{Config, Ipv4Address, Stack, StackResources};
|
||||||
use esp_hal;
|
use esp_hal;
|
||||||
|
|
||||||
|
use const_format::formatcp;
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
use esp_backtrace as _;
|
use esp_backtrace as _;
|
||||||
use esp_hal::clock::ClockControl;
|
use esp_hal::clock::ClockControl;
|
||||||
|
|
@ -92,20 +93,28 @@ async fn main(spawner: Spawner) -> ! {
|
||||||
|
|
||||||
socket.set_timeout(Some(embassy_time::Duration::from_secs(10)));
|
socket.set_timeout(Some(embassy_time::Duration::from_secs(10)));
|
||||||
|
|
||||||
let remote_endpoint = (Ipv4Address::new(142, 250, 185, 115), 80);
|
let remote_endpoint = (Ipv4Address::new(104, 20, 43, 236), 80);
|
||||||
println!("connecting...");
|
println!("connecting...");
|
||||||
let r = socket.connect(remote_endpoint).await;
|
let r = socket.connect(remote_endpoint).await;
|
||||||
if let Err(e) = r {
|
if let Err(e) = r {
|
||||||
println!("connect error: {:?}", e);
|
println!("connect error: {:?}", e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const json: &'static str = "{
|
||||||
|
\"token\": \"ahgvt9acdx5sowxfobadt9cmpqhrzp\",
|
||||||
|
\"user\": \"ud2btptjwvy92xi8y77tfurfew6z7a\",
|
||||||
|
\"message\": \"DOOR BELL!!!\"
|
||||||
|
}";
|
||||||
|
const json_len: usize = json.len();
|
||||||
|
|
||||||
println!("connected!");
|
println!("connected!");
|
||||||
let mut buf = [0; 1024];
|
let mut buf = [0; 1024];
|
||||||
loop {
|
loop {
|
||||||
use embedded_io_async::Write;
|
use embedded_io_async::Write;
|
||||||
let r = socket
|
let req = formatcp!("POST /1/messages.json HTTP/1.0\r\nHost: api.pushover.net\r\nContent-Type: application/json\r\nContent-Length: {}\r\n\r\n{}\r\n\r\n", json_len, json);
|
||||||
.write_all(b"GET / HTTP/1.0\r\nHost: www.mobile-j.de\r\n\r\n")
|
println!("{}", req);
|
||||||
.await;
|
let r = socket.write_all(req.as_bytes()).await;
|
||||||
if let Err(e) = r {
|
if let Err(e) = r {
|
||||||
println!("write error: {:?}", e);
|
println!("write error: {:?}", e);
|
||||||
break;
|
break;
|
||||||
|
|
@ -123,7 +132,7 @@ async fn main(spawner: Spawner) -> ! {
|
||||||
};
|
};
|
||||||
println!("{}", core::str::from_utf8(&buf[..n]).unwrap());
|
println!("{}", core::str::from_utf8(&buf[..n]).unwrap());
|
||||||
}
|
}
|
||||||
Timer::after(Duration::from_millis(3000)).await;
|
Timer::after(Duration::from_millis(5000)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue