esp8266: add connected function
This commit is contained in:
parent
ac7b075b1c
commit
da57f5ee40
@ -141,10 +141,32 @@ void radio_esp8266_reset(void)
|
||||
while(rx_used < 13 || memcmp((char*)&rx_buffer[rx_used - 13], "WIFI GOT IP\r\n", 13) != 0) { // wait to have IP
|
||||
__WFI(); // sleep until something happened
|
||||
}
|
||||
radio_esp8266_transmit((uint8_t*)"ATE0\r\n", 6); // disable echoing
|
||||
}
|
||||
|
||||
bool radio_esp8266_connected(void)
|
||||
{
|
||||
// verify if we ware connect to access point
|
||||
radio_esp8266_transmit_at("+CWJAP_CUR?");
|
||||
while (!radio_esp8266_activity || !radio_esp8266_success) { // wait for response
|
||||
__WFI(); // sleep until something happened
|
||||
}
|
||||
if (rx_used < 5 || 0 == memcmp((char*)&rx_buffer[rx_used - 5], "No AP", 5)) {
|
||||
rx_used = 0; // finished using the buffer
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if we have an IP
|
||||
radio_esp8266_transmit_at("+CIPSTA_CUR?"); // verify if module is present
|
||||
while (!radio_esp8266_activity || !radio_esp8266_success) { // wait for response
|
||||
__WFI(); // sleep until something happened
|
||||
}
|
||||
if (rx_used < 17 || '0' == rx_buffer[16]) { // check for +CIPSTA_CUR:ip:"0.0.0.0"
|
||||
rx_used = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
rx_used = 0; // clear buffer
|
||||
return true;
|
||||
}
|
||||
|
||||
void radio_esp8266_tcp_open(char* host, uint16_t port)
|
||||
|
@ -22,6 +22,10 @@ extern uint16_t radio_esp8266_received_len;
|
||||
void radio_esp8266_setup(void);
|
||||
/** reset ESP */
|
||||
void radio_esp8266_reset(void);
|
||||
/** check if connect to the network
|
||||
* @return if connected to network
|
||||
*/
|
||||
bool radio_esp8266_connected(void);
|
||||
/** establish TCP connection
|
||||
* @param[in] host host to connect to
|
||||
* @param[in] port TCP port to connect to
|
||||
|
Loading…
Reference in New Issue
Block a user