How do you read MQTT data using a background service while main app is closed?

Hello,

i have a working app that connects and receives data from hardware device via mqtt server.

I would like to send notification messages to the users mobile from hardware device even the main app is closed.

As far as i have read in the forum, it is possible to run a background task.
while the main app is closed, can I still be connected to mqtt server and receive messages?

I would appreciate if someone can provide some help on this because i can not go any further with my application.

Thanks in advance
Regards
George

If it can be done, this is what you need to do it:

1 Like

Using the blocks shown in the picture, i am trying to stay connected to mqtt server and i would like to be able to receive messages from the mqtt.

I am totally lost at the moment how to achieve this.

Register all events in your
bgMqttCheck procedure

Use the Notifier.LogInfo method as debug statements and use logcat to debug

You do not need the inner if statement it is wrong anyway (should be if not connected)

Write your MessageReceived event handler

EDIT: first prepare a simple example which is working in the foreground and show your working blocks so we can compare with your blocks from the background processing

Taifun

2 Likes