edusperoni / nativescript-mqtt

MQTT 3.1.1 for Nativescript
Apache License 2.0
12 stars 3 forks source link

Implementation of publishing messages to broker #4

Closed kabaluyot closed 5 years ago

kabaluyot commented 5 years ago

How to publish message from app to the mqtt broker?

edusperoni commented 5 years ago

mqttClient.publish(message)

mqttClient.publish(new Message(new Message({
    destinationName: "topic",
    payloadString: "data to send"
}));
kabaluyot commented 5 years ago

i'll definitely try this out.. If got all this working, is it okay that I will update readme to help others? :)

edusperoni commented 5 years ago

Sure, you're welcome to submit a PR :)

kabaluyot commented 5 years ago

in the above code, I think new Message was duplicated causing the mqtt connection to close. But I got it working with this,

this.mqtt_client.publish(new Message({ destinationName: "PubMonitor", payloadString: "data to send" }));

kabaluyot commented 5 years ago

I have question sir, what is the purpose of the other parameters?.. I can send to broker but I also get the message I sent which can be of course get rid of using conditionals..

image

edusperoni commented 5 years ago

The first line was just showing what method to call, the code you used is correct :)

edusperoni commented 5 years ago

They're all part of the mqtt spec:

payloadBytes sends raw bytes instead of a string

qos: http://www.hivemq.com/blog/mqtt-essentials-part-6-mqtt-quality-of-service-levels

retained: http://www.hivemq.com/blog/mqtt-essentials-part-8-retained-messages

kabaluyot commented 5 years ago

very much explained.. thank you <3

DamiJegede commented 5 years ago

Thanks @edusperoni for this amazing plugin. I struggled for days. I guess a documentation update will solve this issue for others.