1.使用AP模式,判断是否有设备通过wifi接入
void wifi_event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
if (event_id == WIFI_EVENT_AP_STACONNECTED) {
wifi_event_ap_staconnected_t* event = (wifi_event_ap_staconnected_t*) event_data;
ESP_LOGI( TAGb,"station "MACSTR" join, AID=%d",
MAC2STR(event->mac), event->aid);
Tcpcreate();
} else if (event_id == WIFI_EVENT_AP_STADISCONNECTED) {
wifi_event_ap_stadisconnected_t* event = (wifi_event_ap_stadisconnected_t*) event_data;
ESP_LOGI(TAGb,"station "MACSTR" leave, AID=%d",
MAC2STR(event->mac), event->aid);
}
}
2.向nRF24L01写指令时,我参考stm32的代码,根据stm32的代码,将SPI设置为每发送一个字节,同时读取一个字节。(HAL库是可以直接调用这个函数,esp32没有)
uint8_t SPIx_ReadWriteByte(uint8_t data)
{
uint8_t data_out = data;
uint8_t data_in = 0;
uint8_t *p=&data_in;
t.length = 8;
t.tx_buffer = &data_out;
t.rx_buffer = &data_in;
spi_device_polling_transmit(spi, &t);
p=t.rx_buffer;
return *p;
}
ESP32源码给这 ,写的挺乱的
离线