2018-05-09 06:46 AM
Posted on May 09, 2018 at 15:46
Hello there,
We are using quectel's BG96 module with STM32L432KB over UART, to send some data to a cloud service using MQTT protocol.
For this, We are using HAL_UART Drivers to transmit MQTT AT commands and receive its response.
We need to send CTRL+Z from our controller to BG96 module over UART, so that BG96 can understand 'End of Transmission'.
But some how we are not able to not know that is the data is transmitted or not and even also not sure that data is receiving.
code which i have written for the this:
uint8_t gsm_connt[45] = 'AT+CGDCONT=1,\'IP\',\'bsnllive\'\r'; // AT command to be send..
uint8_t gsm_activate[15] = 'AT+CGACT=1\r'; // AT command to be send..
uint8_t dummy_mqtt[100]={0}; // Dummy Variables to store the Rx data..
HAL_UART_Transmit(&huart1,(uint8_t *)gsm_connt,sizeof(gsm_connt),1000);
HAL_UART_Receive(&huart1 , (uint8_t *)&dummy_mqtt, sizeof(dummy_mqtt) , 1000);
Note: Above code is for the reference purpose and above function for transmitting and receiving the data over the UART.
Sending CTRL+Z is really important here.
We know that CTRL+Z = 26(DEc) and 0x1A (HEX).
Suppose we need to send 'ABC'(message) + CTRL^Z over UART, we have tried all the below options. But some how we could not receive expected results.
1. char msg[] = 'ABC';
1) char ctrl_z = '0x1A' OR '26'; OR
2) uint8_t ctrl_z = '0x1A' OR '26'; OR
3) uint8_t ctrl_z = 0x1A OR 26;
HAL_UART_Transmit(&huart1,(uint8_t *)msg, sizeof(msg), 1000);
HAL_UART_Transmit(&huart1, &ctrl_z, sizeof(ctrl_z), 1000);
HAL_UART_Receive(&huart1, (uint8_t*)&buf, sizeof(buf),1000);
2. uint8_t msg[] = {'0x41','0x42','0x43','0x1A'} OR {'65', '66', '67','26'}
uint8_t msg[] = {0x41, 0x42, 0x43, 0x1A} OR {65, 66, 67, 26};
HAL_UART_Transmit(&huart1,(uint8_t *)msg, sizeof(msg), 1000);
HAL_UART_Receive(&huart1, (uint8_t*)&buf, sizeof(buf),1000);
Problem: We are not able to publish the data to the mqtt server using HAL UART DRIVER ... !!!
Can you share some demo codes for the same. It will be helpful to us.
Thanks & Regards,
Sachin
2018-05-09 06:58 AM
Don't use sizeof() for strings, use strlen(), or the length returned by sprintf()
Using sizeof() will result in NUL characters being sent across the interface, and either confusing the modem, or corrupting the data being transferred, or looking unexpected on the other size.
As an escaped character CTRL-Z is '\x1A'
char foo[] = { 26 };
2018-05-21 07:30 AM
Okay Sure ....
thanks for your suggestions
Turvey.Clive.002
. I'm sure this will be helpful for me immediately.