2023-03-05 12:23 PM
char test[10]="beforeAT\n";
char ATcommand[100];
uint8_t ATisOK = 0;
.......................................................... (Other required HAL initiallisation code etc,. i couldn't add due to limit in posting on ST forum.)
int main () {
while(!ATisOK)
{
sprintf(ATcommand,"AT\r\n");
// HAL_UART_Transmit(&huart2,(uint8_t *)ATcommand,strlen(ATcommand),1000);
HAL_UART_Transmit(&huart1,(uint8_t *)ATcommand,strlen(ATcommand),1);
HAL_UART_Receive (&huart1, rx_buffer, 10, 10);
// HAL_UART_Receive (&huart1, rx_buffer, 100, 2000);
// HAL_UART_Transmit(&huart2,(uint8_t *)test1,strlen(test1),1000);
if(strstr((char *)rx_buffer,"OK"))
{
ATisOK = 1;
// HAL_UART_Transmit(&huart2,(uint8_t *)test2,strlen(test2),1000); // just to verify that code working or not
// HAL_UART_Transmit(&huart3,rx_buffer,sizeof(rx_buffer),1000); // AT OK RESPONSE
HAL_UART_Transmit(&huart2,rx_buffer,sizeof(rx_buffer),1);
}
// else HAL_UART_Transmit(&huart2,rx_buffer,sizeof(rx_buffer),50);
// HAL_Delay(1000);
memset(rx_buffer,0,sizeof(rx_buffer));
}
sprintf(ATcommand2,"AT+HTTPPARA=\"CONTENT\",\"application/json\r\n");
// HAL_UART_Transmit(&huart2,(uint8_t *)ATcommand2,strlen(ATcommand2),1000);
HAL_UART_Transmit(&huart1,(uint32_t *)ATcommand2,strlen(ATcommand2),116);
HAL_UART_Receive(&huart1,(uint32_t *)&gsm_buffer,112,115);
HAL_UART_Transmit(&huart2, (uint32_t *)gsm_buffer, sizeof(gsm_buffer), 6);
}
Only AT command response, OK, is getting correctly but other long command, is not working properly. Any how i could fix AT+HTTPINIT command too that enable HTTP on Sim module.
But not able to send more long string using 100 ms timerout etx..
I know, this issue of size of byte & timout selection, but is any smarter way to make this automatic selection of size & timeout as it receiver OK in response..
Actually i'm new too STM cube IDE , move from arduino recently .
Thanks !
Serial debug reponse attached as follows !.
2023-03-05 08:40 PM
You haven't showed your declared variables.What are the baud rates?
Is the gsm data always 112 bytes? Is that where you're having issues receiving large amount of data?
When you send "AT\r\n", is "OK" the only thing returned besides the trailing "\r\n"? Because you send the rx_buffer on huart2 the size of the array instead of the strlen with a timeout of 1ms. What is the longest string length that you are sending?
2023-03-05 09:21 PM
sir, because of space or character limit in post, i couldn't share whole code,
char test[10]="beforeAT\n";
uint8_t ATisOK = 0;
char ATcommand[100];
I tried this below function is but this too not working proper :
void SIMTransmit(char *cmd)
{
memset(rx_buffer,0,sizeof(rx_buffer));
HAL_UART_Transmit(&huart1,(uint8_t *)cmd,strlen(cmd),500);
HAL_UART_Receive (&huart1, rx_buffer, 100, 500);
}
NOR
void gsm_cmd(char *cmd, int gsm_delay)
{
gsm_wait_status=0;
memset(gsm_buffer,'\0',sizeof(gsm_buffer));
HAL_UART_Transmit(&huart1,(uint8_t*) cmd, strlen(cmd),1000);
HAL_Delay(300);
if(gsm_index>0)
{
HAL_Delay(10);
gsm_index=0;
gsm_wait_status=1;
HAL_UART_Transmit(&huart2, (uint8_t *)gsm_buffer, strlen(gsm_buffer), 300);
}
}
Baud rate is 115200,
I'm using simA7672s sim module in UART2 of STf103c8t6
I'm trying to send longer string :
sprintf(ATcommand2,"AT+HTTPPARA=\"CONTENT\",\"application/json\r\n");
Or this below i need to send for Get request :
"AT+HTTPPARA=\"URL\",\"http://34.100.164.184:8000/vehicle_immobilization/v1/immobilize/864180050535405/\"";
2023-03-05 11:33 PM
You say that this code below doesn't work proper. What doesn't work?
Are you really trying to receive 100 bytes? What size is rx_buffer and gsm_buffer?
I tried this below function is but this too not working proper :
void SIMTransmit(char *cmd)
{
memset(rx_buffer,0,sizeof(rx_buffer));
HAL_UART_Transmit(&huart1,(uint8_t *)cmd,strlen(cmd),500);
HAL_UART_Receive (&huart1, rx_buffer, 100, 500);
}
In this function below you're clearing gsm_buffer and then trying to send it using strlen for the size. Well strlen will be zero so nothing will be sent. You have gsm_delay and gsm_wait_status that don't do anything.
void gsm_cmd(char *cmd, int gsm_delay)
{
gsm_wait_status=0;
memset(gsm_buffer,'\0',sizeof(gsm_buffer));
HAL_UART_Transmit(&huart1,(uint8_t*) cmd, strlen(cmd),1000);
HAL_Delay(300);
if(gsm_index>0)
{
HAL_Delay(10);
gsm_index=0;
gsm_wait_status=1;
HAL_UART_Transmit(&huart2, (uint8_t *)gsm_buffer, strlen(gsm_buffer), 300);
}
}
2023-03-06 11:00 AM
Sir, First doesn't not work proper, means, it has same issue as mine line wise code, it has random timeout etc,,, no logical timeout or no necessary delay condition is given in code. so it's working randomly like my code.
Now about 2nd, gsm_cmd function, i'll be sending cmd as variable, that value is as follows, so sir, in Uart1, strlen will not be zero .. it
char getcmd[200]="AT+HTTPPARA=\"URL\",\"http://34.100.164.184:8000/vehicle_immobilization/v1/immobilize/864180050535405/\"";
However i didn't use this in above code, as i still couldn't understand fully yet, i just reallise, it should have HAL_UART_Recieve function, then it shoudd work something.
Can You please correct the above function, so It could communicate properly with my Sim module A7672s, i'm being confuse as per my arduino coding understanding.
2023-03-06 11:19 AM
Watch for blocking and delaying functions. You need to be prepared to receive data from the modem when it might respond, not when you get around to it.
2023-09-04 07:00 AM