PWA redirection & local

This commit is contained in:
2021-10-11 00:52:05 +03:00
parent 7e14e7143c
commit 1e682ea8f3
4 changed files with 18 additions and 5 deletions

View File

@@ -3,7 +3,7 @@
String systemConfig::getMACString()
{
String res;
for (int i=0; i<6; i++) {res+= (((char)mac[i]>>4)+'0');res+=(((char)mac[i]&0xf)+'0');}
for (int i=0; i<6; i++) {res+= ((String(mac[i]>>4,HEX)));res+=((String(mac[i]&0xf,HEX)));}
return res;
}

View File

@@ -237,13 +237,22 @@ uint16_t httpHandler(Client& client, String request, uint8_t method, long conten
debugSerial<<request<<endl;
if (method == HTTP_GET && request == (F("/")))
{
ArduinoOTA.sendHttpResponse(client,301,false); // Send only HTTP header, no close socket
client.println(
"Location: http://lazyhome.ru/pwa?mac="+sysConf.getMACString()
+"&ip="+Ethernet.localIP()//.toString()
+"&port="+ OTA_PORT
#ifdef CORS
//Redirect to cloud PWA application
String(F("Location: "))+QUOTE(CORS)+String(F("/pwa"))
#else
String(F("Location: /index.html"))
#endif
+String(F("?mac="))+sysConf.getMACString()
+String(F("&ip="))+ toString( Ethernet.localIP())
+String(F("&port="))+ OTA_PORT
+ String(F("&name="))+deviceName
);
//response+=(F("&ip="));
//todo response+=(Ethernet.localIP());
client.println();

View File

@@ -415,6 +415,9 @@ for(n = 0; n < 4; n++) {
return buf;
}
String toString(const IPAddress& address){
return String() + address[0] + "." + address[1] + "." + address[2] + "." + address[3];
}
void printIPAddress(IPAddress ipAddress) {
for (byte i = 0; i < 4; i++)

View File

@@ -74,3 +74,4 @@ bool executeCommand(aJsonObject* cmd, int8_t toggle, itemCmd _itemCmd, aJsonObje
itemCmd mapInt(int32_t arg, aJsonObject* map);
unsigned long millisNZ(uint8_t shift=0);
serialParamType str2SerialParam(char * str);
String toString(const IPAddress& address);