commit a3a76d8eb99b94188f10842ba155bbb910119d03 parent 616d58d4adb0a51c9b3a9f710501c9a7a2dee3a2 Author: filipton <filipton12@gmail.com> Date: Thu, 4 Jul 2024 21:54:32 +0200 docs: added example to README Diffstat:
| M | README.md | | | 42 | ++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 42 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md @@ -4,6 +4,48 @@ OTA for esp-hal (no-std). ## Limitations For now only works on esp32s3 (esp32c3 in the near future). +## Example +This example uses embassy-net for TcpSocket, as you can see ota doesn't use +async so you can easily use it with smoltcp. + +```rust +let mut ota_buff = [0; 4096]; +socket + .read(&mut ota_buff[..4]) + .await + .expect("Cannot read firmware size!"); + +let flash_size = u32::from_le_bytes(ota_buff[..4].try_into().unwrap()); +log::info!("flash_size: {flash_size}"); + +let mut ota = Ota::new(FlashStorage::new()).with_next_partition_offset(); +ota.set_flash_size(flash_size); + +let mut bytes_read = 0; +loop { + let res = socket.read(&mut ota_buff).await; + if let Ok(n) = res { + bytes_read += n; + if n == 0 { + break; + } + + let res = ota.ota_write_chunk(&ota_buff[..n]); + if bytes_read % 4096 == 0 { + _ = socket.write(&[0]).await; + } + + if res == Ok(true) { + _ = ota.ota_flush(); + break; + } + } + + Timer::after_millis(10).await; + log::info!("Progress: {}%", (ota.get_ota_progress() * 100.0) as u8); +} +``` + ## Todo - [ ] Fully working library - [ ] Partitions macro (to generate PARTITIONS const at compile time)