diff --git a/lib/radio_esp8266.c b/lib/radio_esp8266.c index 6f5fc1a..58d25be 100644 --- a/lib/radio_esp8266.c +++ b/lib/radio_esp8266.c @@ -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); } } diff --git a/lib/radio_esp8266.h b/lib/radio_esp8266.h index b66e7f5..cf95451 100644 --- a/lib/radio_esp8266.h +++ b/lib/radio_esp8266.h @@ -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