esp-ap

maks971014/esp8266-ap/esp-ap

No description
esp-ap
@/esp-ap
SSIDstring
Name of the Wi-Fi network
PWDstring
Wi-Fi network password
DEVxod-dev/esp8266-mcu/esp8266-mcu-device
An ESP8266-based MCU
CONNpulse
Establish the connection
channelnumber
канал связи
esp-ap
SSID
PWD
DEV
CONN
channel
INET
DONE
DONEpulse
Pulses on a successful connection
INETxod-dev/esp8266-mcu/esp8266-mcu-inet
An internet connection
To use the node in your project you should have the maks971014/esp8266-ap library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD error_raise enable

// clang-format off
{{#global}}
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
WiFiUDP udp;
unsigned int localPort = 2000;
IPAddress ServerIP(192, 168, 4, 1);//задали IP адрес для AP
IPAddress ClientIP(192, 168, 4, 2);//задали IP адрес для STA
{{/global}}
// clang-format on



struct State {
    uint16_t rechecksLeft;
};

// clang-format off
{{ GENERATED_CODE }}
// clang-format on

void evaluate(Context ctx) {
    auto device = getValue<input_DEV>(ctx);
    auto state = getState(ctx);

    if (isInputDirty<input_CONN>(ctx)) {
        auto ssid = getValue<input_SSID>(ctx);
        auto ssidLength = length(ssid);
        char _ssid[ssidLength + 1];
        dump(ssid, _ssid);
        _ssid[ssidLength] = '\0';

        auto password = getValue<input_PWD>(ctx);
        auto passwordLength = length(password);
        char _password[passwordLength + 1];
        dump(password, _password);
        _password[passwordLength] = '\0';
        auto channel = getValue<input_channel>(ctx);
        Serial.println("Start Wi-fi");
        /* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
           would try to act as both a client and an access-point and could cause
           network-issues with your other WiFi-devices on your WiFi-network. */
        WiFi.mode(WIFI_AP);
        WiFi.begin(_ssid, _password);
        Serial.println("Start UDP");
        udp.begin(localPort);
        delay(10000);
        } else {
            emitValue<output_DONE>(ctx, true);
            // DEV and INET are both actually just a pointer to WiFi from ESP8266WiFi.h
            emitValue<output_INET>(ctx, (ValueType<output_INET>::T)device);
        }
    }