esp8266: add listening to port

This commit is contained in:
King Kévin 2022-07-14 18:56:36 +02:00
parent a8b7726c35
commit 462a65cb92
2 changed files with 23 additions and 0 deletions

View File

@ -116,6 +116,23 @@ void radio_esp8266_tcp_open(char* host, uint16_t port)
}
}
bool radio_esp8266_listen(bool udp, uint16_t port)
{
char command[256] = {0}; // string to create command
int length = snprintf(command, LENGTH(command), "AT+CIPSTART=\"%s\",\"0.0.0.0\",0,%u\r\n", udp ? "UDP" : "TCP", port); // create AT command to establish a listening connection
if (!length) {
return false;
}
radio_esp8266_transmit((uint8_t*)command, length);
while (!radio_esp8266_activity || !radio_esp8266_success) { // wait for response
__WFI(); // sleep until something happened
}
if (!radio_esp8266_success) { // send AT command did not succeed
return false;
}
return true;
}
void radio_esp8266_send(uint8_t* data, uint8_t length)
{
char command[16 + 1] = {0}; // string to create command

View File

@ -22,6 +22,12 @@ void radio_esp8266_setup(void);
* @note wait for activity to get success status
*/
void radio_esp8266_tcp_open(char* host, uint16_t port);
/** open listening connection
* @param[in] udp if it's an UDP or TCP connection
* @param[in] port port to listen to
* @return if operation succeeded
*/
bool radio_esp8266_listen(bool udp, uint16_t port);
/** send data (requires established connection)
* @param[in] data data to send
* @param[in] length size of data to send