Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending data over TCP/UDP in transparent mode #32

Open
LinBencheng opened this issue Jun 24, 2021 · 5 comments
Open

Sending data over TCP/UDP in transparent mode #32

LinBencheng opened this issue Jun 24, 2021 · 5 comments

Comments

@LinBencheng
Copy link

LinBencheng commented Jun 24, 2021

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
Copy link
Owner

nimaltd commented Jun 26, 2021

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

@LinBencheng
Copy link
Author

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
Copy link
Contributor

d-serj commented Jul 1, 2021

@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
Copy link
Author

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
Copy link
Owner

nimaltd commented Jul 3, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants