Help using SIMCom Y7080E on STM32L0
I would like to request assistance regarding an integration issue between my microcontroller(STM32L051C8T6) and the SIM Y7080E (an NB-IoT connectivity chip being used to publish messages via MQTT).
I am using an STM32L0 to control the SIM via UART, but for some reason, when I use the functions I wrote in a library to manage message transmission, the device responds that the message was successfully published to the MQTT broker. However, I cannot see the message using MQTT Explorer.
On the other hand, if I follow the same routine using commands by directly transmitting string content to the SIM via UART, the message gets published. Still, this doesn't always work either.
The difference is that in the first case, I concatenate strings and build the entire command body with the necessary information. In the second case, I assume the information is immutable and predefine it in the variable declaration for each command in the process.
I have reviewed all the documentation provided by the SIM manufacturer and followed the examples they supplied. With this approach, I successfully published messages by writing a test code in MicroPython (just to verify the device's functionality). However, the goal is to achieve the same result in C for this project. As mentioned earlier, on the STM32L0, I was only able to publish messages when the strings with the parameters were predefined. If I try to build the command in a transmission buffer, I receive a confirmation from the chip indicating the command is correct, but I notice that the MQTT broker does not receive any message.
Please, check the code below:
uint8_t y7080_mqtt_transmit(Y7080_HandleTypeDef *sim, uint16_t volume, float tension){
uint8_t mqtt_topic[MQTT_TOPIC_SIZE], mqtt_payload[MQTT_PAYLOAD_SIZE], *aux;
uint8_t mqtt_did[MQTT_DID_SIZE];
memset(mqtt_did,0,MQTT_DID_SIZE);
memset(mqtt_topic,0, sizeof(mqtt_topic));
memset(mqtt_payload,0, sizeof(mqtt_payload));
y7080_clear_buffer(sim);
char mqtt_start_cmd[30],
mqtt_accq_client[45],
mqtt_topic_cmd[40],
mqtt_payload_cmd[40],
mqtt_pub_cmd[30],
mqtt_disc_cmd[30];
snprintf(mqtt_start_cmd, sizeof(mqtt_start_cmd),"%s",MQTT_START_CMD);
snprintf(mqtt_accq_client, sizeof(mqtt_accq_client),"%s\"td_etc0\",0\r\n",MQTT_ACC_CLI_CMD);
snprintf((char *)mqtt_topic, MQTT_TOPIC_SIZE, "marcosrangel/test\r\n");
snprintf(mqtt_topic_cmd, sizeof(mqtt_topic_cmd), "%s%d\r\n",MQTT_WRITE_TOPIC_CMD,strlen((char *)mqtt_topic));
snprintf((char *)mqtt_payload, MQTT_PAYLOAD_SIZE, "1234\r\n");
snprintf(mqtt_payload_cmd, sizeof(mqtt_payload_cmd), "%s%d\r\n", MQTT_WRITE_PAYLOAD_CMD, strlen((char *)mqtt_payload));
snprintf(mqtt_pub_cmd, sizeof(mqtt_pub_cmd), "%s1,60\r\n",MQTT_PUB_CMD);
snprintf(mqtt_disc_cmd, sizeof(mqtt_disc_cmd), "%s",MQTT_DISCONNECT_CMD);
HAL_UART_Transmit(sim->sim_uart, (uint8_t *)mqtt_start_cmd, strlen(mqtt_start_cmd),1000);
y7080_wait_response(sim);
y7080_clear_buffer(sim);
HAL_UART_Transmit(sim->sim_uart, (uint8_t *)mqtt_accq_client, strlen(mqtt_accq_client),1000);
y7080_wait_response(sim);
y7080_clear_buffer(sim);
aux = read_eeprom(8);
memcpy(mqtt_did, aux, strlen((char *)aux));
y7080_mqtt_connect(sim);
y7080_clear_buffer(sim);
HAL_UART_Transmit(sim->sim_uart, (uint8_t *)mqtt_topic_cmd, strlen(mqtt_topic_cmd),1000);
y7080_wait_response(sim);
y7080_clear_buffer(sim);
if(HAL_UART_Transmit(sim->sim_uart, (uint8_t *)mqtt_topic, strlen((char *)mqtt_topic),1000) != HAL_OK){
y7080_clear_buffer(sim);
return 1;
}
y7080_wait_response(sim);
y7080_clear_buffer(sim);
if(HAL_UART_Transmit(sim->sim_uart, (uint8_t *)mqtt_payload_cmd, strlen(mqtt_payload_cmd), 1000)!= HAL_OK){
return 1;
}
y7080_wait_response(sim);
y7080_clear_buffer(sim);
if (HAL_UART_Transmit(sim->sim_uart, mqtt_payload, strlen((char *)mqtt_payload), 1000) != HAL_OK){
return 1;
}
y7080_wait_response(sim);
y7080_clear_buffer(sim);
if(HAL_UART_Transmit(sim->sim_uart, (uint8_t *)mqtt_pub_cmd, strlen(mqtt_pub_cmd), 1000)!= HAL_OK){
return 1;
}
y7080_wait_response(sim);
y7080_clear_buffer(sim);
if(HAL_UART_Transmit(sim->sim_uart, (uint8_t *)mqtt_disc_cmd, strlen(mqtt_disc_cmd), 1000) != HAL_OK){
return 1;
}
y7080_wait_response(sim);
y7080_clear_buffer(sim);
return 0;
}
