AT Commands to connect, publish and subscribe to mqtt broker

Asked by Amogh

Hello there
I'm using raspberry pi and sim900 gsm/gprs modem for connectivity, now I want to Publish/Subscribe to MQTT broker through gprs(sim900 modem) and I don't know 'AT commands' for the same.
is it feasible to send data to MQTT broker using modem AT commands? Any help on this is appreciated.
Regards,
Amogh.

Question information

Language:
English Edit question
Status:
Invalid
For:
mosquitto Edit question
Assignee:
No assignee Edit question
Solved by:
Roger Light
Solved:
Last query:
Last reply:
Revision history for this message
Jan-Piet Mens (jpmens) said :
#1

No, that isn't possible. MQTT needs TCP.
What you need to do is read up on how to get, say, a PPP connection set up with your equipment before attempting MQTT, but that is definitely out of scope for Mosquitto!

Revision history for this message
Amogh (amogh1990) said :
#2

Thank you Jan-Piet Mens (jpmens) for quick feedback, I got your point .
I need to understand mqtt publish packet structure and then I can send self created packet along with tcp AT command.

Revision history for this message
Paolo Patruno (p-patruno) said :
#3

I think that the solution suggested by Jan-Piet Mens is the better solution for raspberry but sim900 gsm/gprs modem provide
at commands for TCP connection; for example:
http://www.cooking-hacks.com/documentation/tutorials/arduino-gprs-gsm-quadband-sim900#step7

So is what we try to do with microcontroller using mqtt C library for arduino for example.

Revision history for this message
Dost Shah (dost-mhd) said :
#4

Has any one got something to work with AT commands or embedded AT in SImcom Modules??

Revision history for this message
Roger Light (roger.light) said :
#5

I'm marking this as rejected because as JP Mens says, it's completely out of scope for mosquitto. You should look to the support channel for the part you are using instead.

Revision history for this message
Paolo Patruno (p-patruno) said :
#6

for information you can use those library:

https://github.com/r-map/rmap/tree/master/arduino/sketchbook/libraries/sim800
https://github.com/r-map/rmap/tree/master/arduino/sketchbook/libraries/PubSubClient

in PubSubClient.h change code like this:

// if use sim800 client
#include "sim800Client.h"
#define TCPCLIENT sim800Client

// if use arduino_uip or etherclient
//#include "Client.h"
//#include "Stream.h"
//#define TCPCLIENT Client

and try this example:
https://github.com/r-map/rmap/blob/master/arduino/sketchbook/libraries/sim800/examples/mqtt_basic/mqtt_basic.ino

should work for sim900 too.

Paolo

Revision history for this message
anuj kumar (mailtechno-anii) said :
#7

Hi
Paolo

Basis your suggestion dated 2015-10-27, i tried implementing MQTT on SIM900 but the compiler shows the following error. Please help.

Compiling 'mqtt_basic' for 'Arduino Uno'
sim800.h:14:24: error: 'Serial1' was not declared in this scope
sim800.cpp:in expansion of macro 'HARDWARESERIAL'
Error compiling

Thanks
Anuj

Revision history for this message
Dost Shah (dost-mhd) said :
#8

@anuj Uno has just one hardware serial port.

You should use software serial port in UNO.

Revision history for this message
anuj kumar (mailtechno-anii) said :
#9

Hi Dost Shah

Yes very correct, UNO has only one serial port.

Thus i am trying to covert the code base to work with Software serial but i am unable to do that. Need help in doing the same.

I already have used software serial sometime back and thus understand its syntax to use.

Would request you if you can suggest the places in the code where i should perform changes from hardware serial to software serial.

Thanks
Anuj

Revision history for this message
Dost Shah (dost-mhd) said :
#10

You dont need to convert anything except comment out HardwareSerial define

#ifndef sim800_h
#define sim800_h

#include "Arduino.h"
#include <Time.h>
//#include <inttypes.h>
#include "IPAddress.h"

// activate debug on serial port
//#define DEBUGONSERIAL
#define ENABLEWDT 1
// if define HARDWARESERIAL is set then it will be static (required by Time library)
//#define HARDWARESERIAL Serial1 ---------> comment out this line

Revision history for this message
anuj kumar (mailtechno-anii) said :
#11

Hi Dost

Extremely sorry to bother you again n again but the issue still remains.
After commenting out #define HARDWARESERIAL Serial1
These are the errors

Compiling 'mqtt_basic' for 'Arduino Uno'
mqtt_basic.ino:In function 'void setup()'
mqtt_basic.ino:65:20: error: 'Serial1' was not declared in this scope
sim800.h:In member function 'int sim800Client::available()'
sim800.h:105:19: error: 'HardwareSerial* SIM800::modem' is private
sim800.cpp:930:10: error: within this context
sim800.h:In member function 'int sim800Client::read()'
sim800.h:105:19: error: 'HardwareSerial* SIM800::modem' is private
sim800.cpp:936:9: error: within this context
sim800.h:In member function 'size_t sim800Client::write(uint8_t)'
sim800.h:105:19: error: 'HardwareSerial* SIM800::modem' is private
sim800.cpp:951:10: error: within this context
sim800.h:In member function 'size_t sim800Client::write(const uint8_t*, size_t)'
sim800.h:105:19: error: 'HardwareSerial* SIM800::modem' is private
sim800.cpp:959:10: error: within this context
sim800.h:In member function 'bool sim800Client::transparentescape()'
sim800.h:105:19: error: 'HardwareSerial* SIM800::modem' is private
sim800.cpp:968:3: error: within this context
sim800.h:105:19: error: 'HardwareSerial* SIM800::modem' is private
sim800.cpp:969:3: error: within this context
sim800.h:105:19: error: 'HardwareSerial* SIM800::modem' is private
sim800.cpp:970:3: error: within this context
Error compiling.

Revision history for this message
Paolo Patruno (p-patruno) said :
#12

Sorry, I do not have line 65 in my mqtt_basic.ino and seem you have Serial1 in your code:
https://github.com/r-map/rmap/blob/master/arduino/sketchbook/libraries/PubSubClient/examples/mqtt_basic/mqtt_basic.ino

HARDWARESERIAL should be defined to be the hardware serial port connected to sim800/900.
I use mega2560 and I connect sim800 to Serial1;
if you use software serial unset HARDWARESERIAL and pass your software serial port to sim800 init method.
I get some problems with software serial so I prefer to use hardware serial port.

Paolo

Revision history for this message
Nithin Kurian (nithinkuriank) said :
#13
Revision history for this message
Paolo Patruno (p-patruno) said :
#14
Revision history for this message
Jordan Silverman (jordansilverman) said :
#15

Hey Paolo,

Thanks for the PAHO library - hopefully I can get it to work. My MQTT feed requires authentication with a username and password, how can I edit the code to add that in?

Thanks

Revision history for this message
Paolo Patruno (p-patruno) said :
#16
Revision history for this message
Vanessa Telles (vanessat) said :
#17

Hey Paolo,

Thanks for the library! I managed to compile the library and example in my Arduino using the mega, but I can not perform communication MQTT .
I'm using a shield of icomsat v1.1 and called tx rx SIM900 in Serial1 the Arduino , I need to change something more in the library to make it work with me ?