Arduino MQTT code for SIM800L module - Working :)

Hi Ravi,

Thanks for the quick response earlier today.

I incorporated the code into my already existing error handling code.

the modem connects to the server but the connection is closed immediately as per this video

the code I am using can be found in a repository Here

Kindly let me know what could be wrong with the code since it worked with sim900 in Ravi’s Tutorial.

I am seeing no gap between CIPSEND commands. One command is sent before another is finished.
Add a delay and try. Also put some delay after TCP connection is opened and then send the connect packet.
To see if packets are formed properly, may be you can tap the UART lines and see in a hex editor.

I figured out the problem. The repository is updated for anyone that may wish to try it out!
Happy coding

1 Like

Thanks Peter :slight_smile:
Working code link re written by Peter

Hello Peter Sir… I have downloaded the re written code by you on the link mbari_peter / sim800 mqtt-ravi
But when i am compiling it then it shows error that Serial2 is not declared , initTCP not declared… please help

Hello guys
i tried it too, and it gives me an error
“exit status 1 ‘initTCP’ was not declared in this scope”
your replay will be highly appreciated

Same problem with my setup.

“exit status 1 ‘initTCP’ was not declared in this scope”

Please help!

Hi champ! So the file you’ve downloaded comes with two .ino files, “modemDrivers” & “mqtt_NEW”. The problem you’re having is that the functions (e.g. “initTCP”) is defined in the “modemDrivers.ino” sketch. So to solve this the easiest way would be to 1. open modemDrivers, 2. press ctrl+a to select everything in that sketch 3. ctrl+c to copy everything 4. open mqtt_NEW and paste the copied code into the mqtt_NEW sketch - NB don’t override the code already inside the mqtt_NEW sketch, so just paste it way at the bottom.

Hi Matko, see reply to champ’s question.

Hi, ok but now it gives me ‘Serial2’ was not declared in this scope error

I am facing a problem.
When I send an AT command, the response is empty.
Like as
I send “AT+CIPSEND” the response is empty.
How can I solve this problem ?

@Md_Iqbal_Hossain Create separate thread for your question.