osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How do i execute some code when I have subscribed to a topic with a message payload for mqtt in python?


On 08/08/2019 21:47, Spencer Du via Python-list wrote:
> Ok so here is some code below. How do I write an if code block to
> execute some commands when I subscribe to the topic:
> microscope/light_sheet_microscope/UI and which has a message which is
> a device type published to it. I want to execute some code to check
> if the device has a python file in the currently directory because
> each device also relates to a python file. If the file exists then
> import the file into the python program else print an error message.
> If I need to use on_subscribe callback then tell and show me how the
> code is to be written and if another method then also tell me and
> show me how to write the code. I really appreciate all the help you
> can give me because this is really important for me and I am
> currently really struggling with MQTT because I need help with
> writing MQTT code because I am working on MQTT at work.
The first thing you need to do is stop, take a breath and write down 
step by step exactly what you want done.  At the moment you sound like 
you are flailing about, and you aren't going to get anything done that 
way.  Stop and relax for a moment.  The example program you have already 
should help you figure out what information is available when.


-- 
Rhodri James *-* Kynesim Ltd