Kindly check the void main section
I am running alternate AT commands because AT+CIFSR was not running on my GSM module
The payload is built in the AT_CIPSEND send function
#include "uart.h"
#include "stdlib.h"
#include <stdlib.h>
#include "config.h"
#include "gpio.h"
#include <string.h>
#define BUFFER_SIZE 1200
char TXBuffer[BUFFER_SIZE];
int temperature=2;
char send_whole_str[300]={0, };
//token=BBFF-GPigdeygux8m9S0Frh3QCESHBkx3fe
//variable=604d00741d8472129a7ab12c
char post_cmd[]= "POST /api/v1.6/variables/604d00741d8472129a7ab12c/values HTTP/1.1\r\nX-Auth-Token: BBFF-GPigdeygux8m9S0Frh3QCESHBkx3fe\r\nHost: things.ubidots.com\r\nConnection: close\r\nContent-Type: application/json\r\nContent-Length:14\r\n\n{\"value\": " ;
char http_request[BUFFER_SIZE];
char http_page[BUFFER_SIZE];
char html_page[BUFFER_SIZE];
int response_ok = 0;
int connection_id = 0;
char led_status = 0;
int send_string(char * str) {
char error;
response_ok = 0;
while (*str != '\0') {
uart_putchar(UART_1, *str, &error);
/*if (*str == '\n')
uart_putchar(UART_1, '\r', &error);*/
str++;
}
return 0;
}
int send_char(char code) {
char error;
uart_putchar(UART_1, code, &error);
return 0;
}
void receive_string(char * str) {
char error;
char data;
while (1) {
data = uart_getchar(UART_1, &error);
*str = data;
str++;
//Check for OK
if (data == 'O') {
data = uart_getchar(UART_1, &error);
*str = data;
str++;
if (data == 'K') {
response_ok = 1;
break;
}
}
//Check for ERROR
if (data == 'E') {
data = uart_getchar(UART_1, &error);
*str = data;
str++;
if (data == 'R') {
data = uart_getchar(UART_1, &error);
*str = data;
str++;
if (data == 'R') {
response_ok = 0;
break;
}
}
}
if (data == 'D') {
data = uart_getchar(UART_1, &error);
*str = data;
str++;
if (data == 'O') {
data = uart_getchar(UART_1, &error);
*str = data;
str++;
if (data == 'W') {
response_ok = 0;
break;
}
}
}
if (data == '>') {
response_ok = 0;
break;
}
}
}
int gsm_send(char * sstr) {
char response[100] = { 0, };
send_string(sstr);
receive_string(response);
printf("%s\n",response);
if (response_ok)
return 1;
else
return 0;
}
int gsm_send_data(char * data)
{
char response[100] = { 0, };
char send_str[50]={0,};
sprintf(send_str,"AT+HTTPDATA=%d,10000\r\n", strlen(data));
send_string(send_str);
receive_string(response);
printf("%s\n",response);
udelay(5000000);
send_string(data);
receive_string(response);
printf("%s\n",response);
if (response_ok)
return 1;
else
return 0;
}
void AT_CIPSEND() {
char send_str[300]={0,};
char str[100] = {0, };
sprintf(send_whole_str,"%s%d}\r\n",post_cmd,temperature);
int length = strlen(send_whole_str);
sprintf(send_str,"AT+CIPSEND\r\n",length);
send_string(send_str);
receive_string(str);
//printf("STR: %s\n",str);
if (response_ok)
printf("CIPSEND connected\n");
else
printf("CIPSEND error\n");
}
void API_KEY() {
const char* len;
char str[100] = {0, };
char send_str[50]={0,};
send_string(send_whole_str);
printf("STR: %s\n",send_whole_str);
printf(" value sent \n");
}
/**
@fn main
@brief transmit and reception through uart
@details 1 character is transmitted and received through uart
@param[in] No input parameter.
@param[Out] No ouput parameter.
@return Void function.
*/
void main() {
led_status = 0;
printf("\n\r *****************************************************************************");
printf("\n\r INFO: Connect GSM module [SIM800A] to UART 1 ");
printf("\n\r *****************************************************************************");
**printf("\n\r Setting up GSM Modem \n");**
** uart_set_baud_rate(UART_1, 9600, 40000000);**
** udelay(10000);**
** gsm_send("AT\n");**
** udelay(1000);**
** gsm_send("AT+CIPSHUT\n");**
** udelay(1000);**
** gsm_send("AT+CREG?\r\n"); //check network registration**
** udelay(1000); **
** gsm_send("AT+SAPBR=3,1,\"Contype\",\"GPRS\"\r\n"); //Set GPRS mode**
** udelay(1000);**
** gsm_send("AT+SAPBR=3,1,\"APN\",\"airtelgprs.com\"\r\n"); //Set APN**
** udelay(1000);**
** gsm_send("AT+SAPBR=1,1\r\n"); //Open connection**
** udelay(1000);**
** gsm_send("AT+SAPBR=2,1\r\n"); //Query connection, IP address**
** udelay(1000);**
** gsm_send("AT+CIPSPRT=0\r\n"); //check network registration**
** udelay(3000);**
** udelay(20000);**
** udelay(20000);**
** udelay(20000);**
** gsm_send("AT+CIPSTART=\"TCP\",\"things.ubidots.com\",80\r\n");**
** AT_CIPSEND();**
** udelay(5000);**
** udelay(20000);**
** API_KEY();**
** udelay(5000);**
** gsm_send("AT+CIPCLOSE\r\n");**
}