2025-01-14 06:52 AM - last edited on 2025-01-14 07:14 AM by Andrew Neil
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;
}
2025-01-14 07:11 AM - edited 2025-01-14 07:14 AM
See here for tips on debugging serial comms:
BTW:
@Andryck_Sant wrote:I am using an STM32L0 to control the SIM via UART
Your use of "SIM" here is confusing!
A "SIM" in the context of GSM Cellular Comms is the SIM card - one of these:
(or the equivalent in chip form)
So you're not controlling the SIM - you're controlling the Y7080E module.
The module manufacturer is SIMCom.
2025-01-14 09:29 AM
Sorry about that! I got confused between module and SIM. In this case, my problem is specifically with the module.
I'm using STM32 Cube IDE version 1.17.0 to develop the mcu firmware.
I've already debugged the UART communication between the module and the mcu and everything seems to be ok. So, I can't understand why the message isn't appearing on the mqtt explorer.
I'll send attached bellow the image of the comm debug.
2025-01-14 09:58 AM
You said you have two cases - one works, and one doesn't.
So have you captured the comms traces in both cases, and compared them?
It would be clearer to post the trace as text rather than a screenshot - see here for preserving layout without adding syntax highlighting.