Closed p3g4asus closed 6 years ago
Nice idea. This can be achieved by just displaying the Long id of the broker in the app. What do you think about that?
I think yours is a good idea. It's simple and effective.
To further contribute to this discussion, this could be added to the playstore description of the app and/or to the readme.md of this github repository. Please feel free to correct my code / my english if you find errors or issues.
This app can be used to connect to a mqtt broker and publish messagess through the following intent interface.
Connecting to a broker
String innerAction = "in.dc297.mqttclpro.tasker.activity.Intent.MQTT_CONNECT_ACTION";
//the following numeric value can be read in the interface of the app next to
//the broker nickname and host name
long brokerId = 1;
Bundle b = new Bundle();
b.putLong("in.dc297.mqttclpro.tasker.activity.Intent.EXTRA_BROKER_ID",brokerId);
b.putString("in.dc297.mqttclpro.tasker.activity.intent.ACTION_OPERATION",innerAction);
Intent intent = new Intent("com.twofortyfouram.locale.intent.action.FIRE_SETTING");
intent.putExtra("com.twofortyfouram.locale.intent.extra.BUNDLE",b);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
Publishing a message
String innerAction = "in.dc297.mqttclpro.tasker.activity.Intent.MQTT_PUBLISH_ACTION";
//the following numeric value can be read in the interface of the app next to
//the broker nickname and host name
long brokerId = 1;
String topic = "sample/topic";
String message = "this is a message";
boolean retained = false;
//quos as String
String qos = "0";
Bundle b = new Bundle();
b.putLong("in.dc297.mqttclpro.tasker.activity.Intent.EXTRA_BROKER_ID",brokerId);
b.putString("in.dc297.mqttclpro.tasker.activity.Intent.EXTRA_TOPIC",topic);
b.putString("in.dc297.mqttclpro.tasker.activity.Intent.EXTRA_MESSAGE",message);
b.putString("in.dc297.mqttclpro.tasker.activity.Intent.EXTRA_QOS",qos);
b.putBoolean("in.dc297.mqttclpro.tasker.activity.Intent.EXTRA_RETAINED",retained);
b.putString("in.dc297.mqttclpro.tasker.activity.intent.ACTION_OPERATION",innerAction);
Intent intent = new Intent("com.twofortyfouram.locale.intent.action.FIRE_SETTING");
intent.putExtra("com.twofortyfouram.locale.intent.extra.BUNDLE",b);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
Available in v4.3.0. I'll update the description ASAP.
Perfect. Thank you. I think this can be closed. Or if you want you can leave it open as a remainder for the description update.
Updated.
It would be nice if this app could be easily used as a plugin for a generic app using in.dc297.mqttclpro.tasker.receivers.FireReceiver intent interface. This is possible and working now (and I am using it with my small app) but for an external app is impossible to know the Long id of the broker for the connection or the publish action. It would be nice to specify in the intent interface the String id of the broker as an alternative to its Long id.