esp8266: add UDP support

This commit is contained in:
King Kévin 2021-09-15 18:34:44 +02:00
parent 799584a210
commit 017c649842
2 changed files with 6 additions and 5 deletions

View File

@ -107,11 +107,11 @@ void radio_esp8266_setup(void)
}
}
void radio_esp8266_tcp_open(char* host, uint16_t port)
void radio_esp8266_open(const char* host, uint16_t port, bool tcp)
{
char command[256] = {0}; // string to create command
int length = snprintf(command, LENGTH(command), "AT+CIPSTART=\"TCP\",\"%s\",%u\r\n", host, port); // create AT command to establish a TCP connection
if (length>0) {
int length = snprintf(command, LENGTH(command), "AT+CIPSTART=\"%s\",\"%s\",%u\r\n", tcp ? "TCP" : "UDP", host, port); // create AT command to establish a TCP connection
if (length > 0) {
radio_esp8266_transmit((uint8_t*)command, length);
}
}

View File

@ -18,10 +18,11 @@ extern volatile bool radio_esp8266_success;
void radio_esp8266_setup(void);
/** establish TCP connection
* @param[in] host host to connect to
* @param[in] port TCP port to connect to
* @param[in] port port number to connect to
* @param[in] tcp if connect to a TCP port (else UDP)
* @note wait for activity to get success status
*/
void radio_esp8266_tcp_open(char* host, uint16_t port);
void radio_esp8266_open(const char* host, uint16_t port, bool tcp);
/** send data (requires established connection)
* @param[in] data data to send
* @param[in] length size of data to send