This is an extension crate for the datex-core crate that provides interfaces and helpers for running DATEX on embedded targets.
This crate is nostd-compatible and supports various embedded targets, including:
- ESP32
To get started, add this crate to you project with cargo add datex-core-embedded.
This crate has no default feature flags, so to use it, you probably want to enable additional features:
wifi: When you enable this feature, you get helper functions for all supported targets to initialize a runtime with a Wifi connection. This feature is required and automatically enabled by features likewebsocket-client, that need a network connection.debug: This flag enables thedebugflag for the DATEX core crate, providing some additional debug functionalities,websocket-client: This flag enables theWebSocketClientInterfaceEmbeddedcom interface implementation for the DATEX runtime. When using an initialization function likeinit_runtime_with_wifi, the com interface will automatically be registered and can be used.esp: This flag must be enabled when building for an ESP32 target. It is automatically enabled if a more specific ESP32 target feature (e.gesp32s3) is activated.
To build for an ESP32 target, enable the feature flag for your specific target.
Full list of ESP32 target feature flags
esp32esp32s3
The datex_core_embedded::main macro provides an easy way to use an async main function with an initialized DATEX runtime:
#![no_std]
#![no_main]
use datex_core::runtime::Runtime;
#[datex_core_embedded::main("../config.dx")]
async fn main(runtime: Runtime) {
info!("DATEX runtime version: {}", runtime.version);
// do some stuff
}Note that you need to specify a path to a DATEX config file for your endpoint. Here is a simple example config file that defines Wifi credentials and a websocket server to connect to:
{
endpoint: @mymicrocontroller,
interfaces: [
{
type: "websocket-client",
config: {
address: "wss://example.unyt.land"
}
}
],
env: [
["wifi_ssid", "MY_WIFI"],
["wifi_password", "MY_PASSWORD"]
]
}To initialize a new runtime instance, you can also use init_runtime_with_wifi/init_runtime_without_wifi:
use datex_core_embedded::esp::init::init_runtime_with_wifi;
use datex_core::logger::{init_logger};
let spawner: embassy_executor::Spawner = ...;
let peripherals: esp_hal::peripherals::Peripherals = ...;
init_logger();
let (runtime, stack) = init_runtime_with_wifi(
spawner,
peripherals,
WifiCredentials { ssid, password },
RuntimeConfig {endpoint: Some(Endpoint::new("@myesp")), interfaces: Some(vec![
RuntimeConfigInterface::new(
"websocket-client",
WebSocketClientInterfaceSetupData {
address: "wss://example.unyt.land".to_string()
}
).unwrap()
]), debug: Some(true)}
).await;
info!("runtime version: {}", runtime.version);