I'm pretty new in the world of ESP and I would like to make a net of ESP8266 that controll some timer all connected to a central esp that generate the wifi. I'd like to make a central site at the 192.168.1.1 where you can click a button and open in the browser the corresponding controll page on another ESP8266 (es 192.168.1.2). I have already created all the site and interfaces but i can't find a way to redirect the with a button click.
Any help to get me on the right way is greatly appreciated.
if you want to stay in the same web page, just have a link to the web servers of the other ESPs.
<a href="http://192.168.1.2>Kitchen</a>
<a href="http://192.168.1.3>BedRoom</a>
<a href="http://192.168.1.4>Cellar</a>
<a href="http://192.168.1.5>Living Room</a>
<a href="http://192.168.1.6>Garage</a>
Sorry it's my first time asking on a formun and i forgot to mention that all the web part is made by ESPUI and i don't now how integrate your answers in my code.
Here I attach my code:
#if defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include <WiFiClient.h>
#include <ESPUI.h>
#include <DNSServer.h>
#include <ESP8266HTTPClient.h>
WiFiClient client;
const byte DNS_PORT = 53;
DNSServer dnsServer;
char* hostname= "ESPUI";
IPAddress apIP(192, 168, 1, 1);
void Setup_gui(void);
void Wifi_Setup(boolean mode);
void ESPUI_Setup();
void Select_page(Control *sender, int type);
void button(Control *sender, int type);
int Select_value;
void Setup_gui(void) {
Wifi_Setup();
ESPUI_Setup();
}
void Wifi_Setup(){
ESPUI.setVerbosity(Verbosity::VerboseJSON);
#if defined(ESP32)
WiFi.setHostname(hostname);
#else
WiFi.hostname(hostname);
#endif
Serial.print("\n\nCreating hotspot");
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP("ESPUI","password");
dnsServer.start(DNS_PORT, "*", apIP);
Serial.println("\n\nWiFi parameters:");
Serial.print("Mode: ");
Serial.println(WiFi.getMode() == WIFI_AP ? "Station" : "Client");
Serial.print("IP address: ");
Serial.println(WiFi.getMode() == WIFI_AP ? WiFi.softAPIP() : WiFi.localIP());
}
int statusLabelId;
void ESPUI_Setup(){
uint16_t tab1 = ESPUI.addControl( ControlType::Tab, "Settings 1", "Settings 1" );
uint16_t select = ESPUI.addControl( ControlType::Select, "Select:", "", ControlColor::Alizarin, tab1, &Select_page );
ESPUI.addControl( ControlType::Option, "None", "0", ControlColor::Alizarin, select );
ESPUI.addControl( ControlType::Option, "Place Holder", "1", ControlColor::Alizarin, select );
ESPUI.addControl( ControlType::Option, "Palece Holder", "2", ControlColor::Alizarin, select );
statusLabelId = ESPUI.label("Status", ControlColor::Turquoise, "pene");
ESPUI.addControl( ControlType::Button, "", "enter", ControlColor::Peterriver, tab1, &button );
ESPUI.begin("ESPUI Control");
}
void Select_page(Control *sender, int type){
Select_value=sender->value.toInt();
Serial.println(Select_value);
}
void button(Control *sender, int type) {
switch (type) {
case B_DOWN:
ESPUI.print(statusLabelId, String(Select_value));
connect_to("http://192.168.1.2");
break;
}
}
void connect_to(String IP){
}
void setup() {
Serial.begin(9600);
Setup_gui();
}
void loop() {
dnsServer.processNextRequest();
delay(500);
}
I would like to open in the browser that see the page 192.168.1.2 when is pressed the button.
I've no clue what ESPUI is... sorry.
I can think of a couple of ideas, but I only have one example I have written: the process is called a Captive Portal:
/*
* Compiled under Arduino 1.6.7 on Linux Mint 17.3 tested on 20160202
* ESP8266 core: http://arduino.esp8266.com/staging/package_esp8266com_index.json
Captive Portal by: M. Ray Burnette 20150831
See Notes tab for original code references and compile requirements
Sketch uses 244,640 bytes (56%) of program storage space. Maximum is 434,160 bytes.
Global variables use 35,408 bytes (43%) of dynamic memory, leaving 46,512 bytes for local variables. Maximum is 81,920 bytes.
*/
#include <ESP8266WiFi.h>
#include "./DNSServer.h" // Patched lib
#include <ESP8266WebServer.h>
const byte DNS_PORT = 53; // Capture DNS requests on port 53
IPAddress apIP(10, 10, 10, 1); // Private network for server
DNSServer dnsServer; // Create the DNS object
ESP8266WebServer webServer(80); // HTTP server
String responseHTML = ""
"<!DOCTYPE html><html><head><title>CaptivePortal</title></head><body>"
"<h1>Hello World!</h1><p>This is a captive portal example. All requests will "
"be redirected here.</p></body></html>";
void setup() {
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP("DNSServer CaptivePortal example");
// if DNSServer is started with "*" for domain name, it will reply with
// provided IP to all DNS request
dnsServer.start(DNS_PORT, "*", apIP);
// replay to all requests with same HTML
webServer.onNotFound([]() {
webServer.send(200, "text/html", responseHTML);
});
webServer.begin();
}
void loop() {
dnsServer.processNextRequest();
webServer.handleClient();
}
Thanks for you hint, I tried to implement but for some reason if used with ESPUI Captive Portal stop working
Here is an article that probably explains things better:
I think Captive Portal is for something very different
It is highly likely that I misread the Op's statement:
'd like to make a central site at the 192.168.1.1 where you can click a button and open in the browser the corresponding controll page on another ESP8266 (es 192.168.1.2)
Captive Portal may be completely over-the-moon ... It's the technology used mainly in hotels and similar to keep you from getting DNS-resolution until after you go through some kind of log-in process.
I guess in reading, maybe all the Op needs is a piece of Javascript to put a button into his browser homepage ... or always bring up a saved web-page (192.168.1.2) as her/his homepage.
I do something desktop related that has one icon that brings up an html file in a private browser context that has drill-down html links.
what I read is that OP wants a "summary" page with links pointing to the other Arduinos, so going to a different IP / web site.
that's why I proposed
<a href="http://192.168.1.2>Kitchen</a>
<a href="http://192.168.1.3>BedRoom</a>
<a href="http://192.168.1.4>Cellar</a>
<a href="http://192.168.1.5>Living Room</a>
<a href="http://192.168.1.6>Garage</a>
since OP uses ESPUI, what is needed is to create a button with their UI and attach a callback the routes somewhere else.
I glimpsed at the GitHub and they mention ESPAsyncWebserver as the backend which knows how to redirect as part of an answer . So this should be doable, just needs a bit of exploration with the library
+1 Agree
I'm trying to implement ESPAsyncWebserver but for some reason it doesn't realy work with ESPUI. Someone can tell me if I need to use the ESPUI ESPAsyncWebserver or I need to implement it my self?
are you using advanced drawings from ESPUI for your HTML interface?
I had a quick look and the ESPUI API does not expose the request, you just have a callback being called and no option to inject anything in a response.
Actually i'm only using a multiple option menù, a button and a label where write the status of the timers
it depends how much work you want to put into this, might be worth rewriting it without ESPUI, just plain HTLM and AJAX / equivalent if you want to refresh the display
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.