Expand description
Fundamentum EdgeMCU HTTP Client Library.
§Usage
//! Example showcasing basic usage for this library
use fundamentum_edge_mcu_http_client::{
http_client_config::HttpClientConfig,
models::{DeviceFQN, DeviceIdentity, Empty, HttpRequest, ProvisionResponse, RegistryFQN},
FundamentumApi, HttpClientErrorWrapper, HttpHandler, ProvisionMode,
};
const REGISTRY_ACCESS_TOKEN: &str = "";
const PUBLIC_RSA_KEY: &str = "";
const SERIAL_NUMBER: &str = "serial_number_1";
const ASSET_TYPE_ID: i32 = 1;
const BUFFER_SIZE: usize = 2048;
struct SomeHttpHandler;
#[derive(defmt::Format)]
struct SomeHttpHandlerError;
impl HttpHandler for SomeHttpHandler {
type Error = SomeHttpHandlerError;
async fn http_call<'a, 'd>(
&'a self,
_request: HttpRequest<'_>,
_out_buffer: &'d mut [u8],
) -> Result<(), Self::Error> {
Ok(())
}
}
#[tokio::main]
async fn main() {
// Setup device and registry
let device_fqn = DeviceFQN {
registry_fqn: RegistryFQN {
project_id: 1,
region_id: 1,
registry_id: 1,
},
serial_number: SERIAL_NUMBER,
};
// Initialize the Fundamentum API access point
let api = FundamentumApi::new(HttpClientConfig::default(), SomeHttpHandler);
let mut response_buffer = [0; BUFFER_SIZE];
let device_identity = DeviceIdentity::Rsa256 {
public_key: PUBLIC_RSA_KEY,
};
// Perform the provisioning call on the [`HttpHandler`]
let _provision_result: Result<
ProvisionResponse<Empty>,
HttpClientErrorWrapper<'_, SomeHttpHandler>,
> = api
.provisioning_api()
.provision(
&device_fqn,
ASSET_TYPE_ID,
REGISTRY_ACCESS_TOKEN,
&device_identity,
ProvisionMode::Normal,
&mut response_buffer,
)
.await;
}
Modules§
- api_
version - The various version of the Fundamentum API this library supports. More information in the documentation.
- http_
client_ config - HTTP client’s configuration to be used when making calls to the Fundamentum API.
- models
- Fundamentum API’s models to interact with the API and the HTTP client.
Structs§
- Fundamentum
Api - User facing structure to make calls to the Fundamentum API.
- Http
Client - Client wrapping a
HttpHandler
structure to to perform requests with the Fundamentum API for a specific version. - Provisioning
Api - Provisioning section of the devices API. More information in the documentation and swagger.
Enums§
- Http
Client Error - Errors that might get returned by the
HttpClient
. - Http
Client Error Wrapper - Errors with the error message returned by
HttpClient
. - Provision
Mode - Indicates the provisioning mode.
Traits§
- Http
Handler - Types which are able to perform an HTTP request to a Web server.