To use the node in your project you should have the borislasky/miconexion 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
node {
static const uint8_t RECEHCK_DURATION_MS = 30;
uint16_t rechecksLeft;
void evaluate(Context ctx) {
auto device = getValue<input_DEV>(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';
// Set your Static IP address
IPAddress local_IP(192, 168, 43, 199);
// Set your Gateway IP address
IPAddress gateway(192, 168, 43, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional
/* 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->config(local_IP, gateway, subnet, primaryDNS, secondaryDNS);
device->begin(_ssid, _password);
auto timeout = getValue<input_TO>(ctx);
rechecksLeft = ceil(timeout * 1000.0 / RECEHCK_DURATION_MS);
setTimeout(ctx, RECEHCK_DURATION_MS);
}
if (isTimedOut(ctx)) {
if (device->status() != WL_CONNECTED) {
rechecksLeft -= 1;
if (rechecksLeft == 0) {
raiseError(ctx); // Connection failed
} else {
setTimeout(ctx, RECEHCK_DURATION_MS);
}
} else {
emitValue<output_DONE>(ctx, true);
typeof_INET inet;
inet.wifi = device;
emitValue<output_INET>(ctx, inet);
}
}
}
}