This project showcases the capabilities of Rust, a system programming language known for its safety and performance, in the realm of Internet of Things (IoT) by using a PicoW as the embedded device. It aims to provide a concise example of how Rust can be utilized to develop IoT applications. Leveraging the PicoW's Wi-Fi connectivity the project demonstrates real-world IoT scenarios, including sensor data collection, and seamless data communication over the internet. This initiative not only highlights Rust's suitability for embedded systems but also serves as a stepping stone for developers looking to explore IoT development.
The setup consists of the components:
-
PicoW Sensor (
picow-temperature-sensor)As sample data the temperature is measured periodically.
The value is forwarded to the IoT Data Bridge via Wifi and TCP. -
Sensor Simulator (
sensor-simulator)If no PicoW is available you can also use a sensor simulator.
-
IoT Data Bridge (
iot-data-bridge)Acts as a bridge for data, receiving temperature readings from the sensor and forwarding them to a sqlite database.
-
Sqlite DB
As datastorage a filebased sqlite database is used accessed from rust with
iot-db-accessor. -
IoT WebServer and WebPage (
iot-webserver)serves the web services and a web page with a dashboard of the sensor data.
-
IoT Explorer (
iot-explorer)A CLI application that lists the sensor data and can also create testdata.
When new sensor data becomes available in the database, the iot-explorer and "IoT WebPage" automatically update whenever they are open.
rustup toolchain update stable
Building is separated into two steps:
Pico part and the host part (everything else).
So if you have no PicoW you can test it with the sensor-simulator.
If you use vscode with for the described steps are corresponding tasks configured (in [[.vscode/tasks.json]]). This can be executed with Ctrl+Shift+B ("Run Tasks").
cargo commands from the project root. Otherwise, the database will not be found, as it is configured via a relative path.
cargo install sqlx-clicargo buildStart in one bash terminal the iot-webserver (or with vscode excute task "01-iot-webserver"):
cargo run --bin iot-webserverAfter starting the iot-webserver, you will see a link to the dashboard page, e.g.: http://localhost:3000
To see what's going on behind the scenes start with tracing:
RUST_LOG=DEBUG cargo run --bin iot-webserverYou can also view the latest data via cli (or with vscode excute task "02-iot-explorer"):
cargo run --bin iot-explorer last --followWith cargo run --bin iot-explorer you see the help page.
With cargo run --bin iot-explorer help last you see the help page for the last command.
Start in one bash terminal the iot-data-bridge (or with vscode excute task "03-iot-data-bridge"):
cargo run --bin iot-data-bridgesensor-simulator, OR b) picow-temperature-sensor
Start in one bash terminal the sensor-simulator (or with vscode excute task "04a-sensor-simulator"):
cargo run --release --bin sensor-simulatorThis project is not part of the cargo workspace.
To provision the Wi-Fi for the PicoW, please consider the following preconditions for the Wi-Fi:
- Security: Ensure your Wi-Fi network supports WPA2 encryption.
- Network Restrictions:
- Captive Portal: If your network requires a login page (captive portal) after connecting, the Pico W may not be able to automatically handle it.
- Network Access Control (NAC) / MAC Address Filtering: These security features may prevent the Pico W from joining the network unless its MAC address is manually authorized.
Workaround for Restrictions:
If you encounter network restrictions, consider setting up a Wi-Fi bridge on your host computer with a Wi-Fi adapter (stick) to create an unrestricted network for the PicoW to connect to.
Please ensure that you have set up the rust development environment for the PicoW and tested it, e.g. by running the blinky example from the embassy project (details here)
.env file and complete the TODOs, i.e. set WIFI SSID and password for the WLAN that is used to connect to the PicoW as well as the installation directory of embassy.
Use the following terminal commands (or with vscode excute task "04b-picow-temperature-sensor"):
cd picow-temperature-sensor
cargo run --releaseAfter flashing the Pico tries to periodically send data to the iot-data-bridge. To stop this, disconnect the power cable.
