Hi, i am trying to send Meter_data and sensor data to Server at HTTP Level through GET Method, how we send dynamic data continuously ? every time voltage will be change here i am storing data in the buffer but how i need to send server please suggest me .my server understand only GET Method.
char Command_ATE0[] = "ATE0\r\n";
char Command_AT[] = "AT\r\n";
char Command_SAPBR[] = "AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r\n";
char Command2_SAPBR[] = "AT+SAPBR=3,1,\"APN\",\"airtelgprs.com\"\r\n";
char Command3_SAPBR[] = "AT+SAPBR=1,1\r\n";
char Command4_SAPBR[] = "AT+SAPBR=2,1\r\n";
char Command_HTTPINIT[] = "AT+HTTPINIT\r\n";
char Command_HTTPPARA[] = "AT+HTTPPARA=\"CID\",1\r\n";
// char Command1_HTTPPARA[] = "AT+HTTPPARA=“URL”,"amr.sysamigo.com/base/amr/?device_string=Device_ID=865067026174667,Lat=0.000000,Long=0.000000,AMR_S.No=17081343,VOL=232,Power=0002.5"\r\n";
// char Command1_HTTPPARA[] = “AT+HTTPPARA=“URL”,“server_buf”\r\n”;
char Command1_HTTPPARA[] = "AT+HTTPPARA=\"str1\"\r\n";
char Command_HTTPACTION[] = "AT+HTTPACTION=0\r\n";
char AMR_SNo[50];
char VOL[40];
char Response_ATE0[] = "OK";
char Response_AT[] = "OK";
char Response_SAPBR[] = "OK";
char Response_SAPBR2[] = "OK";
char Response_SAPBR3[] = "OK";
char Response_SAPBR4[] = "";
char Response_HTTPINIT[] = "OK";
char Response_HTTPPARA[] = "OK"; // "STATE: IP INITIAL";
char AT_Error[5] = "ERROR";
char Response1_HTTPPARA[] = "OK";
char Response_HTTPACTION[] = "OK";
char Response_HTTPACTION1[] = "+HTTPACTION:0,200,0";
int fd;
// char server_buf[512];
char DEVICE_ID[]= "865067026174667";
// char Header[] = "GET /base/amr/?device_string=";
char Header[] = "amr.sysamigo.com/base/amr/?device_string=";
char Lat[] = "0.000000";
char Long[] = "1.000000";
// char Data_buf[] = "17081343,VOL=230";
// char AMR_S.No[];
// char VOL[];
char Power[] = “0012.5”;
unsigned int buf_len[32];
unsigned int len;
/==========================================================================================/
/* main function /
/==========================================================================================*/
char str1[145]= ““URL”,”;
int main(void)
{
gpio_export();
gpio_dir_in();
openPort();
int gpio =129;
char buf[40];
int fd1;
/* exporting the gpio pin for METER */
fd1 = open("/sys/class/gpio/export", O_WRONLY);
if(fd1 == -1) {
printf("can't open gpio129\n");
}
sprintf(buf,"%d",gpio);
write(fd1, buf, strlen(buf));
close(fd1);
//Set the direction in the GPIO folder
sprintf(buf,"/sys/class/gpio/gpio%d/direction", gpio);
fd1 = open(buf, O_RDWR);
write(fd1, "out", 3); // Set out direction
send_flag=1;
while(1)
{
gpio_read();
}
return 0;
}
/================================================================================================/
/* open the serial port, sending data to the gprs /
/================================================================================================*/
void uart_gprs()
{
int k,i; /*File Descriptor*/
char read_buffer[40];
int bytes_written = 0;
int nread=0;
char read_buff[10];
printf("\n +----------------------------------+");
printf("\n | Serial Port Write |");
printf("\n +----------------------------------+");
fd = open("/dev/ttySAC1",O_RDWR | O_NOCTTY | O_NDELAY);
if(fd == -1) /* Error Checking */
printf("\n Error! in Opening /dev/ttySAC1 ");
else
printf("\n /dev/ttySAC1 Opened Successfully ");
/*---------- Setting the Attributes of the serial port using termios structure --------- */
struct termios SerialPortSettings; /* Create the structure */
tcgetattr(fd, &SerialPortSettings); /* Get the current attributes of the Serial port */
cfsetispeed(&SerialPortSettings,B9600); /* Set Read Speed as 9600 */
cfsetospeed(&SerialPortSettings,B9600); /* Set Write Speed as 9600 */
SerialPortSettings.c_cflag &= ~PARENB; /* Disables the Parity Enable bit(PARENB),So No Parity */
SerialPortSettings.c_cflag &= ~CSTOPB; /* CSTOPB = 2 Stop bits,here it is cleared so 1 Stop bit */
SerialPortSettings.c_cflag &= ~CSIZE; /* Clears the mask for setting the data size */
SerialPortSettings.c_cflag |= CS8; /* Set the data bits = 8 */
SerialPortSettings.c_cflag &= ~CRTSCTS; /* No Hardware flow Control */
SerialPortSettings.c_cflag |= CREAD | CLOCAL; /* Enable receiver,Ignore Modem Control lines */
SerialPortSettings.c_iflag &= ~(IXON | IXOFF | IXANY); /* Disable XON/XOFF flow control both i/p and o/p */
SerialPortSettings.c_iflag &= ~(ICANON | ECHO | ECHOE | ISIG); /* Non Cannonical mode */
SerialPortSettings.c_oflag &= ~OPOST; /*No Output Processing*/
SerialPortSettings.c_cc[VMIN] = 0;
SerialPortSettings.c_cc[VTIME] = 10;
if((tcsetattr(fd,TCSANOW,&SerialPortSettings)) != 0) /* Set the attributes to the termios structure*/
printf("\n ERROR ! REG?\r\n",10);
else
printf("\n BaudRate = 9600 \n StopBits = 1 \n Parity = none\n");
/*------------------------------- Write data to serial port -----------------------------*/
while(1)
{
sleep(5);
printf("continue scheduler.....!!\n");
if(gprs_send_flag)
{
gprs_send_flag=0;
switch(http_cmd)
{
case 1:
printf("\n ATE0 status :\n");
tcflush(fd, TCIFLUSH); //Discards old data in the rx buffer
write(fd,Command_ATE0,strlen(Command_ATE0));
status= Get_responce(fd,Response_ATE0,strlen(Response_ATE0));
sleep(2);
break;
case 2:
printf("\n AT init status:\n");
tcflush(fd, TCIFLUSH);
write(fd,Command_AT,strlen(Command_AT));
status=Get_responce(fd,Response_AT,strlen(Response_AT));
sleep(2);
break;
case 3:
printf("\n Command_SAPBR Connetion type staus:\n");
tcflush(fd, TCIFLUSH);
write(fd,Command_SAPBR,strlen(Command_SAPBR));
status= Get_responce(fd,Response_SAPBR,strlen(Response_SAPBR));
sleep(2);
break;
case 4:
printf("\n Command2_AT+SAPBR APN :\n");
tcflush(fd, TCIFLUSH);
write(fd, Command2_SAPBR,strlen(Command2_SAPBR));
status= Get_responce(fd,Response_SAPBR2,strlen(Response_SAPBR2));
sleep(2);
break;
case 5:
printf("\n Command3_AT+SAPBR Enable the Gprs :\n");
tcflush(fd, TCIFLUSH);
write(fd,Command3_SAPBR,strlen(Command3_SAPBR));
sleep(2);
status= Get_responce(fd,Response_SAPBR3,strlen(Response_SAPBR3));
sleep(2);
break;
case 6:
printf("\n Command4_AT+SAPBR check for connection :\n");
tcflush(fd, TCIFLUSH);
write(fd,Command4_SAPBR,strlen(Command4_SAPBR));
status= Get_responce(fd,Response_SAPBR4,strlen(Response_SAPBR4));
sleep(2);
break;
case 7:
printf("\n Command_AT+HTTPINIT: \n");
tcflush(fd, TCIFLUSH);
write(fd,Command_HTTPINIT,strlen(Command_HTTPINIT));
status= Get_responce(fd,Response_HTTPINIT,strlen(Response_HTTPINIT));
sleep(2);
break;
case 8:
printf("\n Command_AT+HTTPPARA setting up the HTTP bearer profile identifier:\n");
tcflush(fd, TCIFLUSH);
write(fd,Command_HTTPPARA,strlen(Command_HTTPPARA));
status= Get_responce(fd,Response_HTTPPARA,strlen(Response_HTTPPARA));
sleep(2);
break;
case 9:
printf("\n Command1_AT+HTTPPARA:\n"); // Set the url to the address of the webpage you want to access
tcflush(fd, TCIFLUSH);
write(fd,Command1_HTTPPARA,strlen(Command1_HTTPPARA));
sleep(1);
status= Get_responce(fd, Response1_HTTPPARA,strlen(Response1_HTTPPARA));
sleep(2);
break;
case 10:
printf("\n Command_AT+HTTPACTION start HTTP Get Session:\n"); // Start the HTTP GET session, by giving this command
tcflush(fd, TCIFLUSH);
write(fd,Command_HTTPACTION,strlen(Command_HTTPACTION));
sleep(2);
printf("waiting for response\n");
sleep(20);
status=Get_responce(fd,Response_HTTPACTION1,strlen(Response_HTTPACTION1));
sleep(2);
break;
i am kindly waiting for you response…
Regards
Naresh
have a great day…