Compare commits
No commits in common. "9bf1bb1871aa0ace0bc66fab815046fcae205480" and "90c8d9b1d60a03cb24be5af6a45178db6a858cd0" have entirely different histories.
9bf1bb1871
...
90c8d9b1d6
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,4 +3,3 @@
|
|||||||
.vscode/c_cpp_properties.json
|
.vscode/c_cpp_properties.json
|
||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
.vscode/ipch
|
.vscode/ipch
|
||||||
.vscode/*
|
|
104
src/main.cpp
104
src/main.cpp
@ -15,11 +15,8 @@
|
|||||||
const char *APssid = APSSID;
|
const char *APssid = APSSID;
|
||||||
const char *APpassword = APPSK;
|
const char *APpassword = APPSK;
|
||||||
|
|
||||||
const char *ssid = "QueirozX";
|
const char *ssid = "Apto202";
|
||||||
const char *password = "queirozlindo";
|
const char *password = "gatocafe";
|
||||||
|
|
||||||
bool is_discovering_tuya_ip = true;
|
|
||||||
|
|
||||||
|
|
||||||
ESP8266WebServer web_server(80);
|
ESP8266WebServer web_server(80);
|
||||||
WiFiClient wifiClient;
|
WiFiClient wifiClient;
|
||||||
@ -55,41 +52,6 @@ void handleSetHost()
|
|||||||
HOST_ADDRESS = host;
|
HOST_ADDRESS = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void try_to_connect_to_wifi_network_if_not_connected()
|
|
||||||
{
|
|
||||||
WiFi.begin(ssid, password);
|
|
||||||
while(WiFi.status() != WL_CONNECTED)
|
|
||||||
{
|
|
||||||
Serial.print(".");
|
|
||||||
delay(500);
|
|
||||||
}
|
|
||||||
Serial.println("");
|
|
||||||
}
|
|
||||||
|
|
||||||
String return_first_client_ip()
|
|
||||||
{
|
|
||||||
unsigned char softap_stations_cnt;
|
|
||||||
struct station_info *stat_info;
|
|
||||||
uint32 uintaddress;
|
|
||||||
|
|
||||||
softap_stations_cnt = wifi_softap_get_station_num();
|
|
||||||
stat_info = wifi_softap_get_station_info();
|
|
||||||
String string_ip;
|
|
||||||
|
|
||||||
if (stat_info != NULL) {
|
|
||||||
auto IPaddress = &stat_info->ip;
|
|
||||||
uintaddress = IPaddress->addr;
|
|
||||||
IPAddress myIp(uintaddress);
|
|
||||||
string_ip = myIp.toString();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return String("👎");
|
|
||||||
}
|
|
||||||
return string_ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
pinMode(BUTTON, INPUT_PULLUP);
|
pinMode(BUTTON, INPUT_PULLUP);
|
||||||
@ -99,50 +61,40 @@ void setup()
|
|||||||
Serial.print("Configuring access point...");
|
Serial.print("Configuring access point...");
|
||||||
/* You can remove the password parameter if you want the AP to be open. */
|
/* You can remove the password parameter if you want the AP to be open. */
|
||||||
|
|
||||||
WiFi.mode(WIFI_AP_STA);
|
// WiFi.mode(WIFI_AP_STA);
|
||||||
WiFi.softAP(APssid, APpassword);
|
// WiFi.softAP(APssid, APpassword);
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
Serial.print("Server ip: ");
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
Serial.println(WiFi.softAPIP());
|
{
|
||||||
|
Serial.print('.');
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
// Serial.println(WiFi.localIP());
|
||||||
|
// Serial.println(WiFi.softAPIP());
|
||||||
Serial.print("AP IP address: ");
|
Serial.print("AP IP address: ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
web_server.on("/", handleRoot);
|
web_server.on("/", handleRoot);
|
||||||
web_server.on("/sethost", handleSetHost);
|
web_server.on("/sethost", handleSetHost);
|
||||||
web_server.begin();
|
web_server.begin();
|
||||||
Serial.println("HTTP server started");
|
Serial.println("HTTP server started");
|
||||||
|
|
||||||
|
|
||||||
while (is_discovering_tuya_ip)
|
|
||||||
{
|
|
||||||
Serial.println('Collecting ip');
|
|
||||||
String client_ip = return_first_client_ip();
|
|
||||||
if (client_ip != String("👎"))
|
|
||||||
{
|
|
||||||
is_discovering_tuya_ip = false;
|
|
||||||
HOST_ADDRESS = client_ip;
|
|
||||||
Serial.println("New host address: " + HOST_ADDRESS);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Serial.println("Leaving setup");
|
|
||||||
|
|
||||||
try_to_connect_to_wifi_network_if_not_connected();
|
|
||||||
Serial.println(WiFi.localIP());
|
|
||||||
Serial.println(WiFi.softAPIP());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void handle_button_click()
|
|
||||||
{
|
|
||||||
if(digitalRead(BUTTON) == LOW) {
|
|
||||||
make_toggle_request();
|
|
||||||
delay(500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
handle_button_click();
|
if(digitalRead(BUTTON) == LOW) {
|
||||||
|
//digitalWrite(LED_BUILTIN, HIGH);
|
||||||
|
//int v = digitalRead(BUTTON);
|
||||||
|
//Serial.print("READ: ");
|
||||||
|
//Serial.println(v);
|
||||||
|
// Wait for the button to be released
|
||||||
|
//while(digitalRead(BUTTON) == LOW) {
|
||||||
|
// delay(100);
|
||||||
|
//}
|
||||||
|
//digitalWrite(LED_BUILTIN, LOW);
|
||||||
|
//Serial.println("BOO");
|
||||||
|
make_toggle_request();
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
|
||||||
web_server.handleClient();
|
web_server.handleClient();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user