You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using reqwless 0.13.0 on an esp32-c6 dev board. I've got all default features turned off and only the embedded-tls and log features turned on. I'm suing embedded-tls 0.17.0. I'm taking an environmental reading (pressure, humidity and temperature) using a BME280. Then this data should be send to Grafana cloud via the Influx protocol.
use core::fmt::Write;use embassy_net::tcp::client::TcpClientState;use embassy_net::Stack;use embassy_net::{dns::DnsSocket, tcp::client::TcpClient};use embassy_sync::channel::Sender;use embassy_sync::{blocking_mutex::raw::NoopRawMutex, channel::Receiver};use heapless::String;use hifitime::Epoch;use log::info;use log::{debug, error};use rand_core::RngCoreas _;use reqwless::client::{HttpClient,TlsConfig,TlsVerify};use reqwless::{
headers::ContentType,
request::{Method,RequestBuilder},};use thiserror::Error;use uom::si::pressure::pascal;use uom::si::{pressure::hectopascal, ratio::percent, thermodynamic_temperature::degree_celsius};constGRAFANA_CLOUD_URL:&str = "https://influx-prod-41-prod-au-southeast-1.grafana.net/api/v1";constGRAFANA_USER_NAME:&str = "my-user";constGRAFANA_API_KEY:&str = env!("GRAFANA_METRICS_API_KEY");/// A clock error#[derive(Error,Debug)]pubenumError{#[error("The response code does not indicate success.")]NonSuccessResponseCode,#[error("The request failed to send.")]RequestFailed,}#[derive(Clone,Debug,Default)]pubstructEnvironmentalData{/// Temperaturepubtemperature:Temperature,/// Humiditypubhumidity:Humidity,/// Air Pressurepubpressure:Pressure,}/// A reading, i.e. a pair (time, sample)pubtypeReading = (Epoch,EnvironmentalData);// Use the influx line protocol from here: https://docs.influxdata.com/influxdb/v1/write_protocols/line_protocol_tutorial/fnformat_metrics(boot_count:u32,environmental_data:Reading) -> String<512>{letmut buffer:String<512> = String::new();
buffer
}asyncfnsend_data_to_grafana<'a>(stack:Stack<'a>,rng_wrapper:&mutRngWrapper,boot_count:u32,environmental_data:Reading,) -> Result<(),Error>{info!("Sending data to grafana ...");let metrics = format_metrics(boot_count, environmental_data);let bytes = metrics.as_bytes();let dns_socket = DnsSocket::new(stack);let tcp_client_state = TcpClientState::<1,4096,4096>::new();let tcp_client = TcpClient::new(stack,&tcp_client_state);let seed = rng_wrapper.next_u64();letmut read_record_buffer = [0_u8;16640];letmut write_record_buffer = [0_u8;16640];let tls_config = TlsConfig::new(
seed,&mut read_record_buffer,&mut write_record_buffer,TlsVerify::None,);debug!("Creating HTTP client ...");letmut client = HttpClient::new_with_tls(&tcp_client,&dns_socket, tls_config);debug!("Creating request ...");letmut rx_buf = [0;4096];letmut resource = client.resource(GRAFANA_CLOUD_URL).await.unwrap();let response = resource
.post("push/influx/write").content_type(ContentType::TextPlain).basic_auth(GRAFANA_USER_NAME,GRAFANA_API_KEY).body(bytes);debug!("Sending request ...");let response = response.send(&mut rx_buf).await;debug!("Processing response ...");match response {Ok(r) => {if r.status.is_successful(){debug!("Send data to grafana. Status code: {:?}", r.status);Ok(())}else{error!("Failed to send data to grafana: Status code {:?}", r.status,);Err(Error::NonSuccessResponseCode)}}Err(e) => {error!("Failed to send data to grafana: error {:?}", e);Err(Error::RequestFailed)}}}
What I'm after is some explanation of what the error actually means. Is it a problem with the TLS or with something else when connecting with the grafana cloud. When I use the address and user / key I can push data from postman to grafana cloud.
The text was updated successfully, but these errors were encountered:
. That seems to create a buffer with a size of a 128 characters. However the Grafana API key is 165 characters in length (+ the username of about 10 characters). So I think my Codec issue is caused by the buffer being too small for the API key I have been given.
I'm using reqwless 0.13.0 on an esp32-c6 dev board. I've got all default features turned off and only the embedded-tls and log features turned on. I'm suing embedded-tls 0.17.0. I'm taking an environmental reading (pressure, humidity and temperature) using a BME280. Then this data should be send to Grafana cloud via the Influx protocol.
The output I'm getting is
The relevant code is:
What I'm after is some explanation of what the error actually means. Is it a problem with the TLS or with something else when connecting with the grafana cloud. When I use the address and user / key I can push data from postman to grafana cloud.
The text was updated successfully, but these errors were encountered: