nimaltd / gsm_v5

gsm module library for STM32 LL
GNU General Public License v3.0
231 stars 85 forks source link

Sending data over TCP/UDP in transparent mode #32

Open LinBencheng opened 3 years ago

LinBencheng commented 3 years ago

This library is very wonderful, thanks I’m trying to send binary data over TCP to a server using SIM800. I need to send binary data, without coding, non-ASCII characters indeed. Some of the data bytes can be 0x1A which coincides with the send command, doing that all data were transmitted early. Using AT+CIPSEND=< length > solves the problem because data are transmitted when the content of the buffer reaches that quantity. But this latest version, TCP-related functions removed and never touched about this. Could you add TCP functions?

nimaltd commented 3 years ago

Hello. your welcome. I always add a function when I need it. if you add early than me, send to me please .

LinBencheng commented 3 years ago

Yes, I tried, but doesn't work properly. To send the binary data, I needed to add new function that can send binary data. In the atc_command function, you used strlen() function to get length of data. But in binary data, can't use strlen() function. So I modified the atc_command() function like this. But still don't work properly

int8_t atc_data_send(atc_t atc, uint8_t data, uint16_t len, uint32_t timeout_ms, char answer, uint16_t answer_size, int items, ...) { if (atc->inited == false) return -1; if (atc_lock(atc, timeout_ms) == false) return -1; if (answer != NULL) memset(answer, 0, answer_size); uint8_t foundIndex = 0; va_list tag; va_start(tag, items); for (uint8_t i = 0; i < items; i++) { char str = va_arg(tag, char); atc->searchCmd[i] = (char) atc_alloc(strlen(str) + 1); if (atc->searchCmd[i] != NULL) { strcpy(atc->searchCmd[i], str); atc->searchCmd[i][strlen(str)] = 0; } if (items >= _ATC_SEARCH_CMD_MAX) break; } va_end(tag); atc_transmit(atc, data, len); uint32_t start = HAL_GetTick(); while (HAL_GetTick() - start < timeout_ms) { atc_delay(1); if (atc_available(atc)) { atc_printf("[%s] %s", atc->name, (char )atc->rxBuffer); atc_search(atc); char found = atc_searchAnswer(atc, items, &foundIndex); if (found != NULL && answer != NULL) strncpy(answer, found, answer_size); atc_empty(atc); if (found != NULL) break; } } for (uint8_t i = 0; i < items; i++) atc_free(atc->searchCmd[i]); atc_unlock(atc); return foundIndex; }

Would you check this function?

d-serj commented 3 years ago

@LinBencheng in the transparent mode you are able to send only raw binary data. This data will be sent directly to the TCP server. SIM800 doesn't process your data in the transparent mode and doesn't send any response to the data you have sent, it will send you only raw data from TCP server if received. So I would recommend you to use uart_transmit / uart_receive functions directly without this library. You can use atc only to activate the transparent mode.

Pseudocode:

atc_transmit(atc, command_to_activate_transparent, command_len);

if (sim800_is_in_transparent())
{
  uart_send_raw(raw_data_buff, raw_data_buff_size);
  uart_receive_raw(receive_buffer, receive_buffer_size);
}
else
{
  atc_transmit(atc, command, command_len);
}
LinBencheng commented 3 years ago

Thank you very much. Yes, Already I could send raw binary data using transparent mode. But In transparent mode, all other AT commands are disabled. To use AT commands such as SMS commands, it should be escaped from the data transparent mode. So I was thinking AT+CIPSEND=< length > in normal mode could be useful. I tested with SIMCOM tester and AT+CIPSEND=< length > worked But in case of a byte take a certain value it is not transmitted properly, such as 0x00 (in this case, the byte is not transmitted) or 0x0A (line-feed or new line, in this case, the server receives 0x0A 0x0D, an extra byte). I don’t know if the module interprets certain values, low values in the ASCII table, or a problem on the server-side.

nimaltd commented 3 years ago

It seems ok. but i can not test this function. i don't have a board and free time to test it. please debug it to find the problem. thanks On Thursday, July 1, 2021, 07:24:23 PM GMT+4:30, LinBencheng @.***> wrote:

Yes, I tried, but doesn't work properly. To send the binary data, I needed to add new function that can send binary data. In the atc_command function, you used strlen() function to get length of data. But in binary data, can't use strlen() function. So I modified the atc_command() function like this. But still don't work properly

int8_t atc_data_send(atc_t atc, uint8_t data, uint16_t len, uint32_t timeout_ms, char answer, uint16_t answer_size, int items, ...) { if (atc->inited == false) return -1; if (atc_lock(atc, timeout_ms) == false) return -1; if (answer != NULL) memset(answer, 0, answer_size); uint8_t foundIndex = 0; va_list tag; va_start(tag, items); for (uint8_t i = 0; i < items; i++) { char str = va_arg(tag, char); atc->searchCmd[i] = (char) atc_alloc(strlen(str) + 1); if (atc->searchCmd[i] != NULL) { strcpy(atc->searchCmd[i], str); atc->searchCmd[i][strlen(str)] = 0; } if (items >= _ATC_SEARCH_CMD_MAX) break; } va_end(tag); atc_transmit(atc, data, len); uint32_t start = HAL_GetTick(); while (HAL_GetTick() - start < timeout_ms) { atc_delay(1); if (atc_available(atc)) { atc_printf("[%s] %s", atc->name, (char )atc->rxBuffer); atc_search(atc); char found = atc_searchAnswer(atc, items, &foundIndex); if (found != NULL && answer != NULL) strncpy(answer, found, answer_size); atc_empty(atc); if (found != NULL) break; } } for (uint8_t i = 0; i < items; i++) atc_free(atc->searchCmd[i]); atc_unlock(atc); return foundIndex; }

Would you check this function?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub, or unsubscribe.