938 lines
33 KiB
C++
938 lines
33 KiB
C++
#include <ESP8266WiFi.h>
|
|
//#include <Wire.h>
|
|
//#include "/home/souti/Arduino/EEPROM_TEST/eeprom.h"
|
|
|
|
//////////////////////
|
|
// WiFi Definitions //
|
|
//////////////////////
|
|
const char WiFiAPPSK[] = "sparkfun";
|
|
|
|
// Avant la connexion au réseau local
|
|
// Se connecter au réseau ESP8266 Thing **** Qui apparait dans
|
|
// la liste des réseau WIFI
|
|
// sur l'adresse IP http://192.168.4.1/
|
|
|
|
#define DELAI_LECTURE 120
|
|
|
|
#define PAGE_MENU 0
|
|
#define PAGE_ADMIN 1
|
|
#define PAGE_STATUS 2
|
|
#define PAGE_INFOS 3
|
|
#define PAGE_GRAPH 4
|
|
|
|
String domoticz = "192.168.1.3";
|
|
String port = "81";
|
|
|
|
String radiateur = ""; //"217";
|
|
String temp = ""; //"281";
|
|
String cons = ""; //"212";
|
|
|
|
String ssid = "Livebox-37cc";
|
|
String pass = "8A6060920A8A86896F770F2C47";
|
|
String macID = "";
|
|
|
|
String jsPath = "/ESP8266/js/";
|
|
String jqueryName = "jquery.js";
|
|
String chartName = "chart.js";
|
|
String AP_NameString = "";
|
|
int nbData = 0;
|
|
String data = "";
|
|
String labels = "";
|
|
int bcl = 0;
|
|
int val0;
|
|
int val2;
|
|
String separator = ",";
|
|
String nom = "";
|
|
int refresh = 2;
|
|
|
|
// Relay
|
|
const int relay_pin = 13;
|
|
// End stop filament
|
|
const int buttonPin = 12; // the number of the pushbutton pin
|
|
int end_filament = 0;
|
|
|
|
|
|
// Ordre dans Domoticz
|
|
// Radiateur Temp Consigne
|
|
//Manon 217 281 212
|
|
//Théo 219 335 211
|
|
//Chambre 218 254 213
|
|
//Bureau 163 260 214
|
|
|
|
WiFiClient client;
|
|
|
|
WiFiServer server(80);
|
|
|
|
void setup()
|
|
{
|
|
initHardware();
|
|
setupWiFi();
|
|
server.begin();
|
|
// for (int i = 0; i < 256; i++) {
|
|
// data[i] = "";
|
|
// }
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
|
|
// read the state of the end button value:
|
|
end_filament = digitalRead(buttonPin);
|
|
|
|
if ((bcl % (refresh * 60)) == 0) { //DELAI_LECTURE == 0) {
|
|
infos();
|
|
nbData += 1;
|
|
nbData = nbData % 256;
|
|
}
|
|
|
|
// Check if a client has connected
|
|
client = server.available();
|
|
if (!client) {
|
|
// infos();
|
|
delay(1000);
|
|
bcl++;
|
|
return;
|
|
}
|
|
|
|
// Read the first line of the request
|
|
String req = client.readStringUntil('\r');
|
|
Serial.println(req);
|
|
// client.flush();
|
|
|
|
// Match the request
|
|
int val = -1; // We'll use 'val' to keep track of both the
|
|
// request type (read/set) and value if set.
|
|
if (req.indexOf("/admin") != -1) {
|
|
val = -3;
|
|
//int end = readPage(START_ADDRESS);
|
|
//pageAdmin();
|
|
pageMenu(PAGE_ADMIN);
|
|
|
|
} else if (req.indexOf("/graph") != -1) {
|
|
pageMenu(PAGE_GRAPH);
|
|
|
|
} else if (req.indexOf("/reset") != -1) {
|
|
client.println("Reset done. SSID, PASS, Domoticz, port & id cleaned.");
|
|
delay(100);
|
|
// } else if (req.indexOf("/ident") != -1) {
|
|
//
|
|
// ident(req);
|
|
|
|
} else if (req.indexOf("/status") != -1) {
|
|
|
|
//printWifiStatus();
|
|
pageMenu(PAGE_STATUS);
|
|
|
|
} else if (req.indexOf("/infos") != -1) {
|
|
pageMenu(PAGE_INFOS);
|
|
} else if (req.indexOf("/relay_01") != -1) {
|
|
client.print("relay_01=");
|
|
client.print(val0); //digitalRead(0));
|
|
delay(100);
|
|
} else if (req.indexOf("/relay_02") != -1) {
|
|
client.print("relay_02=");
|
|
client.print(val2); //digitalRead(2));
|
|
delay(100);
|
|
} else if (req.indexOf("/action") != -1) {
|
|
|
|
// Affectation des variables aux sorties correspondantes
|
|
if (req.indexOf("relay_01=false") != -1)
|
|
{
|
|
val0 = LOW;
|
|
digitalWrite(0, val0);
|
|
}
|
|
if (req.indexOf("relay_01=true") != -1)
|
|
{
|
|
val0 = HIGH;
|
|
digitalWrite(0, val0);
|
|
}
|
|
if (req.indexOf("relay_02=false") != -1)
|
|
{
|
|
val2 = LOW;
|
|
digitalWrite(2, val2);
|
|
}
|
|
if (req.indexOf("relay_02=true") != -1)
|
|
{
|
|
val2 = HIGH;
|
|
digitalWrite(2, val2);
|
|
}
|
|
|
|
Serial.println("Val0=" + String(val0) + " Val2=" + String(val2));
|
|
|
|
pageMenu(PAGE_MENU);
|
|
} else if (req.indexOf("/menu") != -1) {
|
|
//pageMenu();
|
|
pageMenu(PAGE_MENU);
|
|
} else {
|
|
pageMenu(PAGE_MENU);
|
|
}
|
|
|
|
//client.stop();
|
|
|
|
// The client will actually be disconnected
|
|
// when the function returns and 'client' object is detroyed
|
|
}
|
|
|
|
|
|
void setupWiFi()
|
|
{
|
|
WiFi.mode(WIFI_AP);
|
|
|
|
// Do a little work to get a unique-ish name. Append the
|
|
// last two bytes of the MAC (HEX'd) to "Thing-":
|
|
uint8_t mac[WL_MAC_ADDR_LENGTH];
|
|
WiFi.softAPmacAddress(mac);
|
|
macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) + String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
|
|
macID.toUpperCase();
|
|
AP_NameString = "ESP8266 Thing " + macID;
|
|
|
|
char AP_NameChar[AP_NameString.length() + 1];
|
|
memset(AP_NameChar, 0, AP_NameString.length() + 1);
|
|
|
|
for (int i = 0; i < AP_NameString.length(); i++)
|
|
AP_NameChar[i] = AP_NameString.charAt(i);
|
|
|
|
WiFi.softAP(AP_NameChar, WiFiAPPSK);
|
|
|
|
Serial.println("macID=" + macID);
|
|
Serial.println("Info lues " + ssid + " " + pass + " " + domoticz + " " + port + " " + radiateur);
|
|
|
|
if (ssid.length() != 0 && pass.length() != 0) {
|
|
char ssidc[ssid.length() + 1];
|
|
ssid.toCharArray(ssidc, ssid.length() + 1);
|
|
//Password
|
|
char passc[pass.length() + 1];
|
|
pass.toCharArray(passc, pass.length() + 1);
|
|
boolean ret = connectToWifi(ssidc, passc);
|
|
Serial.println(ret);
|
|
if (ret) {
|
|
Serial.print("Connexion au reseau ");
|
|
Serial.println(WiFi.localIP());
|
|
} else {
|
|
Serial.print("Pas de connexion au reseau ");
|
|
Serial.println(ssid);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
boolean connectToWifi(char* ssidc, char* passc) {
|
|
|
|
//WL_NO_SHIELD = 255,
|
|
//WL_IDLE_STATUS = 0,
|
|
//WL_NO_SSID_AVAIL = 1
|
|
//WL_SCAN_COMPLETED = 2
|
|
//WL_CONNECTED = 3
|
|
//WL_CONNECT_FAILED = 4
|
|
//WL_CONNECTION_LOST = 5
|
|
//WL_DISCONNECTED = 6
|
|
|
|
boolean ret = false;
|
|
WiFi.begin(ssidc, passc);
|
|
|
|
Serial.println("Connexion en-cours");
|
|
|
|
int time = 0;
|
|
int status = 0;
|
|
while (/*WiFi.status() != WL_CONNECTED &&*/ time < 30) {
|
|
delay(500);
|
|
//Serial.print(".");
|
|
status = WiFi.status();
|
|
Serial.print(status);
|
|
if (status == WL_CONNECTED) {
|
|
break;
|
|
}
|
|
time++;
|
|
}
|
|
|
|
if (status == WL_CONNECTED) {
|
|
ret = true;
|
|
Serial.println("WiFi connected");
|
|
Serial.println("IP address: ");
|
|
Serial.println(WiFi.localIP());
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void initHardware()
|
|
{
|
|
// Serial.begin(115200);
|
|
Serial.begin(9600);
|
|
|
|
pinMode(relay_pin, OUTPUT);
|
|
digitalWrite(relay_pin, HIGH);
|
|
// initialize the pushbutton pin as an input:
|
|
pinMode(buttonPin, INPUT);
|
|
|
|
}
|
|
String getValueFrom(String request, int deb, int fin) {
|
|
|
|
int bufLength = ((fin) - (deb + 5)); //the 5 is for the "name=" string
|
|
|
|
String tmp = request.substring((deb + 5), (fin - 1));
|
|
|
|
return tmp;
|
|
}
|
|
|
|
char* convertToChar(String s, char* buf) {
|
|
char c[s.length() + 1];
|
|
s.toCharArray(c, s.length() + 1);
|
|
return c;
|
|
}
|
|
|
|
|
|
void infos()
|
|
{
|
|
int nb = 0;
|
|
|
|
WiFiClient client2;
|
|
// Domoticz format /json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT
|
|
|
|
// Type
|
|
// 0 = Integer, e.g. -1, 1, 0, 2, 10
|
|
//1 = Float, e.g. -1.1, 1.2, 3.1
|
|
//2 = String
|
|
//3 = Date in format DD/MM/YYYY
|
|
//4 = Time in 24 hr format HH:MM
|
|
//5 = DateTime (but the format is not checked)
|
|
// SAve variable "json.htm?type=command¶m=saveuservariable&vname=" + macID + "uservariablename&vtype=2&vvalue=uservariablevalue"
|
|
|
|
// GEt Variables
|
|
// http://192.168.0.10:8080/json.htm?type=command¶m=getuservariables&idx=4
|
|
|
|
|
|
// Domo
|
|
char domoc[domoticz.length() + 1];
|
|
domoticz.toCharArray(domoc, domoticz.length() + 1);
|
|
|
|
// Port
|
|
char portc[port.length() + 1];
|
|
port.toCharArray(portc, port.length() + 1);
|
|
int iport = atoi(portc);
|
|
|
|
Serial.print(domoc);
|
|
Serial.print(" ");
|
|
Serial.println(iport);
|
|
|
|
Serial.print(" radiateur=");
|
|
Serial.print(radiateur);
|
|
Serial.print(" temperature=");
|
|
Serial.print(temp);
|
|
Serial.print(" consigne=");
|
|
Serial.print(cons);
|
|
Serial.println("");
|
|
|
|
// -------------------
|
|
// LECTURE PARAM
|
|
// -------------------
|
|
if (radiateur == "") {
|
|
Serial.println("Lecture parametre dans domoticz");
|
|
if (client2.connect(domoc, iport)) {
|
|
Serial.println("Connected to domoticz");
|
|
client2.print("GET /json.htm?type=command¶m=getuservariables");
|
|
client2.println(" HTTP/1.1");
|
|
client2.print("Host: ");
|
|
client2.print(domoc);
|
|
client2.print(":");
|
|
client2.println(iport);
|
|
client2.println("User-Agent: Arduino-ethernet");
|
|
client2.println("Connection: close");
|
|
client2.println();
|
|
|
|
// Read the first line of the request
|
|
while (1) {
|
|
String req = client2.readStringUntil('\n');
|
|
|
|
if (req.indexOf(macID) != -1) {
|
|
Serial.println(req);
|
|
req = client2.readStringUntil('\n');
|
|
req = client2.readStringUntil('\n');
|
|
String val = req.substring(req.indexOf(":") + 2, req.length() - 1);
|
|
Serial.println(val);
|
|
val.replace("\"", "");
|
|
radiateur = getIndexOfString(val, separator, 0);
|
|
temp = getIndexOfString(val, separator, 1);
|
|
cons = getIndexOfString(val, separator, 2);
|
|
refresh = getIndexOfString(val, separator, 3).toInt();
|
|
nom = getIndexOfString(val, separator, 4);
|
|
|
|
for (int cpt = 0; cpt < 5; cpt++ ) {
|
|
Serial.print(getIndexOfString(val, separator, cpt));
|
|
}
|
|
Serial.println("");
|
|
// // radiateur =
|
|
//
|
|
// radiateur = val.substring(0, val.indexOf(","));
|
|
// val = val.substring(val.indexOf(",") + 1);
|
|
// temp = val.substring(0, val.indexOf(","));
|
|
// val = val.substring(val.indexOf(",") + 1);
|
|
// cons = val.substring(0, val.indexOf(","));
|
|
|
|
Serial.println("val1=" + radiateur);
|
|
Serial.println("val2=" + temp);
|
|
Serial.println("val3=" + cons);
|
|
|
|
break;
|
|
}
|
|
if (req == "" || nb > 50) {
|
|
break;
|
|
}
|
|
nb++;
|
|
}
|
|
|
|
client2.stop();
|
|
delay(100);
|
|
}
|
|
}
|
|
if (radiateur != "") {
|
|
if (client2.connect(domoc, iport)) {
|
|
Serial.println("Radiateur");
|
|
client2.print("GET /json.htm?type=devices&rid=");
|
|
client2.print(radiateur);
|
|
client2.println(" HTTP/1.1");
|
|
client2.print("Host: ");
|
|
client2.print(domoc);
|
|
client2.print(":");
|
|
client2.println(iport);
|
|
client2.println("User-Agent: Arduino-ethernet");
|
|
client2.println("Connection: close");
|
|
client2.println();
|
|
|
|
// Read the first line of the request
|
|
while (1) {
|
|
String req = client2.readStringUntil('\n');
|
|
|
|
if (req.indexOf("\"Status\"") != -1) {
|
|
Serial.println(req.substring(req.indexOf(":") + 2));
|
|
break;
|
|
}
|
|
if (req == "" || nb > 50) {
|
|
break;
|
|
}
|
|
Serial.print(".");
|
|
nb++;
|
|
}
|
|
|
|
client2.stop();
|
|
delay(100);
|
|
}
|
|
if (temp != "") {
|
|
if (client2.connect(domoc, iport)) {
|
|
client2.print("GET /json.htm?type=devices&rid=");
|
|
client2.print(temp);
|
|
client2.println(" HTTP/1.1");
|
|
client2.print("Host: ");
|
|
client2.print(domoc);
|
|
client2.print(":");
|
|
client2.println(iport);
|
|
client2.println("User-Agent: Arduino-ethernet");
|
|
client2.println("Connection: close");
|
|
client2.println();
|
|
|
|
// Read the first line of the request
|
|
while (1) {
|
|
String req = client2.readStringUntil('\n');
|
|
|
|
if (req.indexOf("\"Temp\"") != -1) {
|
|
String tmp = req.substring(req.indexOf(":") + 2);
|
|
tmp = tmp.substring(0, tmp.indexOf(".") + 2);
|
|
Serial.println(tmp);
|
|
if (data == "") {
|
|
data += tmp;
|
|
labels = "\"0\"";
|
|
} else {
|
|
data += "," + tmp;
|
|
if (nbData % 10 == 0) {
|
|
labels = labels + "," + "\"" + nbData + "\"";
|
|
} else {
|
|
labels = labels + "," + "\"" + "\"";
|
|
}
|
|
|
|
}
|
|
if (data.length() > 500) {
|
|
data = data.substring(data.indexOf(",") + 1);
|
|
labels = labels.substring(labels.indexOf(",") + 1);
|
|
}
|
|
Serial.println(data);
|
|
Serial.println(labels);
|
|
break;
|
|
}
|
|
if (req == "" || nb > 50) {
|
|
break;
|
|
}
|
|
Serial.print("_");
|
|
|
|
nb++;
|
|
}
|
|
client2.stop();
|
|
delay(100);
|
|
}
|
|
}
|
|
if (cons != "") {
|
|
if (client2.connect(domoc, iport)) {
|
|
client2.print("GET /json.htm?type=devices&rid=");
|
|
client2.print(cons);
|
|
client2.println(" HTTP/1.1");
|
|
client2.print("Host: ");
|
|
client2.print(domoc);
|
|
client2.print(":");
|
|
client2.println(iport);
|
|
client2.println("User-Agent: Arduino-ethernet");
|
|
client2.println("Connection: close");
|
|
client2.println();
|
|
|
|
// Read the first line of the request
|
|
while (1) {
|
|
String req = client2.readStringUntil('\n');
|
|
|
|
if (req.indexOf("\"SetPoint\"") != -1) {
|
|
String value = req.substring(req.indexOf(":") + 2);
|
|
//value = .substring(req.indexOf(":") + 1);
|
|
value.trim();
|
|
|
|
Serial.println(value);
|
|
break;
|
|
}
|
|
if (req == "" || nb > 50) {
|
|
break;
|
|
}
|
|
nb++;
|
|
}
|
|
|
|
client2.stop();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void printWifiStatus() {
|
|
// print the SSID of the network you're attached to:
|
|
Serial.print("SSID: ");
|
|
Serial.println(WiFi.SSID());
|
|
|
|
// print your WiFi shield's IP address:
|
|
IPAddress ip = WiFi.localIP();
|
|
Serial.print("IP Address: ");
|
|
Serial.println(ip);
|
|
|
|
// print the received signal strength:
|
|
long rssi = WiFi.RSSI();
|
|
Serial.print("signal strength (RSSI):");
|
|
Serial.print(rssi);
|
|
Serial.println(" dBm");
|
|
|
|
// PAge
|
|
client.println("<p>Connected to ");
|
|
client.println(WiFi.SSID());
|
|
client.println("</p><p>Ip: ");
|
|
client.println(ip);
|
|
client.println("</p><p>Force du signal:");
|
|
client.println(rssi);
|
|
client.println(" dBm</p>");
|
|
client.println("<p>Domoticz:");
|
|
client.println(domoticz);
|
|
client.println(":");
|
|
client.println(port);
|
|
client.println("</p>");
|
|
//
|
|
// client.println("<div class='c100 p25 dark orange'>");
|
|
// client.println(" <span>25%</span>");
|
|
// client.println(" <div class='slice'>");
|
|
// client.println(" <div class='bar'></div>");
|
|
// client.println(" <div class='fill'></div>");
|
|
// client.println(" </div>");
|
|
// client.println("</div>");
|
|
client.println("<button class='boutonTemp' onclick='click()'>" + temp + "</button>");
|
|
client.println("<button class='boutonCons' onclick='click()'>" + cons + "</button>");
|
|
}
|
|
|
|
////////////////////////////////////////////
|
|
////// PAGE MENU
|
|
////////////////////////////////////////////
|
|
void pageMenu(int page) {
|
|
client.println("<html>");
|
|
client.println("<head>");
|
|
client.println("<link rel=\"shortcut icon\" href=\"http://" + domoticz + ":" + port + "/favicon.ico\">");
|
|
if (page == PAGE_GRAPH) {
|
|
client.println("<meta http-equiv=\"refresh\" content=\"60\" >");
|
|
}
|
|
if (page == PAGE_MENU) {
|
|
// // Look des champs de saisis
|
|
// client.println("<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"http://" + domoticz + "/ESP8266/css/styles.css\">");
|
|
// // Look Bouton toggle
|
|
// client.println("<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"http://" + domoticz + "/ESP8266/css/toggles-soft.css\">");
|
|
}
|
|
|
|
menuStyle(page);
|
|
client.println("</head>");
|
|
|
|
menuBody(page);
|
|
client.println("</html>\n\r");
|
|
|
|
}
|
|
|
|
void menuBody(int page) {
|
|
client.println("<body>");
|
|
client.println("<header role='banner'>");
|
|
client.println("<div class='wrapper'>");
|
|
client.print("<h1> ");
|
|
client.print(nom + " " + macID);
|
|
client.println("</h1>");
|
|
client.println("<nav id='nav' role='navigation'>");
|
|
client.println("<div class='show_menu_btn' data-target='#nav ul' data-shown-text='Hide menu' data-hidden-text='Show menu' >Show menu</div>");
|
|
client.println("<ul>");
|
|
client.println("<li><a href='/menu'>Menu</a></li>");
|
|
client.println("<li><a href='/admin'>Admin</a></li>");
|
|
//client.println("<li><a href='/infos'>Infos</a></li>");
|
|
client.println("<li><a href='/status'>Status</a></li>");
|
|
//client.println("<li><a href='/reset'>Reset</a></li>");
|
|
client.println("<li><a href='/graph'>Graph</a></li>");
|
|
//client.println("<li><a href='/aide'>Aide</a></li>");
|
|
client.println("</ul>");
|
|
client.println("</nav>");
|
|
client.println("</div>");
|
|
client.println("</header>");
|
|
|
|
client.println("<main role='main'>");
|
|
client.println("<div class='wrapper'>");
|
|
if (page == PAGE_MENU) {
|
|
client.print("<form><div><input type=\"checkbox\" id=\"relay_01\" onclick=\"handleClick(this);\" ");
|
|
if (val0 == 0) {
|
|
client.print("unchecked");
|
|
} else {
|
|
client.print("checked");
|
|
}
|
|
client.println("><label for=\"relay_01\" onclick=\"relay_01();\">Relai 1</label></div>");
|
|
client.println("<div><input type=\"checkbox\" id=\"relay_02\" onclick=\"handleClick(this);\" ");
|
|
if (val2 == 0) {
|
|
client.print("unchecked");
|
|
} else {
|
|
client.print("checked");
|
|
}
|
|
client.println("><label for=\"relay_02\" onclick=\"relay_02();\">Relai 2</label></div></form>");
|
|
|
|
} else if (page == PAGE_ADMIN) {
|
|
client.println( "<form action='/ident' method='get'>");
|
|
client.println( "<script type='text/javascript'>\nfunction showValue(newValue)\n{\ndocument.getElementById('text').innerHTML=newValue;\n}\n</script>");
|
|
client.println( "<div>");
|
|
client.println( "<label for='name'>SSID:</label>");
|
|
client.println( "<input type='text' id='name' name='name' value='" + ssid + "'/>");
|
|
client.println( "</div>");
|
|
client.println( "<div>");
|
|
client.println( "<label for='pass'>Password:</label>");
|
|
client.println( "<input type='password' id='pass' name='pass' />");
|
|
client.println( "</div>");
|
|
client.println( "<div>");
|
|
client.println( "<label for='domo'>Domoticz:</label>");
|
|
client.println( "<input type='text' id='domo' name='domo' value='" + domoticz + "'/>"); // />");
|
|
client.println( "</div>");
|
|
client.println( "<div>");
|
|
client.println( "<label for='port'>Port:</label>");
|
|
client.println( "<input type='text' id='port' name='port' value='" + port + "'/>");
|
|
client.println( "</div>");
|
|
client.println( "<div>");
|
|
client.println( "<label for='radi'>Id Radiateur:</label>");
|
|
client.println( "<input type='radi' id='radi' name='radi' value='" + radiateur + "'/>");
|
|
client.println( "</div>");
|
|
client.println( "<div>");
|
|
client.println( "<label for='temp'>Id Thermometre:</label>");
|
|
client.println( "<input type='temp' id='temp' name='temp' value='" + temp + "'/>");
|
|
client.println( "</div>");
|
|
client.println( "<div>");
|
|
client.println( "<label for='cons'>Id Consigne:</label>");
|
|
client.println( "<input type='cons' id='cons' name='cons' value='" + cons + "'/>");
|
|
client.println( "</div>");
|
|
|
|
client.println( "<div class='button'>");
|
|
client.println( "<button name=H type='submit'>Ok</button>");
|
|
client.println( "</div>");
|
|
client.println( "</form>");
|
|
} else if (page == PAGE_STATUS) {
|
|
client.println("<article>");
|
|
printWifiStatus();
|
|
client.println("</article>");
|
|
} else if (page == PAGE_GRAPH) {
|
|
graph();
|
|
} else if (page == PAGE_INFOS) {
|
|
infos();
|
|
}
|
|
client.println(" </div>");
|
|
client.println("</main>");
|
|
|
|
client.println("<script>");
|
|
client.println("var show_menu=document.querySelector('.show_menu_btn'),viewport_width=document.documentElement.clientWidth,menu=document.querySelector('#nav ul');600>viewport_width&&(menu.style.display='none'),window.addEventListener('resize',function(){var e=document.documentElement.clientWidth;menu.style.display=e>599?'block':'none'}),show_menu.addEventListener('click',function(){var e=document.querySelector(show_menu.getAttribute('data-target'));'none'==e.style.display?(e.style.display='block',show_menu.innerHTML=show_menu.getAttribute('data-shown-text')):(e.style.display='none',show_menu.innerHTML=show_menu.getAttribute('data-hidden-text'))});");
|
|
//menuJS();
|
|
// Fonction pour les voutons
|
|
//client.println("function click(){$(function() {$( '#dialog' ).dialog({width : 250, height: 180, modal : true }); }); }");
|
|
client.println("</script>");
|
|
|
|
|
|
if (page == PAGE_GRAPH) {
|
|
// client.println("<script src=\"http://" + domoticz + "/" + jsPath + "/" + chartName + "\"></script>");
|
|
client.println("<script src=\"https://www.chartjs.org/dist/2.9.3/Chart.min.js\"></script>");
|
|
}
|
|
else if (page == PAGE_MENU) {
|
|
client.println("<script>");
|
|
client.println("function relay_02() {document.getElementById(\"relay_02\").click();}");
|
|
client.println("function relay_01() {document.getElementById(\"relay_01\").click();}");
|
|
client.println("function handleClick(cb) {post_to_url(\"/action\", { submit: \"submit\" });}");
|
|
client.println("function post_to_url(path, params, method) {");
|
|
client.println("method = \"get\"; var form = document.createElement(\"form\");");
|
|
client.println("var x = document.getElementById(\"relay_01\");");
|
|
client.println("var x2 = document.getElementById(\"relay_02\");");
|
|
client.println("form._submit_function_ = form.submit;");
|
|
client.println("form.setAttribute(\"method\", method);");
|
|
client.println("form.setAttribute(\"action\", path);");
|
|
|
|
client.println("var hiddenField = document.createElement(\"input\");");
|
|
client.println("hiddenField.setAttribute(\"type\", \"hidden\");");
|
|
client.println("hiddenField.setAttribute(\"name\", x.id);");
|
|
client.println("hiddenField.setAttribute(\"value\", x.checked);");
|
|
client.println("form.appendChild(hiddenField);");
|
|
client.println("document.body.appendChild(form);");
|
|
|
|
client.println("var hiddenField2 = document.createElement(\"input\");");
|
|
client.println("hiddenField2.setAttribute(\"type\", \"hidden\");");
|
|
client.println("hiddenField2.setAttribute(\"name\", x2.id);");
|
|
client.println("hiddenField2.setAttribute(\"value\", x2.checked);");
|
|
client.println("form.appendChild(hiddenField2);");
|
|
client.println("document.body.appendChild(form);form._submit_function_(); }</script>");
|
|
|
|
}
|
|
|
|
client.println("</body>");
|
|
|
|
}
|
|
void menuJS() {
|
|
//
|
|
// client.println( "var show_menu=document.querySelector('.show_menu_btn'),viewport_width=document.documentElement.clientWidth,menu=document.querySelector('#nav ul');");
|
|
// client.println( "600>viewport_width&&(menu.style.display='none'),window.addEventListener('resize',function(){var e=document.documentElement.clientWidth;");
|
|
// client.println( "menu.style.display=e>599?'block':'none'}),show_menu.addEventListener('click',function(){var e=document.querySelector(show_menu.getAttribute('data-target'));");
|
|
// client.println( "'none'==e.style.display?(e.style.display='block',show_menu.innerHTML=show_menu.getAttribute('data-shown-text')):");
|
|
// client.println( "(e.style.display='none',show_menu.innerHTML=show_menu.getAttribute('data-hidden-text'))}");
|
|
//
|
|
}
|
|
void menuStyle(int page) {
|
|
client.println("<style>");
|
|
client.println( "a,abbr,acronym,address,applet,article,aside,audio,b,big,blockquote,body,canvas,caption,center,cite,code,dd,del,details,dfn,div,dl,dt,em,embed,fieldset,figcaption,");
|
|
client.println( "figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,html,i,iframe,img,ins,kbd,label,legend,li,mark,menu,nav,object,ol,output,p,pre,q,ruby,s,samp,section,small,span,");
|
|
client.println( "strike,strong,sub,summary,sup,table,tbody,td,tfoot,th,thead,time,tr,tt,u,ul,var,video{margin:0;padding:0;border:0;font:inherit;vertical-align:baseline}");
|
|
client.println( "article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}nav ul{list-style:none}blockquote,q{quotes:none}blockquote:");
|
|
client.println( "after,blockquote:before,q:after,q:before{content:'';");
|
|
client.println( "content:none}table{border-collapse:collapse;border-spacing:0}h1{font-size:1.5em;font-weight:700;padding:.5em 0;letter-spacing:1px}@media screen and ");
|
|
client.println( "(max-width:599px){h1{text-align:center}}h2{font-size:1.25em;font-weight:700;line-height:1.2;padding:.5em 0}p{font-size:1em;padding:0 0 1em}a{color:#555;");
|
|
client.println( "text-decoration:none;border-bottom:1px solid #555}a:hover{color:#88b47f;border-bottom:1px solid #88b47f}*{-moz-box-sizing:border-box;-webkit-box-sizing:");
|
|
client.println( "border-box;box-sizing:border-box;-webkit-text-size-adjust:auto}body{font-family:sans-serif;font-size:100%;text-align:center;line-height:1.5;background:");
|
|
client.println( "#f8f7f0;color:#555}.wrapper{width:90%;max-width:50em;margin:0 auto;text-align:left;overflow:hidden}");
|
|
client.println( "header{margin-bottom:1em;padding-bottom:1em;background:#57575f;color:#fff}@media screen and (max-width:599px){.no-js .show_menu_btn{display:none}.js .show_menu_btn,.no-js #nav ul{display:block}.js #nav ul{display:none}}@media screen and (min-width:600px){.show_menu_btn{display:none}#nav ul{display:block}}.show_menu_btn{width:35%;margin:0 auto;padding:.3em;cursor:pointer;text-align:center;background:#88b47f}#nav ul{margin:1em 0}#nav ul li{padding:.5em}#nav ul li:hover{background:#88b47f}#nav ul a{display:block;font-size:1em;color:#eee;border-bottom:none}@media screen and (max-width:599px){#nav ul{display:block}#nav ul li{display:block;text-align:center;border-bottom:1px solid #6f6f7a}}@media screen and (min-width:600px){#nav{overflow:hidden}#nav ul li{width:7em;float:left;margin-right:1em}}");
|
|
//Bouton
|
|
client.println( ".boutonTemp {width:85px;height:85px;background:#fafafa;box-shadow:2px 2px 8px #aaa;font:bold 13px Arial;border-radius:50%;color:#555;}");
|
|
client.println( ".boutonCons {width:85px;height:85px;background:#cc0000;font:bold 13px Arial;border-radius:50%;border:none;color:#fff;}");
|
|
|
|
// PAGE MENU
|
|
client.println("input[type=\"checkbox\"] {display: none;}");
|
|
client.println("input[type=\"checkbox\"] + label {display:inline-block; line-height:normal; cursor:pointer; padding: 3px 14px;");
|
|
client.println("background-color: #EFEFEF;border-radius: 4px;border: 1px solid #D0D0D0;margin: 40px 100px 10px 40px;");
|
|
client.println("}input[type=\"checkbox\"] + label:hover {border-color: #000;background-color: #911;color: #fff;}");
|
|
client.println("input[type=\"checkbox\"]:checked + label {border-color: #000;background-color: #888;color: #fff;}");
|
|
|
|
|
|
client.println("</style>");
|
|
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////////
|
|
// PAGE ADMIN
|
|
///////////////////////////////////////////////////
|
|
void pageAdmin() {
|
|
|
|
client.println("<html>");
|
|
style();
|
|
body();
|
|
client.println("</html>\n\r");
|
|
}
|
|
|
|
void body() {
|
|
client.println( "<body>");
|
|
client.println( "<form action='/ident' method='get'>");
|
|
client.println( "<script type='text/javascript'>\nfunction showValue(newValue)\n{\ndocument.getElementById('text').innerHTML=newValue;\n}\n</script>");
|
|
client.println( "<div>");
|
|
client.println( "<label for='name'>SSID:</label>");
|
|
client.println( "<input type='text' id='name' name='name' />");
|
|
client.println( "</div>");
|
|
client.println( "<div>");
|
|
client.println( " <label for='pass'>Password:</label>");
|
|
client.println( " <input type='password' id='pass' name='pass' />");
|
|
client.println( "</div>");
|
|
client.println( "<div>");
|
|
client.println( " <label for='domo'>Domoticz:</label>");
|
|
client.println( " <input type='text' id='domo' name='domo' />");
|
|
client.println( " <label for='port'>Port:</label>");
|
|
client.println( " <input type='text' id='port' name='port' />");
|
|
client.println( "</div>");
|
|
client.println( "<div>");
|
|
client.println( " <label for='radi'>Id Radiateur:</label>");
|
|
client.println( " <input type='radi' id='radi' name='radi' />");
|
|
client.println( "</div>");
|
|
client.println( "<div class='button'>");
|
|
client.println( " <button name=H type='submit'>Ok</button>");
|
|
client.println( "</div>");
|
|
client.println( "</form>");
|
|
client.println( "</body>");
|
|
|
|
}
|
|
|
|
|
|
void style() {
|
|
|
|
client.println( "<style>");
|
|
client.println( "form {");
|
|
// client.println( " /* Just to center the form on the page */");
|
|
client.println( " margin: 0 auto;");
|
|
client.println( " width: 400px;");
|
|
client.println( "");
|
|
// client.println( " /* To see the limits of the form */");
|
|
client.println( " padding: 1em;");
|
|
client.println( " border: 1px solid #CCC;");
|
|
client.println( " border-radius: 1em;");
|
|
client.println( "}");
|
|
client.println( "");
|
|
client.println( "div + div {");
|
|
client.println( " margin-top: 1em;");
|
|
client.println( "}");
|
|
client.println( "");
|
|
client.println( "label {");
|
|
// client.println( " /* To make sure that all label have the same size and are properly align */");
|
|
client.println( " display: inline-block;");
|
|
client.println( " width: 90px;");
|
|
client.println( " text-align: right;");
|
|
client.println( "}");
|
|
client.println( "");
|
|
client.println( "input, textarea {");
|
|
// client.println( " /* To make sure that all text field have the same font settings");
|
|
// client.println( " By default, textarea are set with a monospace font */");
|
|
client.println( " font: 1em sans-serif;");
|
|
client.println( "");
|
|
// client.println( " /* To give the same size to all text field */");
|
|
client.println( " width: 300px;");
|
|
client.println( "");
|
|
client.println( " -moz-box-sizing: border-box;");
|
|
client.println( " box-sizing: border-box;");
|
|
client.println( "");
|
|
// client.println( " /* To harmonize the look & feel of text field border */");
|
|
client.println( " border: 1px solid #999;");
|
|
client.println( "}");
|
|
client.println( "");
|
|
client.println( "input:focus, textarea:focus {");
|
|
// client.println( " /* To give a little highligh on active elements */");
|
|
client.println( " border-color: #000;");
|
|
client.println( "}");
|
|
client.println( "");
|
|
client.println( "textarea {");
|
|
// client.println( " /* To properly align multiline text field with their label */");
|
|
client.println( " vertical-align: top;");
|
|
client.println( "");
|
|
// client.println( " /* To give enough room to type some text */");
|
|
client.println( " height: 5em;");
|
|
client.println( "");
|
|
// client.println( " /* To allow users to resize any textarea vertically");
|
|
// client.println( " It works only on Chrome, Firefox and Safari */");
|
|
client.println( " resize: vertical;");
|
|
client.println( "}");
|
|
client.println( "");
|
|
client.println( ".button {");
|
|
// client.println( " /* To position the buttons to the same position of the text fields */");
|
|
// client.println( " padding-left: 90px; /* same size as the label elements */");
|
|
client.println( "}");
|
|
client.println( "");
|
|
client.println( "button {");
|
|
// client.println( " /* This extra magin represent the same space as the space between");
|
|
// client.println( " the labels and their text fields */");
|
|
client.println( " margin-left: .5em;");
|
|
client.println( "}");
|
|
|
|
client.println(".toggle-slide {");
|
|
client.println(" overflow: hidden;");
|
|
client.println(" cursor: pointer;");
|
|
client.println(" -webkit-touch-callout: none;");
|
|
client.println(" -webkit-user-select: none;");
|
|
client.println(" -khtml-user-select: none;");
|
|
client.println(" -moz-user-select: none;");
|
|
client.println(" -ms-user-select: none;");
|
|
client.println(" user-select: none;");
|
|
client.println(" direction: ltr;");
|
|
client.println("}");
|
|
client.println(".toggle-slide .toggle-on,.toggle-slide .toggle-off,.toggle-slide .toggle-blob {");
|
|
client.println(" float: left;");
|
|
client.println("}");
|
|
client.println(".toggle-slide .toggle-blob {");
|
|
client.println(" position: relative;");
|
|
client.println(" z-index: 99;");
|
|
client.println(" cursor: hand;");
|
|
client.println(" cursor: grab;");
|
|
client.println(" cursor: -moz-grab;");
|
|
client.println(" cursor: -webkit-grab;");
|
|
client.println("}");
|
|
|
|
|
|
client.println( "</style>");
|
|
|
|
}
|
|
|
|
|
|
void graph() {
|
|
client.println( "<canvas id='canvas' ></canvas>");
|
|
|
|
client.println( "<script>");
|
|
client.println( "var randomScalingFactor = function(){ return Math.round(Math.random()*100)};");
|
|
|
|
client.println( "var lineChartData = {");
|
|
|
|
client.print( "labels : ["); //\"January\",\"February\",\"March\",\"April\",\"May\",\"June\",\"July\"],");
|
|
client.print(labels);
|
|
client.println("],");
|
|
|
|
client.println( "datasets : [");
|
|
client.println( "{");
|
|
client.println( "label: \"My First dataset\",");
|
|
client.println( " fillColor : \"rgba(220,220,220,0.2)\",");
|
|
client.println( " strokeColor : \"rgba(220,220,220,1)\",");
|
|
client.println( " pointColor : \"rgba(220,220,220,1)\",");
|
|
client.println( " pointStrokeColor : \"#fff\",");
|
|
client.println( " pointHighlightFill : \"#fff\",");
|
|
client.println( " pointHighlightStroke : \"rgba(220,220,220,1)\",");
|
|
client.print( " data : [");
|
|
|
|
|
|
// randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()
|
|
client.print(data);
|
|
client.print("]}");
|
|
|
|
client.println( " ]};");
|
|
client.println( "window.onload = function(){");
|
|
client.println( " var ctx = document.getElementById(\"canvas\").getContext(\"2d\");");
|
|
client.println( " window.myLine = new Chart(ctx).Line(lineChartData, {");
|
|
client.println( " responsive: true, animation:true});");
|
|
client.println( "}");
|
|
client.println( "</script>");
|
|
|
|
}
|
|
|
|
String getIndexOfString(String data, String separator, int index)
|
|
{
|
|
int found = 0;
|
|
int strIndex[] = { 0, -1 };
|
|
int maxIndex = data.length() - 1;
|
|
|
|
for (int i = 0; i <= maxIndex && found <= index; i++) {
|
|
if (data.charAt(i) == separator.charAt(0) || i == maxIndex) {
|
|
found++;
|
|
strIndex[0] = strIndex[1] + 1;
|
|
strIndex[1] = (i == maxIndex) ? i+1 : i;
|
|
}
|
|
}
|
|
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
|
|
}
|