Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By sohialsadiq
#31413 HI,
try this code its working with android app sending & receiving data.


WiFiServer server(80);


/* Just a little test message. Go to http://192.168.4.1 in a web browser
* connected to this access point to see it.
*/


void setup() {
delay(1000);
Serial.begin(115200);

const char *ssid = "Timi";
const char *password = "timi373timi";




WiFi.softAP(ssid, password);


IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);

server.begin();
Serial.println("HTTP server started");



}

void wifi_data()
{

WiFiClient client = server.available(); // Wait for a new client



data =client.readStringUntil('\n');
Serial.print("data is =");
Serial.println(data);


client.println(temp);
client.println(hum);
client.println(Motion);


client.println(timer_status);
client.println(pin_data);
pin_data="";
Serial.print("timer_status");
Serial.println(timer_status);
client.stop();


}
User avatar
By bitmanrc
#31541 Hello friends,
I can not understand this skecth NOT where I'm wrong to do so to receive html page

I can send the GET on ASP
when I try to send the command from ASP page ESP
with example http://192.168.1.33/?comando=21&Azione=ON
I can not let him get the string
even if I do http://192.168.1.33, to open the HTML page of Arduino.
Where am I wrong?

Thank you in advance..

Code: Select all#include<stdlib.h>
 
#define SSID "Vodafone-xxxxxx" 
#define PASS "xxxxxxxxxxxxx" 
#define HOST "www.MIOSITO.it" 
#define PORT "80" 
  String Header;
 String Content;
int counter=0;
String cmd="";
String strURL = "";
String readString;
String Messaggio="";   


 
 
void setup() {
  Serial.begin(115200);
  Serial1.begin(115200);
  sendDebug("AT");
  delay(2000);
 
  if(Serial1.find("OK")){
    Serial.println("RECEIVED: OK");
    connectWiFi();
  }

  delay(1000);
 
 

}

 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void loop() {
 unsigned long int Ora = millis();
  counter++;
 SendToDomoticz();
char channel;   



  if( Serial1.find("+IPD,") )
  {   
    boolean currentLineIsBlank = true;   
    while (Serial1.available())
    {   
    if (Serial1.available())
      {   

      channel=Serial1.read();
      homepage(channel -'0');    //ascii to int
      delay(1);
         
      char c = Serial1.read();   
      readString.concat(c); 
      Messaggio= Messaggio + c;   
 
        //if (c == '\n' && currentLineIsBlank)
 
          {   
            Serial.println("Messaggio:");
            Serial.println(Messaggio);
            Serial.println("\r\n");
          }
     }
   }
 }
     
 
 
 
 delay(5000);
}
//==========================================================================================================================================================================================


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
boolean connectWiFi(){
 
  Serial1.println("AT+CWMODE=1");
  delay(3000);
  cmd="AT+CWJAP=\"";
  cmd+=SSID;
  cmd+="\",\"";
  cmd+=PASS;
  cmd+="\"";
  sendDebug(cmd);
  delay(3000);
  if(Serial1.find("OK")){
    Serial.println("RECEIVED: OK (connectWiFi)");
    return true;
  }else{
    Serial.println("RECEIVED: Error (connectWiFi)");
    return false;
  return true;
  }
 
}
//==========================================================================================================================================================================================



//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void sendDebug(String cmd){
  Serial.print("SEND: ");
  Serial.println(cmd);
  Serial1.println(cmd);
}
//==========================================================================================================================================================================================



//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void SendToDomoticz(){
  String cmd = "AT+CIPSTART=\"TCP\",\""; 
  cmd += HOST;
  cmd += "\",80"; 
  sendDebug(cmd);
  delay(2000);
  if(Serial1.find("Linked")) {
    Serial.println("Linked!");
  }
 delay(3000);
  cmd = "GET /ARDUINO.asp?Azione=ESP";
  cmd += int(millis()/1000);
  cmd += "(Counter=";
  cmd += counter;
  cmd += ")";
  cmd += "&Comando=CTRL&ArduinoIP=192,168,1,33";
  cmd += " HTTP/1.1\r\n";  //construct http GET request
  cmd += "Host: www.MIOSITO.it\r\n\r\n";        //Domoticz IP > Needs to be changed into variable that is set on top of sketch
  Serial1.print("AT+CIPSEND=");             
  Serial1.println(cmd.length());  //esp8266 needs to know message length of incoming message - .length provides this
 
  if(Serial1.find(">"))   
  {
   Serial.println(cmd);  //a debug message
    Serial1.println(cmd);  //this is our http GET request
  }
  else
  {
    Serial1.println("AT+CIPCLOSE"); 
    Serial.println("No '>' prompt received after AT+CPISEND");
  }
}
//==========================================================================================================================================================================================
//=============================================================================
void homepage(int ch_id) //this serves the page
{
  String Header;

  Header =  "HTTP/1.1 200 OK\r\n";            //bog standard stuff - should provide alternative headers
  Header += "Content-Type: text/html\r\n";
  Header += "Connection: close\r\n"; 
  Header += "Refresh: 1\r\n";

  String Content;
  Content = "<body bgcolor=\"#99ff99\" alink=\"#EE0000\" link=\"#0000EE\" text=\"#000000\"vlink=\"#551A8B\">";
  Content += "<title> ESP8266 test </title>";
  Content += "<H1>";
  Content += "pagina di prova ";
  counter++;

  Header += "Content-Length: ";  //ESP likes to know the length
  Header += (int)(Content.length());  //length determined here
  Header += "\r\n\r\n";    //blank line

  Serial1.print("AT+CIPSEND=");    //send the web page
  Serial1.print(ch_id);
  Serial1.print(",");
  Serial1.println(Header.length()+Content.length());
  delay(10);
  if (Serial1.find(">")) {  //prompt from ESP8266 indicating ready
    Serial1.print(Header);  //out it goes!!
    Serial1.print(Content);
    delay(10);
  }
}


Sorry for my English, I use a translator