Closed mrdvt92 closed 3 weeks ago
Why should this be in the module, and not in a script you write? I think everyone's requirements for RPC-like protocols over MQTT will be different.
I think everyone's requirements for RPC-like protocols over MQTT will be different.
I think a one-shot capability will be a very common capability needed for the IoT revolution that is here/coming. There were a few edge cases to this development that need to be baked in so that users can depend on them.
I think many IoT devices will prefer MQTT message/response pattern so, that they only need to support one protocol instead of two (e.g. MQTT for events and HTTP for status). I'm working with Tasmota today which does have an HTTP API.
If MQTT stays as the hub for IoT automation, I would like for Perl to be in the ecosphere.
Why should this be in the module, and not in a script you write?
I plan to use this capability in multiple places. So, I will package it. However, I would like for this capability to be in your namespace and not in an overlay package (i.e., login
).
my $value = $mqtt->one_shot($topic_sub, $topic_pub => $message);
Feel free to change the method name or the context-based return to an object or a hash ref with error code, if you have a better convention.
I believe the new functionality introduced in v1.30 provides the requested feature.
I need a "one shot" method where I can send a command and then received the response via MQTT to control and query a device that only knows MQTT.
This Python script https://stackoverflow.com/questions/61189974/how-to-get-a-one-shot-message-with-mqtt does the exact process that I need (just not in Perl).
Process
For example, to toggle a Tasmota device but you don't know if it is currently on or off.
Returns