Hallo Comm,
Ich hab folgendes Problem und zwar möchte ich gerne die Funktion:
if (numberOfNetworks <= 0)
{
numberOfNetworks = WiFi.scanNetworks();
Serial.print(numberOfNetworks);
Serial.println(F(" gefundene Netzwerke"));
}
else if (millis() - lastAusgabe > intervall)
{
numberOfNetworks--;
display.clearDisplay();
display.setCursor(0, 0);
display.print("Network-name: ");
display.setCursor(0, 10);
display.print(WiFi.SSID(numberOfNetworks));
display.setCursor(0, 20);
display.print("Signal strength: ");
display.setCursor(0, 30);
display.print(WiFi.RSSI(numberOfNetworks));
display.display();
Serial.print("Network name: ");
Serial.println(WiFi.SSID(numberOfNetworks));
Serial.print("Signal strength: ");
Serial.println(WiFi.RSSI(numberOfNetworks));
Serial.println("-----------------------");
lastAusgabe = millis();
}
Gerne im Webapge Bereich:
server.on("/oledscan", []() {
server.send(200, "text/plain", "oledscan started");
});
Einfügen, leider funktioniert die Obere Funktion nur im void loop() {}
Bereich.
Das hier hab ich mir zurechtgebastelt, leider ohne funktion.
#if LWIP_FEATURES && !LWIP_IPV6
#define HAVE_NETDUMP 0
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <lwip/napt.h>
#include <lwip/dns.h>
#include <LwipDhcpServer.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define NAPT 1000
#define NAPT_PORT 10
#if HAVE_NETDUMP
#include <NetDump.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDR 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void dump(int netif_idx, const char* data, size_t len, int out, int success) {
(void)success;
Serial.print(out ? F("out ") : F(" in "));
Serial.printf("%d ", netif_idx);
// optional filter example: if (netDump_is_ARP(data))
{
netDump(Serial, data, len);
//netDumpHex(Serial, data, len);
}
}
#endif
// MY FUNCTIONS
bool testwifi() {
Serial.printf("\nTesting connection with '%s'\n", WiFi.SSID().c_str());
int count = 0;
digitalWrite(2,LOW);
while (count < 20) {
if (WiFi.status() == WL_CONNECTED) {
Serial.printf("\nWiFi Connected! \nSTA: %s (dns: %s / %s)\n\n",
WiFi.localIP().toString().c_str(),
WiFi.dnsIP(0).toString().c_str(),
WiFi.dnsIP(1).toString().c_str());
// give DNS servers to AP side
dhcpSoftAP.dhcps_set_dns(0, WiFi.dnsIP(0));
dhcpSoftAP.dhcps_set_dns(1, WiFi.dnsIP(1));
digitalWrite(2,HIGH);
return true;
}
Serial.print(".");
delay(1000);
count++;
}
Serial.printf("\nCan't connect to WiFi, connect to AP '%s' and configure...\n\n", WiFi.softAPSSID());
return false;
}
// SERVER
ESP8266WebServer server(80);
String content;
String networks[40];
void serverconfig() {
server.begin();
int n = WiFi.scanNetworks();
content = "<!DOCTYPE html><html lang='en'><meta name='viewport' content='width=device-width, initial-scale=1.0'>";
content += "<head><title>ESP8266 Configuration Page</title></head>";
content += "<body>";
if (WiFi.status() != WL_CONNECTED) {
content += "<div>currently not connected</div>";
}
else {
content += "<div>connected to: ";
content += WiFi.SSID();
content += " IP: ";
content += WiFi.localIP().toString();
content += "</div>";
}
content += "<div>";
if (n == 0) {
content += "<h1>No wireless networks found</h1>";
}
else {
content += "<h1>Wireless Station Settings</h1>";
content += "<form method='post'>";
for (int i = 0; i < n; ++i) {
networks[i] = WiFi.SSID(i);
content += "<div>";
content += "<input type=\"radio\" id=\"";
content += String(i);
content += "\" ";
content += "name=\"SSIDs\" value=\"";
content += String(i);
content += "\">";
content += "<label for=\"";
content += String(i);
content += "\"";
content += ">";
content += String(i + 1);
content += ": ";
content += WiFi.SSID(i);
content += " (";
content += String(WiFi.RSSI(i));
content += ")";
content += (WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*";
content += "</label>";
content += "</div>";
delay(10);
}
content += "<label>Password:</label><br><input type='password' placeholder='********' name='stapsk' minlength=8 maxlength=63><br><small>Must be at least 8 characters or blank!</small><br><br>";
content += "<button type='submit' formaction='stasettings'>Save Permanently</button><button type='submit' formaction='tempstasettings'>Save Temporarily (Until Reboot)</button>";
content += "</form>";
content += "<h1>Wireless Access Point Settings</h1>";
content += "<form method='post'>";
content += "<label>SSID:</label><br><input name='apssid' placeholder='";
content += WiFi.softAPSSID();
content += "' length=32><br>";
content += "<label>Password:</label><br><input type='password' placeholder='";
content += WiFi.softAPPSK();
content += "' name='appsk' minlength=8 maxlength=63><br><small>Must be at least 8 characters or blank!</small><br><br>";
content += "<button type='submit' formaction='apsettings'>Save Permanently</button><button type='submit' formaction='tempapsettings'>Save Temporarily (Until Reboot)</button>";
content += "<button type='submit' formaction='oledscan'>Scan</button>";
content += "</form>";
}
content += "<h1>Miscellaneous</h1>";
content += "<form method='get' action='reboot'><input type='submit' value='Reboot'></form>";
content += "<div>";
server.on("/", []() {
server.send(200, "text/html", content);
});
server.onNotFound([]() {
server.send(404, "text/plain", "How the heck did you get here?");
});
server.on("/stasettings", []() {
String temp = server.arg("SSIDs");
int number = temp.toInt();
String stassid = networks[number];
String stapsk = server.arg("stapsk");
if (stassid.length() > 0) {
server.send(200, "text/plain", "Settings Recieved");
Serial.printf("\n\nAttempting to connect to '%s' using password '%s' \n", stassid.c_str(), stapsk.c_str());
WiFi.persistent(true);
WiFi.begin(stassid, stapsk);
testwifi();
}
});
server.on("/oledscan", []() {
server.send(200, "text/plain", "oledscan started");
#include "ESP8266WiFi.h"
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDR 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int numberOfNetworks;
unsigned long lastAusgabe;
const unsigned long intervall = 5000;
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDR))
{
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.display();
delay(2000);
display.clearDisplay();
display.display();
display.setTextSize(1);
display.setCursor(0,0);
display.setTextColor(WHITE);
display.print("Test");
display.display();
delay(3000);
display.clearDisplay();
display.display();
if (numberOfNetworks <= 0)
{
numberOfNetworks = WiFi.scanNetworks();
Serial.print(numberOfNetworks);
Serial.println(F(" gefundene Netzwerke"));
}
else if (millis() - lastAusgabe > intervall)
{
numberOfNetworks--;
display.clearDisplay();
display.setCursor(0, 0);
display.print("Network-name: ");
display.setCursor(0, 10);
display.print(WiFi.SSID(numberOfNetworks));
display.setCursor(0, 20);
display.print("Signal strength: ");
display.setCursor(0, 30);
display.print(WiFi.RSSI(numberOfNetworks));
display.display();
Serial.print("Network name: ");
Serial.println(WiFi.SSID(numberOfNetworks));
Serial.print("Signal strength: ");
Serial.println(WiFi.RSSI(numberOfNetworks));
Serial.println("-----------------------");
lastAusgabe = millis();
}
});
server.on("/tempstasettings", []() {
String temp = server.arg("SSIDs");
int number = temp.toInt();
String stassid = networks[number];
String stapsk = server.arg("stapsk");
if (stassid.length() > 0) {
server.send(200, "text/plain", "Settings Recieved");
Serial.printf("\n\nAttempting to connect to '%s' using password '%s' \n", stassid.c_str(), stapsk.c_str());
WiFi.persistent(false);
WiFi.begin(stassid, stapsk);
testwifi();
}
});
server.on("/apsettings", []() {
String apssid = server.arg("apssid");
String appsk = server.arg("appsk");
if (apssid.length() > 0) {
server.send(200, "text/plain", "Settings Recieved");
Serial.printf("\n\nSetting AP Credentials \nSSID: %s \nPassword: %s \n", apssid.c_str(), appsk.c_str());
WiFi.persistent(true);
WiFi.softAP(apssid, appsk);
}
});
server.on("/tempapsettings", []() {
String apssid = server.arg("apssid");
String appsk = server.arg("appsk");
if (apssid.length() > 0) {
server.send(200, "text/plain", "Settings Recieved");
Serial.printf("\n\nSetting Temporary AP Credentials \nSSID: %s \nPassword: %s \n", apssid.c_str(), appsk.c_str());
WiFi.persistent(false);
WiFi.softAP(apssid, appsk);
}
});
server.on("/reboot", []() {
server.send(200, "text/plain", "Rebooting now...");
delay(5000);
ESP.reset();
});
}
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDR 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int numberOfNetworks;
unsigned long lastAusgabe;
const unsigned long intervall = 5000;
void setup() {
Serial.begin(115200);
pinMode(2, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
Serial.begin(115200);
Serial.println("ConsoleLog<>> started.");
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDR))
{
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Starting...");
display.display();
delay(1000);
Serial.printf("\n\nNAPT Range extender\n");
Serial.printf("Heap on start: %d\n", ESP.getFreeHeap());
#if HAVE_NETDUMP
phy_capture = dump;
#endif
WiFi.setPhyMode(WIFI_PHY_MODE_11N); // Set radio type to N
WiFi.mode(WIFI_AP_STA);
WiFi.persistent(false);
WiFi.begin(); // Use stored credentials to connect to network
testwifi();
WiFi.softAPConfig( // Set IP Address, Gateway and Subnet
IPAddress(192, 168, 4, 1),
IPAddress(192, 168, 4, 1),
IPAddress(255, 255, 255, 0));
WiFi.softAP("BlackLeakz-Repeater", "12345678"); // Use stored credentials to create AP
//WiFi.softAPSSID(), WiFi.softAPPSK()
Serial.printf("Heap before: %d\n", ESP.getFreeHeap());
err_t ret = ip_napt_init(NAPT, NAPT_PORT);
Serial.printf("ip_napt_init(%d,%d): ret=%d (OK=%d)\n", NAPT, NAPT_PORT, (int)ret, (int)ERR_OK);
if (ret == ERR_OK) {
ret = ip_napt_enable_no(SOFTAP_IF, 1);
Serial.printf("ip_napt_enable_no(SOFTAP_IF): ret=%d (OK=%d)\n", (int)ret, (int)ERR_OK);
if (ret == ERR_OK) {
Serial.printf("\nWiFi Network '%s' with Passowrd '%s' and IP '%s' is now setup\n", WiFi.softAPSSID(), WiFi.softAPPSK().c_str(), WiFi.softAPIP().toString().c_str());
}
}
Serial.printf("Heap after napt init: %d\n", ESP.getFreeHeap());
if (ret != ERR_OK) {
Serial.printf("NAPT initialization failed\n");
}
serverconfig();
}
#else
void setup() {
Serial.begin(115200);
Serial.printf("\n\nNAPT not supported in this configuration\n");
}
#endif
void loop() {
server.handleClient();
if (WiFi.status() != WL_CONNECTED) {
digitalWrite(2, LOW);
delay(1000);
digitalWrite(2, HIGH);
delay(1000);
}
else {
digitalWrite(2, HIGH);
}
}
Wäre dankbar für eine Berichtigung/Belehrung.
Mfg blackleakz2



