This commit is contained in:
Jaroslaw Konik 2024-04-09 20:25:59 +02:00
parent eb4b23ade9
commit 8c61dbeaea
3 changed files with 42 additions and 5 deletions

27
Cargo.lock generated
View file

@ -119,6 +119,26 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "core-isa-parser"
version = "0.2.0"
@ -1077,6 +1097,7 @@ checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47"
name = "rusty-bell"
version = "0.1.0"
dependencies = [
"const_format",
"embassy-executor",
"embassy-net",
"embassy-net-driver",
@ -1301,6 +1322,12 @@ version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-xid"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "vcell"
version = "0.1.3"

View file

@ -21,6 +21,7 @@ static_cell = { version = "2.0.0", features = ["nightly"] }
embassy-net = { version = "0.4.0", features = ["dhcpv4", "proto-ipv4", "tcp"] }
embedded-io-async = "0.6.1"
embassy-net-driver = "0.2.0"
const_format = "0.2.32"
[profile.dev]
# Rust debug is too slow.

View file

@ -7,6 +7,7 @@ use embassy_net::tcp::TcpSocket;
use embassy_net::{Config, Ipv4Address, Stack, StackResources};
use esp_hal;
use const_format::formatcp;
use embassy_time::{Duration, Timer};
use esp_backtrace as _;
use esp_hal::clock::ClockControl;
@ -92,20 +93,28 @@ async fn main(spawner: Spawner) -> ! {
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...");
let r = socket.connect(remote_endpoint).await;
if let Err(e) = r {
println!("connect error: {:?}", e);
continue;
}
const json: &'static str = "{
\"token\": \"ahgvt9acdx5sowxfobadt9cmpqhrzp\",
\"user\": \"ud2btptjwvy92xi8y77tfurfew6z7a\",
\"message\": \"DOOR BELL!!!\"
}";
const json_len: usize = json.len();
println!("connected!");
let mut buf = [0; 1024];
loop {
use embedded_io_async::Write;
let r = socket
.write_all(b"GET / HTTP/1.0\r\nHost: www.mobile-j.de\r\n\r\n")
.await;
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);
println!("{}", req);
let r = socket.write_all(req.as_bytes()).await;
if let Err(e) = r {
println!("write error: {:?}", e);
break;
@ -123,7 +132,7 @@ async fn main(spawner: Spawner) -> ! {
};
println!("{}", core::str::from_utf8(&buf[..n]).unwrap());
}
Timer::after(Duration::from_millis(3000)).await;
Timer::after(Duration::from_millis(5000)).await;
}
}