terrorsl / sMQTTBroker

Simple MQTT broker
MIT License
70 stars 19 forks source link

Send Message from Broker #10

Closed conaito closed 1 year ago

conaito commented 2 years ago

Is there a way to send a message from broker to the clients or a special client? if not can you implement such solution? As far as i see there is not client as such in the library to can do it?

terrorsl commented 2 years ago

I'll see what i can do

terrorsl commented 2 years ago

i append function publish in broker, but not test it.

conaito commented 2 years ago

can you give me some sample code to how to use / test it?

terrorsl commented 2 years ago
char *topic="test/test";
char *payload="some text";
broker->publish(topic,payload);

if client subscribe to topic it receive message

conaito commented 2 years ago

nice! i will test it soon! thx a lot. btw. is this message set as retain?

terrorsl commented 2 years ago

nice! i will test it soon! thx a lot. btw. is this message set as retain?

now this message Qos 0 and not retain.

henrythasler commented 2 years ago

Works great, thanks! It's exactly what I was looking for.

whiledpeterman commented 2 years ago

Sort of continuing with this topic ....for/in the loop calling broker.update() is there a way to get notified or set up a call back function for when there is a valid subscribe to a new topic or a valid unsubscribe from a current topic? That way would know when and what to broadcast based only from the connected clients needs and desires. The envisioned use for this code would be to publish using broker->publish(topic,payload); shown above -With only the needed topics/payloads of connected client(s) out of the many many topic possibilities for our devices. Thanks!

terrorsl commented 2 years ago

hi, there are no such functions now. But I can add, and it will be possible to receive events like the rest through the onEvent function

whiledpeterman commented 2 years ago

That would be excellent and appreciated!

whiledpeterman commented 2 years ago

Is there a way I am able to use the requested feature before the library is updated? Thanks

terrorsl commented 2 years ago

I plan to add a branch for development, all new functionality will go there, and then into the main and releases.