//https://frieder-weiss.de/OSC/index.html
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <WiFiUdp.h>
#include <OSCMessage.h>
// структура настроек
struct Data {
char str[20];
};
Data data;
#include <EEManager.h>
EEManager memory(data);
WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP
const IPAddress outIp(10, 40, 10, 105); // remote IP of your computer
const unsigned int outPort = 9999; // remote port to receive OSC
const unsigned int localPort = 8888; // local port to listen for OSC packets (actually not used for sending)
#include <GyverPortal.h>
GyverPortal ui;
String valText;
void build() {
GP.BUILD_BEGIN(GP_DARK);
GP.TITLE("Title", "t1");
GP.HR();
GP.BREAK();
GP.TEXT("txt", "", data.str);
GP.BREAK();
GP.BUTTON("btn", "Button");
GP.AREA_LOG(5);
GP.BREAK();
GP.BUILD_END();
}
void setup() {
EEPROM.begin(100); // выделить память (больше или равно размеру даты)
memory.begin(0, 'a');
// WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// it is a good practice to make sure your code sets wifi mode how you want it.
// put your setup code here, to run once:
Serial.begin(115200);
//WiFiManager, Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wm;
// reset settings - wipe stored credentials for testing
// these are stored by the esp library
// wm.resetSettings();
// Automatically connect using saved credentials,
// if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
// if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
// then goes into a blocking loop awaiting configuration and will return success result
bool res;
// res = wm.autoConnect(); // auto generated AP name from chipid
// res = wm.autoConnect("AutoConnectAP"); // anonymous ap
res = wm.autoConnect("AutoConnectAP", "password"); // password protected ap
if (!res) {
Serial.println("Failed to connect");
// ESP.restart();
} else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
Serial.println("Starting UDP");
Udp.begin(localPort);
Serial.print("Local port: ");
Serial.println(Udp.localPort());
ui.attachBuild(build);
ui.attach(action);
ui.start();
ui.log.start(30); // передали размер буфера
}
void action() {
if (ui.click()) {
// проверяем компоненты и обновляем переменные
ui.clickStr("txt", data.str);
if (ui.click("btn")) {
Serial.println("Button click");
void trans();
ui.log.println("click");
}
memory.update();
}
}
void loop() {
// put your main code here, to run repeatedly:
ui.tick();
memory.tick();
}
void trans() {
OSCMessage msg("/test");
msg.add("/hello");
Udp.beginPacket(data.str, outPort);
msg.send(Udp);
Udp.endPacket();
msg.empty();
}