Вот функция, которая получает данные/сообщение:
Код: Выделить всё
private async void client_MqttMsgPublishReceivedAsync(object sender, MqttMsgPublishEventArgs e)
{
try
{
string msg = System.Text.Encoding.Default.GetString(e.Message);
System.Diagnostics.Debug.WriteLine("Message Received: " + msg);
await MainThread.InvokeOnMainThreadAsync(() =>
{
if (datenPage != null)
{
datenPage.UpdateContent(msg);
}
else
{
System.Diagnostics.Debug.WriteLine("DatenPage is null.");
}
});
}
catch (Exception ex)
{
await DisplayAlert("MQTT", $"Error: {ex.Message}", "OK");
}
}
Код: Выделить всё
public void UpdateContent(string newText)
{
if (temp != null)
{
temp.Text = newText;
System.Diagnostics.Debug.WriteLine($"Label changed to: {newText}");
}
else
{
System.Diagnostics.Debug.WriteLine("Label 'temp' is null.");
}
}
Я ожидаю, что сообщение mqtt будет отображаться как текст метки.
Подробнее здесь: https://stackoverflow.com/questions/790 ... ing-m2mqtt
Мобильная версия