Программирование nodemCU в Arduino IDE
- Войдите на сайт для отправки комментариев
Ср, 27/12/2017 - 19:14
Есть код:
Программирование nodemCU в Arduino IDE
#define IP_FORWARD 1
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
// Set these to your desired credentials for ESP8266 AP.
const char *ssid = "ESPap";
const char *password = "";
IPAddress apIP(192, 168, 4, 1);
//const char* ssidExt = "dlink";
//const char* passwordExt = "";
// Setup credentials for original WiFi, that we plan to repeat
const char* ssidExt = "Ptech 208";
const char* passwordExt = ""; //TEJ8Pod2DE2pk
const byte DNS_PORT = 53;
int cb;
int noBytes;
WiFiUDP Udp;
byte packetBuffer[512];
WiFiUDP Udp8;
IPAddress ip(192, 168, 0, 13);
IPAddress gateway(10, 254, 20, 1);
IPAddress subnet(255, 255, 254, 0);
void setup()
{
Serial.begin(115200);
Serial.println();
WiFi.mode(WIFI_AP_STA);
//WiFi.mode(WIFI_AP);
Serial.println(" ");
WiFi.begin(ssidExt, passwordExt);
WiFi.config(ip, gateway, subnet);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Подключено к ");
Serial.println(ssidExt);
Serial.print("IP адрес: ");
Serial.println(WiFi.localIP());
Serial.print("dnsIP адрес: ");
Serial.println(WiFi.dnsIP());
Serial.print("gatewayIP адрес: ");
Serial.println(WiFi.gatewayIP());
Serial.print("subnetMask адрес: ");
Serial.println(WiFi.subnetMask());
Serial.println("");
Serial.println("Настройки точки доступа...");
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP адрес: ");
Serial.println(myIP);
Udp.begin(DNS_PORT);
Udp8.begin(DNS_PORT);
}
void loop()
{
noBytes = Udp.parsePacket();
if ( noBytes ) {
Serial.print(millis() / 1000);
Serial.print(":Пакет ");
Serial.print(noBytes);
Serial.print(" получен от ");
Serial.print(Udp.remoteIP());
Serial.print(":");
Serial.println(Udp.remotePort());
Udp.read(packetBuffer, noBytes);
for (int i = 1; i <= noBytes; i++) {
Serial.print(packetBuffer[i - 1], HEX);
if (i % 32 == 0) {
Serial.println();
}
else Serial.print(' ');
}
Serial.println();
IPAddress ip8(192, 168, 1, 1);
Udp8.beginPacket(ip8, 53);
Udp8.write(packetBuffer, noBytes);
Udp8.endPacket();
delay(100);
cb = Udp8.parsePacket();
if (!cb) {
Serial.print("пакета нет, длина= ");
Serial.println(cb);
}
else {
Serial.print("пакет получен, длина=");
Serial.println(cb);
byte packetBuffer8[cb];
Udp8.read(packetBuffer8, cb);
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(packetBuffer8, cb);
Udp.endPacket();
}
} // end if
}
Он должен работать как повторитель. Модуль должен подключаться к точке доступа Wifi, потом создается точка доступа. Подключаюсь с устройства, пошли пакеты, но нет пакетов ответа.
Проблемма с загрузкой картинки: https://ibb.co/fO10sG
В строке номер 100 что за айпишник?