GSM MQTT Subscribe - mqtt

I want to subscribe a topic from my mqtt broker using a GSM Modem. I am new to GSM modem, Please guide me to implement this.
Based on my under standing, I need to follow these steps.
Prepare modem using Basic AT commands
Start TCP connection to MQTT broker using ATcommands ( Say: AT+ CIPSTART="TCP","MQTT BROKER","MQTT PORT"
Send Subscribe message to MQTT broker ( AT + CIPSEND and remaining steps )
Then In a loop continuously read serial buffer data. If connection closed reconnect.
Please confirm my understandings are correct.

Related

Getting Multiple times same MQTT messages on single topic

I am developing an application with MQTT and here i am facing same messages are coming multiple times to the same topic instead of one message.
I am using a mosquitto broker, which is also bridged to another cloud private mosquitto broker and client is one paho mqtt client and An android MQTT Application.
Can anyone tell me what could be the reason for above scenario. During publishing also we can experience multiple messages at the subscriber, just for one publish.
This is the Broker Configuration
connection GlowFY-GWY-b827eb83b211
address xx:xx:xx:xx:1883
topic GlowFY/# both 0

AT / CMQTT, subscription silently removed after publish (cmqttpub)

I am using MQTT on a SIM7500 LTE modem. I can connect to some mqtt broker after sending a bunch of AT and MQTT commands.
The thing I didn't expect to happen, is when I publish a topic from my modem, I loose the subscription I had open. Regardless of the topic name I subscribed to. After a publish from my modem, my modem no longer receives bytes when I publish on any subscribed topic on the broker.
I checked the documentation on the modem again, I can't find any reference to this behavior.
Anybody with knowledge on AT/CMQTT can explain if this is "expected behavior"? I can't imagine it's a bug in the modem. So either I am using things in the wrong way, or there is a reason for this.
A screenshot which shows the commands being sent/received:
In text:
startup commands left out for convenience (atz, ate0, at+cgatt=1, at+cgact=1,1)
MCU ==> Modem MCU <== Modem
AT+CMQTTCONNECT=0,"someipaddress:port,90,1
+CMQTTCONNECT: 0,0
AT+CMQTTSUBTOPIC=0,5,2
>
stm32
OK
AT+CMQTTSUB=0
OK
from this moment on, I have a live subscription, I published 2 messages on that topic which are received and passed through to my MCU
MCU ==> Modem MCU <== Modem
hello
hello
AT+CMQTTTOPIC=0,17
>
t/867584034403399
OK
AT+CMQTTPAYLOAD=0,5
>
hello
OK
from this point onwards, the subscription is lost. Whatever I publish on 'stm32', it no longer is received on my uart connected to my modem.

MQTT broker communication to MQTT Client

I already have a cumulocity client that communicates with the cumulocity broker through MQTT.
What should I do in order to send data back from MQTT broken in cumulocity to mqtt client? (Say the client sends some data and I want the confirmation that the data was sent successfully)
For some reason couldn't find any info on this on the cumulocity docs the only for client.
If you want to get confirmation from the server of getting your data you should use the normal MQTT QoS. http://cumulocity.com/guides/mqtt/implementation/
If you want to send data in general from the platform to your device client operations is what you are looking for. This is currently the only data you can subscribe to on Cumulocity MQTT.
http://cumulocity.com/guides/concepts/domain-model/#operations
You can check the python example. It contains the subscription part
http://cumulocity.com/guides/mqtt/hello-mqtt-python/
You should connect to the broker with Qos 1 or above. This will guarantee that the data has reached the broker at least once. The client will be receiving the PUBACK message once this happens. If the connectivity is lost then the client is supposed to re-send the PUBLISH message with Duplicate flag set. So the cient should stop publishing when a PUBACK is received.
For more information about Qos, refer this link
HiveMQ/blog/mqtt-essentials/QualityOfService

Gsm800 mqtt library

I have sim800 module ,i want to control relay from webserver so i need mqtt library and sample code for arduino uno please help to me,What is AT command for publish and subscribe the tag in sim800 using arduino uno
I think it is very unlikely that your SIM800 module will have an AT command for MQTT.
There are a couple of MQTT libraries for Arduino:
AdaFruit: https://github.com/adafruit/Adafruit_MQTT_Library
PubSubClient by Nick O'Leary: http://pubsubclient.knolleary.net/
Both of these libraries should work with any library than implements the Client interface. So it should be possible to create a TCP client that talks to the GSM module.
If the SIM800 supports the GSM library then that implements the Client interface:
https://www.arduino.cc/en/Reference/GSM
If you are using the hardware serial port in the Arduino, you might be better using a Leonardo than a Uno, because you can use the USB to programme the Arduino, and the hardware serial to talk to the GSM module.
MQTT Library for SIM800 GSM Modem is available at ElementzTechBlog, ElementzGithubRepository,ElementzOnlineCart
Functionalities:
Auto connect
Automatically connect to TCP and to MQTT server.
connect function
This function can be used to connect your client to MQTT broker.
Use only if you do not use Auto connect functionality.
Optionally you can use username, password, WILL topic and WILL Message.
OnConnect CallBack function
This call back function is called when MQTT connection is established.
You can call subscription and publish functions inside it (according to your need).
publish function
This function can be used to publish messages to different topics.
You can select QoS levels and RETAIN flag according to your need.
subscribe function
This function can be used to subscribe messages from different topics.
OnMessage CallBack function
This callback function is called when messages are received from subscribed topics
Topic, TopicLength, Message, MessageLength are the arguments of OnMessage callback function.
Inside this, you can write your custom code.
unsubscribe function
This function can be used to unsubscribe from a previously subscribed topic.
disconnect function
This function can be used to disconnect your client from MQTT broker.
Keep Alive
You can specify your KeepAlive duration while initializing.
Ping requests are sent and received automatically.
You can try using Paho Arduino client library. It features full fledged MQTT library with support to MQTT 3.1, MQTT 3.1.1 & SSL/TLS.

How to receive UDP broadcast packets on a PARTICULAR interface?

On an iPhone I have created a UDP socket and bound it to the WLAN interface. I enabled SO_BROADCAST and I am able to send broadcast packets to the network (confirmed by a client running on my notebook.) But the UDP socket on the iPhone is unable to receive broadcast packets.
In my opinion this is a kernel bug, because not allowing a socket with SO_BROADCAST enabled to receive any broadcast packet, is a bad design decision.
The problem is further described here and here. The most popular solution to this problem is to bind to INADDR_ANY. However, it would be nice to be able to bind an UDP socket to only one interface while still receiving broadcast packets! Is there really no way to achieve this?
(When I bind a socket to 192.168.1.7 on a class C net (/24), it should accept packets sent to 192.168.1.7 and packets sent to 192.168.1.255!)
Thanks!
pls check below link may be it's helpful.
Receive udp broadcast packets ios
iPhone UDP broadcast and response
iOS UDP broadcast vs. PHP UDP broadcast
https://github.com/robbiehanson/CocoaAsyncSocket

Resources