I have an ESP-32 device which measures and sends data to my Adafruit IO account every 10 minutes.
The temperature feed is regurarly saved in the key "temp_sleep". This works fine.
I would like to read this specific temperature feed. My code is based on https://www.b4x.com/android/forum/t...-the-home-temperature-with-adafruit-io.80820/
The app connects fine to my Adadruit account, there are NO errors. But the temperature remains "0°".
I've added a screenshot of the Adafruit IO feeds.
Probably I mix up the feed in the code. I can't find the cause. Can somebody help me?
The relevant code:
The temperature feed is regurarly saved in the key "temp_sleep". This works fine.
I would like to read this specific temperature feed. My code is based on https://www.b4x.com/android/forum/t...-the-home-temperature-with-adafruit-io.80820/
The app connects fine to my Adadruit account, there are NO errors. But the temperature remains "0°".
I've added a screenshot of the Adafruit IO feeds.
Probably I mix up the feed in the code. I can't find the cause. Can somebody help me?
The relevant code:
Starter:
Private Sub AfterConnect
mqtt.Subscribe($"${username}/f/temp-sleep"$, 0)
UpdateState
End Sub
Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)
If Topic.EndsWith("/temp-sleep") Then
Dim temp As String = BytesToString(Payload, 0, Payload.Length, "ascii")
temperature = temp
UpdateState
End If
End Sub
B4X:
Main:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private lblTemperature As Label
Private lblState As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
End Sub
Public Sub SetState
If Starter.mqtt.Connected Then
lblState.Text = "Connected"
lblTemperature.Text = $"Temperature: $1.1{Starter.temperature} °"$
Else
lblState.Text = "Disconnected"
lblTemperature.Text = "Temperature: N/A"
End If
End Sub
Attachments
Last edited: