did some simplification and add a response.
i finaly did it!!!
This code send hello word to my lora anttena
private async void ALARMEPIQUET_Click(object sender, EventArgs e)
{
string payload = "SGVsbG8gV29ybGQ="; // Payload base64
int port = 1; // Port
bool confirmed = false; // downlink confirm
string downlinkUrl = $"https://eu1.cloud.thethings.network/api/v3/as/applications/XXX-test/devices/eui-XXXXX/down/push";
var downlinkPayload = new
{
downlinks = new[]
{
new
{
frm_payload = payload,
f_port = port,
confirmed = confirmed
}
}
};
var json = Newtonsoft.Json.JsonConvert.SerializeObject(downlinkPayload);
var content = new StringContent(json, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apikey);
var response = await client.PostAsync(downlinkUrl, content);
if (response.IsSuccessStatusCode)
{
string responseData = await response.Content.ReadAsStringAsync();
MessageBox.Show("Downlink message sent successfully. Response: " + responseData);
}
else
{
MessageBox.Show("Failed to send downlink message. Status Code: " + response.StatusCode);
}
}