ESP8266 Использование wifimanager с onSoftAPModeProbeRequestReceived - PullRequest
0 голосов
/ 01 декабря 2018

Я хотел бы использовать https://github.com/tzapu/WiFiManager в сочетании с onSoftAPModeProbeRequestReceived.Конечная цель - настроить Wi-Fi с помощью WifiMaager, затем «переключиться» и отправить информацию о пробном запросе через Wi-Fi.

Я получаю это для работы без менеджера Wi-Fi, используя следующее

#include <ESP8266httpUpdate.h>
#include <ESP8266WiFi.h> 
#include <esp8266httpclient.h>
#include <stdio.h>

const char* ssid     = "someap";         // The SSID (name) of the Wi-Fi 
network you want to connect to
const char* password = "";     // The password of the Wi-Fi network
int status = WL_IDLE_STATUS;  
String macAddr = "";
WiFiEventHandler probeRequestPrintHandler; 
WiFiEventHandler probeRequestBlinkHandler;

bool blinkFlag;

void setup() {
    Serial.begin(115200);
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, HIGH);
    Serial.print("Starting");
    WiFi.persistent(false);
    WiFi.mode(WIFI_AP);
    WiFi.softAP(ssid, password);

    probeRequestPrintHandler =
    WiFi.onSoftAPModeProbeRequestReceived(&onProbeRequestPrint);
    probeRequestBlinkHandler =
    WiFi.onSoftAPModeProbeRequestReceived(&onProbeRequestBlink);

while ( status != 3) 
{
Serial.print("Attempting to connect to network, SSID: ");
Serial.println(ssid);
status = WiFi.status();
WiFi.begin(ssid, password);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println(WiFi.localIP()); 
}

void onProbeRequestPrint(const WiFiEventSoftAPModeProbeRequestReceived& evt) 
{
if (macAddr != macToString(evt.mac))
{
macAddr = macToString(evt.mac);   
Serial.print("Probe request from: ");
Serial.print(macToString(evt.mac));
Serial.print(" RSSI: ");
Serial.println(evt.rssi);
}
}
void onProbeRequestBlink(const WiFiEventSoftAPModeProbeRequestReceived&) {
blinkFlag = true;
}
void loop() {
if (blinkFlag) {
HTTPClient http;  //Declare an object of class HTTPClient
http.begin("http://requestbin.fullcontact.com/110f1ss6a1?test=true");  
//Specify request destination
int httpCode = http.GET();     
Serial.println(httpCode);
if (httpCode > 0) { //Check the returning code
  String payload = http.getString();   //Get the request response payload
  Serial.println(payload);                     //Print the response payload
}
http.end();   //Close connection
macAddr="";
blinkFlag = false;
digitalWrite(LED_BUILTIN, LOW);
delay(100);
digitalWrite(LED_BUILTIN, HIGH);

status = 0;
}
delay(1000);
}
String macToString(const unsigned char* mac) {
char buf[20];
snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x",
       mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return String(buf);
}

Когда соединение установлено, мы полагаемся на WiFiEventHandler probeRequestPrintHandler; и WiFiEventHandler probeRequestBlinkHandler probeRequestBlinkHandler;Это работает и собирает MAC-адрес, как бы то ни было, он не может подключиться к точке доступа.Нужно ли закрыть текущий режим Wi-Fi, открыть соединение и закрыть его?

1 Ответ

0 голосов
/ 07 декабря 2018

Кажется, все, что мне нужно было сделать, это добавить WiFi.begin(); до void loop()

...