This project is a backend canister written in Rust for a Smart Watering System. It monitors soil moisture levels and controls a water pump to automatically water the plants as needed. The canister is deployed on the Internet Computer (IC) blockchain.
sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup update stable
rustup target add wasm32-unknown-unknowngit clone https://github.com/Jud-et/rust_1.git
cd rust_1Edit Cargo.toml to include the necessary dependencies:
[package]
name = "smart_watering_system"
version = "0.1.0"
edition = "2018"
[dependencies]
ic-cdk = "0.14.0"
ic-cdk-macros = "0.14.0"
candid = "0.10.9"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
[lib]
crate-type = ["cdylib"]Edit src/lib.rs.
Build the project and generate the Candid interface file:
cargo build --target wasm32-unknown-unknown --release
cargo test -- --nocaptureThis will run the test that generates the rust_1_backend.did file in your project directory.
Edit dfx.json to include the Candid interface file:
{
"canisters": {
"smart_watering_system": {
"main": "src/smart_watering_system/src/lib.rs",
"type": "rust",
"candid": "src/smart_watering_system/smart_watering_system.did"
}
},
"networks": {
"local": {
"bind": "127.0.0.1:8000",
"type": "ephemeral"
}
},
"version": 1
}Deploy your canister to the local Internet Computer instance:
dfx deploydfx canister call rust_1_backend update_moisture_level '(30.5)'dfx canister call rust_1_backend get_moisture_leveldfx canister call rust_1_backend get_moisture_logdfx canister call rust_1_backend control_pump '(true)' # Turn on the pump
dfx canister call rust_1_backend control_pump '(false)' # Turn off the pumpdfx canister call rust_1_backend get_pump_state