Почему последовательный монитор просто показывает бесконечный цикл «точки», а не другие последовательные отпечатки? - PullRequest
0 голосов
/ 05 июня 2019

Код должен передать объект JSON и печать "привет" в цикле void, но он просто повторяет "точку" из установки void.Что я упустил?

Я пробовал разные последовательные отпечатки в основном цикле, но ни один из них фактически не передается.Может быть, в настройке void есть бесконечный цикл?

#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
#include <vector>

const char* apSsid     = "ap-ssid";
const char* apPassword = "ap-password";
const char* clientSsid     = "client-ssid";
const char* clientPassword = "client-password";


WiFiEventHandler probeRequestPrintHandler;

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);
}

std::vector<WiFiEventSoftAPModeProbeRequestReceived> myList;

void onProbeRequestPrint(const WiFiEventSoftAPModeProbeRequestReceived& evt) {
  myList.push_back(evt);
}

void setup() {
  Serial.begin(115200);
  Serial.print("Hello!");

  // Don't save WiFi configuration in flash - optional
  WiFi.persistent(false);

  WiFi.mode(WIFI_AP_STA);
  WiFi.softAP(apSsid, apPassword);
  WiFi.begin(clientSsid, clientPassword);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(100);
  }
  Serial.print("");
  probeRequestPrintHandler = WiFi.onSoftAPModeProbeRequestReceived(&onProbeRequestPrint);
}

void loop() {
  delay(3000);
  String json = "";
  DynamicJsonBuffer jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  JsonArray& probes = root.createNestedArray("probes");
  for(WiFiEventSoftAPModeProbeRequestReceived w : myList){
    JsonObject& probe = probes.createNestedObject();
    probe["address"] = macToString(w.mac);
    probe["rssi"] = w.rssi;
  }
  myList.clear();
  root.printTo(json);
  Serial.print(json);
  Serial.print("hallo");

}

Он должен передавать точку, объект json и слово "hallo"

1 Ответ

0 голосов
/ 07 июня 2019

Это связано с тем, что ESP8266 не может найти точку доступа WiFi с SSID client-ssid и паролем client-password.

Если он не подключен к указанной точке доступа, он напечатает . наэкран.

Вы можете изменить параметры точки доступа на параметры, видимые в диапазоне ESP8266. В качестве альтернативы вы можете изменить SSID и пароль точки доступа на один в коде.

Вы можете использоватьWiFi manager во избежание жесткого ввода имен SSID и пароля.

...