esp8266: add simple at command function
This commit is contained in:
parent
e44110d315
commit
61a427c18a
|
@ -62,6 +62,31 @@ static void radio_esp8266_transmit(uint8_t* data, uint8_t length) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** transmit string to radio
|
||||||
|
* @param[in] data data to transmit
|
||||||
|
* @param[in] length length of data to transmit
|
||||||
|
*/
|
||||||
|
static void radio_esp8266_transmits(char* str) {
|
||||||
|
if (NULL == str) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const uint16_t length = strlen(str);
|
||||||
|
radio_esp8266_transmit((uint8_t*)str, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** transmit string to radio
|
||||||
|
* @param[in] data data to transmit
|
||||||
|
* @param[in] length length of data to transmit
|
||||||
|
*/
|
||||||
|
static void radio_esp8266_transmit_at(char* at) {
|
||||||
|
if (NULL == at) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
radio_esp8266_transmits("AT");
|
||||||
|
radio_esp8266_transmits(at);
|
||||||
|
radio_esp8266_transmits("\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
void radio_esp8266_setup(void)
|
void radio_esp8266_setup(void)
|
||||||
{
|
{
|
||||||
// configure pins
|
// configure pins
|
||||||
|
@ -93,7 +118,7 @@ void radio_esp8266_setup(void)
|
||||||
radio_esp8266_activity = false;
|
radio_esp8266_activity = false;
|
||||||
radio_esp8266_success = false;
|
radio_esp8266_success = false;
|
||||||
|
|
||||||
radio_esp8266_transmit((uint8_t*)"AT\r\n", 4); // verify if module is present
|
radio_esp8266_transmit_at(""); // verify if module is present
|
||||||
while (!radio_esp8266_activity || !radio_esp8266_success) { // wait for response
|
while (!radio_esp8266_activity || !radio_esp8266_success) { // wait for response
|
||||||
__WFI(); // sleep until something happened
|
__WFI(); // sleep until something happened
|
||||||
}
|
}
|
||||||
|
@ -154,7 +179,7 @@ void radio_esp8266_send(uint8_t* data, uint8_t length)
|
||||||
|
|
||||||
void radio_esp8266_close(void)
|
void radio_esp8266_close(void)
|
||||||
{
|
{
|
||||||
radio_esp8266_transmit((uint8_t*)"AT+CIPCLOSE\r\n", 13); // send AT command to close established connection
|
radio_esp8266_transmit_at("+CIPCLOSE"); // send AT command to close established connection
|
||||||
}
|
}
|
||||||
|
|
||||||
/** USART interrupt service routine called when data has been transmitted or received */
|
/** USART interrupt service routine called when data has been transmitted or received */
|
||||||
|
|
Loading…
Reference in New Issue