Skip to content

Commit

Permalink
Merge pull request #5 from Kezii/upd
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
Kezii authored Mar 16, 2024
2 parents 1670f01 + 9135084 commit ccd1dbd
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ build-std = ["std", "panic_abort"]
[env]
MCU="esp32"
# Note: this variable is not used by the pio builder (`cargo build --features pio`)
ESP_IDF_VERSION = "v5.1.1"
ESP_IDF_VERSION = "v5.2.1"

CARGO_WORKSPACE_DIR = { value = "", relative = true }
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
default: true
ldproxy: true
- name: Run cargo check
run: cargo check
run: cargo check --bins --examples
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
/target
/Cargo.lock

wifi_pass.txt
wifi_ssid.txt
examples/telegram_bot/bot_token.txt
examples/telegram_bot/owner_id.txt
cfg.toml
15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,28 @@ embassy = ["esp-idf-svc/embassy-sync", "esp-idf-svc/critical-section", "esp-idf-

[dependencies]
log = { version = "0.4", default-features = false }
esp-idf-svc = { version = "0.47", default-features = false }
embedded-svc = "0.26.4"
esp-idf-svc = { version = "0.48", default-features = false }
embedded-svc = "0.27.1"
anyhow = "1.0.79"

bstr = { version = "1.8.0", default-features = false }
esp32-nimble = "0.5.0"
esp32-nimble = "0.6.0"
tokio = { version = "*", features = ["rt", "time", "sync","macros"] }
lazy_static = "1.4.0"
uuid = { version = "1.2.2", default-features = false, features = ["macro-diagnostics"] }
rgb565 = "0.1.3"
image = "0.24.8"
image = "0.25"
frankenstein = { version = "0.30", default-features = false, features = ["telegram-trait"]}
serde = { version = "1", features = ["derive"]}
serde_json = { version = "1"}

idotmatrix = {git = "https://github.com/Kezii/idotmatrix.git"}
esp-idf-hal = "*"
esp-idf-sys = "*"
esp-idf-hal = "0.43"
esp-idf-sys = "0.34"
thiserror = "1.0.56"

toml-cfg = "=0.1.3"

[[package.metadata.esp-idf-sys.extra_components]]
component_dirs = "components/esp32-camera"
bindings_header = "components/bindings.h"
Expand All @@ -54,3 +56,4 @@ bindings_module = "camera"

[build-dependencies]
embuild = "0.31.3"
toml-cfg = "=0.1.3"
17 changes: 17 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#[toml_cfg::toml_config]
pub struct Config {
#[default("")]
wifi_ssid: &'static str,
#[default("")]
wifi_psk: &'static str,
#[default("")]
bot_token: &'static str,
#[default(0)]
owner_id: i64,
}

fn main() {
// Check if the `cfg.toml` file exists and has been filled out.
if !std::path::Path::new("cfg.toml").exists() {
panic!("You need to create a `cfg.toml` file with your Wi-Fi credentials! Use `cfg.toml.example` as a template.");
}

embuild::espidf::sysenv::output();
}
5 changes: 5 additions & 0 deletions cfg.toml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[espcam]
wifi_ssid = "FBI Surveillance Van"
wifi_psk = "hunter2"
bot_token = "change_me"
bot_owner_id = 12345678
2 changes: 1 addition & 1 deletion components_esp32.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dependencies:
component_hash: null
source:
type: idf
version: 5.1.1
version: 5.2.1
manifest_hash: 3e6980bc5fca475de2a39d94c3ea3944c0528040d862609e810d1d8f5ea7f661
target: esp32
version: 1.0.0
12 changes: 6 additions & 6 deletions examples/idotmatrix/idotmatrixble.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::Camera;
use anyhow::Result;
use bstr::ByteSlice;
use esp32_nimble::{uuid128, BLEClient, BLEDevice, BLEReturnCode};
use esp32_nimble::{uuid128, BLEClient, BLEDevice, BLEError};
use esp_idf_sys::camera;
use espcam::espcam::FrameBuffer;
use image::{ImageBuffer, ImageOutputFormat, Rgb};
use image::{ImageBuffer, ImageFormat, Rgb};
use log::{error, info};

pub struct IDMBle<'a> {
Expand All @@ -15,7 +15,7 @@ impl<'a> IDMBle<'a> {
pub async fn new(
ble_device: &'a BLEDevice,
client: &'a mut BLEClient,
) -> Result<Self, BLEReturnCode> {
) -> Result<Self, BLEError> {
let ble_scan = ble_device.get_scan();

info!("Scanning for BLE devices...");
Expand Down Expand Up @@ -44,11 +44,11 @@ impl<'a> IDMBle<'a> {
Ok(Self { characteristic })
} else {
error!("No device found");
Err(BLEReturnCode::fail().unwrap_err())
Err(BLEError::fail().unwrap_err())
}
}

pub async fn send_data(&mut self, bytes: &[u8]) -> Result<(), BLEReturnCode> {
pub async fn send_data(&mut self, bytes: &[u8]) -> Result<(), BLEError> {
for (counter, chunk) in bytes.chunks(512).enumerate() {
let succ = self.characteristic.write_value(chunk, true).await;
info!("progress: {}%", (counter * chunk.len()) * 100 / bytes.len());
Expand Down Expand Up @@ -90,7 +90,7 @@ pub async fn idotmatrix_stream_task(camera: Camera<'_>) -> Result<()> {
let mut c = std::io::Cursor::new(Vec::new());

info!("Writing png");
scaled.write_to(&mut c, ImageOutputFormat::Png).unwrap();
scaled.write_to(&mut c, ImageFormat::Png).unwrap();

info!("Creating command");
let command = idotmatrix::IDMCommand::UploadPng(c.into_inner());
Expand Down
16 changes: 10 additions & 6 deletions examples/telegram_bot/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::{bail, Result};
use bot_api::{telegram_post_multipart, Esp32Api};
use esp_idf_hal::gpio::PinDriver;
use esp_idf_svc::{eventloop::EspSystemEventLoop, hal::peripherals::Peripherals};
use espcam::{espcam::Camera, wifi_handler::my_wifi};
use espcam::{config::get_config, espcam::Camera, wifi_handler::my_wifi};
use frankenstein::{
ForwardMessageParams, GetUpdatesParams, SendChatActionParams, SendMessageParams, TelegramApi,
};
Expand All @@ -29,10 +29,14 @@ fn main() -> Result<()> {
let mut flash_led = PinDriver::output(peripherals.pins.gpio4).unwrap();
flash_led.set_low().unwrap();

let wifi_ssid = include_str!("../../wifi_ssid.txt");
let wifi_pass = include_str!("../../wifi_pass.txt");
let config = get_config();

let _wifi = match my_wifi(wifi_ssid, wifi_pass, peripherals.modem, sysloop) {
let _wifi = match my_wifi(
config.wifi_ssid,
config.wifi_psk,
peripherals.modem,
sysloop,
) {
Ok(inner) => inner,
Err(err) => {
bail!("Could not connect to Wi-Fi network: {:?}", err)
Expand Down Expand Up @@ -63,8 +67,8 @@ fn main() -> Result<()> {
let mut bot_state = BotState {
should_use_flash: false,
public_use: false,
owner_id: include_str!("owner_id.txt").parse().unwrap(),
bot_token: include_str!("bot_token.txt"),
owner_id: config.bot_owner_id,
bot_token: config.bot_token,
};

let api = Esp32Api::new(bot_state.bot_token);
Expand Down
16 changes: 10 additions & 6 deletions examples/webserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use esp_idf_svc::{
hal::peripherals::Peripherals,
http::{server::EspHttpServer, Method},
};
use espcam::{espcam::Camera, wifi_handler::my_wifi};
use espcam::{config::get_config, espcam::Camera, wifi_handler::my_wifi};

fn main() -> Result<()> {
esp_idf_svc::sys::link_patches();
Expand All @@ -16,10 +16,14 @@ fn main() -> Result<()> {

let peripherals = Peripherals::take().unwrap();

let wifi_ssid = include_str!("../wifi_ssid.txt");
let wifi_pass = include_str!("../wifi_pass.txt");
let config = get_config();

let _wifi = match my_wifi(wifi_ssid, wifi_pass, peripherals.modem, sysloop) {
let _wifi = match my_wifi(
config.wifi_ssid,
config.wifi_psk,
peripherals.modem,
sysloop,
) {
Ok(inner) => inner,
Err(err) => {
bail!("Could not connect to Wi-Fi network: {:?}", err)
Expand Down Expand Up @@ -66,13 +70,13 @@ fn main() -> Result<()> {
response.write_all("no framebuffer".as_bytes())?;
}

Ok(())
Ok::<(), anyhow::Error>(())
})?;

server.fn_handler("/", Method::Get, |request| {
let mut response = request.into_ok_response()?;
response.write_all("ok".as_bytes())?;
Ok(())
Ok::<(), anyhow::Error>(())
})?;

loop {
Expand Down
11 changes: 9 additions & 2 deletions src/ble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::Duration;

use anyhow::bail;
use esp32_nimble::utilities::BleUuid;
use esp32_nimble::{BLEAdvertising, BLEScan, BLEServer, NimbleProperties};
use esp32_nimble::{BLEAdvertisementData, BLEAdvertising, BLEScan, BLEServer, NimbleProperties};
use lazy_static::lazy_static;
use log::{info, warn};
use tokio::select;
Expand Down Expand Up @@ -52,7 +52,14 @@ pub async fn ble_advertise_task(
);
notifying_characteristic.lock().set_value(b"uptime: 0");

advertising.name(name).add_service_uuid(*UUID_BLE_SERVICE);
// advertising.name(name).add_service_uuid(*UUID_BLE_SERVICE);
advertising
.set_data(
BLEAdvertisementData::new()
.name(name)
.add_service_uuid(*UUID_BLE_SERVICE),
)
.unwrap();

advertising.start().expect("ble_advertising.start()");

Expand Down
15 changes: 15 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#[toml_cfg::toml_config]
pub struct Config {
#[default("")]
wifi_ssid: &'static str,
#[default("")]
wifi_psk: &'static str,
#[default("")]
bot_token: &'static str,
#[default(0)]
bot_owner_id: i64,
}

pub fn get_config() -> Config {
CONFIG
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod ble;
pub mod config;
pub mod espcam;
pub mod wifi_handler;
8 changes: 6 additions & 2 deletions src/wifi_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ pub fn my_wifi(
};

wifi.set_configuration(&Configuration::Client(ClientConfiguration {
ssid: ssid.into(),
password: pass.into(),
ssid: ssid
.try_into()
.expect("SSID could not be converted to heapless String"),
password: pass
.try_into()
.expect("Password could not be converted to heapless String"),
channel,
auth_method,
..Default::default()
Expand Down

0 comments on commit ccd1dbd

Please sign in to comment.