This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GH6PM: Implement MQTT protocol on sim800 module with TM4C123GH6PM

Part Number: TM4C123GH6PM

Hello All,
I am beginner to MQTT protocol, I want to publish some data(dummy) on server over MQTT protocol through SIM800 GSM/GPRS module. I am using TM4C123GXL-Launchpad.i send AT commands to GSM module using uart of TM4C123 controller and creat TCP socket using following AT command send using uart
AT
AT+CSTT='BSNLNET",",""
AT+CIICR
AT+CIFSR
AT+CIPSTART="TCP","iot.eclipse.org","1883"
AT+CIPSEND
socket creat sucessfully.
now i want to implement MQTT protocol on top of TCP/IP

here is my code
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
//#include "inc/tm4c123gh6pm.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "driverlib/uart.h"

char ok[]="OK\r\n";

char receivechar[35];
int count=0;
int count1=0;
unsigned int i,j;

void UARTTransmitCommand( char *p)
{
while(*p!='\0')
{
ROM_UARTCharPut(UART1_BASE, *p);
p++;
}

ROM_IntEnable(INT_UART1);

}
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

//*****************************************************************************

// The UART interrupt handler.
/************************************************************/
void
UART1IntHandler(void)
{

uint32_t ui32Status;
++count1;

//
// Get the interrrupt status.
//
ui32Status = ROM_UARTIntStatus(UART1_BASE, true);


// Loop while there are characters in the receive FIFO.
//


while(ROM_UARTCharsAvail(UART1_BASE))
{
receivechar[count]=ROM_UARTCharGet(UART1_BASE);
ROM_UARTCharPut (UART0_BASE, receivechar[count]);

count++;
if(count==35)
{
count=0;
}
}

//
// Clear the asserted interrupts.

ROM_UARTIntClear(UART1_BASE, ui32Status);
}
/********************************************************/
int
main(void)
{
//
// Enable lazy stacking for interrupt handlers. This allows floating-point
// //instructions to be used within interrupt handlers, but at the expense of
// extra stack usage.
//
ROM_FPUEnable();
ROM_FPULazyStackingEnable();

//
// Set the clocking to run directly from the crystal.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);


//
// Enable the peripherals used by this example.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

//
// Enable processor interrupts.
//
ROM_IntMasterEnable();

//
// Set GPIO B0 and B1 as UART pins.
//
GPIOPinConfigure(GPIO_PB0_U1RX);
GPIOPinConfigure(GPIO_PB1_U1TX);

GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);


ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);


//
// Configure the UART for 115,200, 8-N-1 operation.
//
ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//
// Enable the UART interrupt.

ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);

ROM_UARTFIFOEnable(UART1_BASE);

UARTFIFOLevelSet(UART1_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8);


ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

ROM_UARTFIFOEnable(UART0_BASE);

UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8);

UARTEnable (UART0_BASE);
UARTEnable (UART1_BASE);

do
{

UARTTransmitCommand("AT\r\n");

SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
break;
}while((strcmp(ok,receivechar))!=0);


do
{

UARTTransmitCommand("AT+CSTT=\"bsnlnet\","",""\r\n");

SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());

break;
}while((strcmp(ok,receivechar))!=0);


do
{

UARTTransmitCommand("AT+CIICR\r\n\0");

SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
break;
}while((strcmp(ok,receivechar))!=0);

do
{

UARTTransmitCommand("AT+CIFSR\r\n\0");

SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
break;
}while((strcmp(ok,receivechar))!=0);


do
{

UARTTransmitCommand("\"AT+CIPSTART=\"TCP\",\"iot.eclipse.org\",\"1883\"\r\n\0");

SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
break;
}while((strcmp(ok,receivechar))!=0);

do
{

UARTTransmitCommand("AT+CIPSEND\r\n\0");

SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
break;
}while((strcmp(ok,receivechar))!=0);

while(1)
{


}

}

please help how implement MQTT on top of TCP/IP 

Does anyone has a sample code which will do the same thing or to begin with? Any suggestion to understand these things better are welcome.
Board-EKTM4C123GXL
Compiler version- TI v5.2.5
If anyone have some suggestion kindly reply.
Thanks.

  • Hi,
    Similar question has been answered in this post. e2e.ti.com/.../2338921. Basically we have no support for MQTT. You an search the forum to see if community members have success with and examples for MQTT or hopefully someone in the forum can provide some guidance.
  • Hi Charles,

    Is it not true that such, "Repeated calls to, "SysCtlDelay(SysCtlClockGet());" simply to implement a delay - are unnecessary & may "cause" issues?      (as much "goes on" during such call - any noise burst/glitch may prove disruptive - and cause serious impact...)

    Hard coding a value - able to "fit" w/in "SysCtlDelay's" 24 bit capacity - seems a far safer means to create delay...

    That "so related posts" arrive - so closely together - sounds the alarm bell - does it not?         Suggests a, "School Assignment" or a 2nd attempt by the initiator - who has "transformed."

  • I think I would phrase it as

    Using SysCtlDelay is likely to cause problems and should be avoided in favour of other approaches. More importantly the use of arbitrary delays in command processing should be documented.

    I will also note that the command response processing used here is particularly fragile.

    Robert

  • Agreed - note too (under category, "particularly fragile") poster's requirement for an "exact match" (to reset a "Uart-control" counter.)
    (poster's use of "count ==35" would be less fragile with "count >=35")