Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable allocations for reqwless #15

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,4 @@ rustflags = [
target = "riscv32imc-unknown-none-elf"

[unstable]
build-std = [
# "alloc",
"core",
]
build-std = ["alloc", "core"]
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ esp-hal-embassy = { version = "0.1.0", features = [
"time-timg0",
] }

esp-backtrace = { version = "0.12.0", features = [
esp-backtrace = { version = "0.12.1", features = [
"exception-handler",
"panic-handler",
"println",
Expand Down Expand Up @@ -59,15 +59,15 @@ embedded-graphics = { version = "0.8.1", features = ["nalgebra_support"] }


#higher level embedded-hal traits for wifi, bluetooth, ect
embedded-svc = { version = "0.27.1", default-features = false, optional = true }
embedded-svc = { version = "0.28.0", default-features = false, optional = true }
embedded-io = "0.6.1"
embedded-io-async = "0.6.1"
embedded-hal = "1.0.0"
embedded-hal-async = "^1.0"
embedded-hal-bus = { version = "0.2.0", features = ["async"] }

# no_std http/s requests.
reqwless = { version = "0.12.0", optional = true }
reqwless = { version = "0.12.0", optional = true, features = ["alloc"] }

# heapless = { version = "0.8.0", default-features = false }

Expand Down Expand Up @@ -109,7 +109,7 @@ overflow-checks = false
opt-level = 3

[features]
default = ["log", "net"]
default = ["log", "net", "alloc"]

alloc = ["dep:esp-alloc"]

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

// #[cfg(feature = "adc")]
// pub mod adc;
// #[cfg(feature = "alloc")]
// pub mod alloc;
#[cfg(feature = "alloc")]
pub mod alloc;
pub mod blink;
pub mod display;
pub mod errors;
Expand Down
29 changes: 18 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ async fn main(spawner: Spawner) -> ! {
info!("Logger is setup");
println!("Hello world!");

// #[cfg(feature = "alloc")]
// spotify_mini::alloc::init_heap();
#[cfg(feature = "alloc")]
teeny::alloc::init_heap();

let peripherals = Peripherals::take();

Expand Down Expand Up @@ -189,11 +189,18 @@ async fn main(spawner: Spawner) -> ! {

debug!("HttpClient created");

let token = "TOKEN_GOES_HERE";

let mut string: String<64> = String::new();

string.push_str("Bearer ").unwrap();
string.push_str(token).unwrap();

let headers = [
("user-agent", "teeny/0.1.0"),
("Host", "example.com"),
("accept", "application/json"),
// ("connection", "close"),
("User-Agent", "teeny/0.1.0"),
("Accept", "*/*"),
("Connection", "close"),
("Authorization", string.as_str()),
];

let mut header_buf = [0; 1024];
Expand All @@ -202,25 +209,25 @@ async fn main(spawner: Spawner) -> ! {
.request(Method::GET, "https://example.com")
.await
.unwrap()
.content_type(reqwless::headers::ContentType::TextPlain)
.path("/v1/artists/0TnOYISbd1XYRBk9myaseg")
.headers(&headers);

debug!("Request sent");

let response = request.send(&mut header_buf).await.unwrap();

debug!("Request sent");

let content_len = response.content_length.unwrap();

debug!("Response Recieved");

let mut buf = [0; 50 * 1024];

if let Err(e) = response.body().reader().read_to_end(&mut buf).await {
error!("{e:?}");
error!("Error: {e:?}");
break;
}

print!("{:#?}", core::str::from_utf8(&buf[..content_len]).unwrap());
println!("{:#?}", core::str::from_utf8(&buf[..content_len]).unwrap());

Timer::after(Duration::from_secs(3)).await;
}
Expand Down