esp-sta

maks971014/esp8266-ap/esp-sta

No description
esp-sta
@/esp-sta
DEVxod-dev/esp8266-mcu/esp8266-mcu-device
An ESP8266-based MCU
SSIDstring
Name of the Wi-Fi network
PWDstring
Wi-Fi network password
TOnumber
Connection timeout (in seconds)
CONNpulse
Establish the connection
esp-sta
DEV
SSID
PWD
TO
CONN
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>

unsigned int localPort = 2000; // local port to listen for UDP packets
IPAddress ServerIP(192, 168, 4, 1);
IPAddress ClientIP(192, 168, 4, 2);
WiFiUDP udp;

{{/global}}
// clang-format on

//const uint8_t RECEHCK_DURATION_MS = 1000;

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);
    Serial.println("Start wi-fi");
    if (isInputDirty<input_CONN>(ctx)) {
        //udp.begin(localPort);
        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';

        /* 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. 
        device->mode(WIFI_STA);
        device->begin(_ssid, _password);*/
        WiFi.mode(WIFI_STA);
        WiFi.begin(_ssid, _password);
    }
    while(WiFi.status() != WL_CONNECTED){Serial.println(".");delay(500);}
    emitValue<output_DONE>(ctx, true);
    
    Serial.print("SSID ");
    Serial.print("PASSWORD ");}
    /*
        auto timeout = getValue<input_TO>(ctx);
        state->rechecksLeft = ceil(timeout * 1000.0 / RECEHCK_DURATION_MS);
        setTimeout(ctx, RECEHCK_DURATION_MS);
    }

    if (isTimedOut(ctx)) {
        if (device->status() != WL_CONNECTED) {
            state->rechecksLeft -= 1;
            Serial.println(".");

            if (state->rechecksLeft == 0) {
                raiseError(ctx); // Connection failed
            } else {
                setTimeout(ctx, RECEHCK_DURATION_MS);
            }
        } 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); 

            Serial.print("SSID ");
            Serial.print("PASSWORD ");

        }
    }
}
*/