ESP8266: cifsr:staip 0.0.0.0

Hi, i'm getting staip 0.0.0.0
it works only on one network when I use another network it doesn't recognise it's ip address instead it gives 0.0.0.0
using this code

#include <LCD5110_Graph.h>
#include <Adafruit_MLX90614.h>

#define DEVICE_ID "Monitor1"

#define DEBUG true
#define REQ_CODE_ACK 1
#define REQ_CODE_VALUES 2

//84w * 48h
LCD5110 myGLCD(8,9,10,12,11);
extern uint8_t SmallFont[];   //8h * 6w font

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
int pinLM35 = A0;         //Pin A0 is for LM35
int fsrAnalogPin = A2;    //Pin A2 is for force sensor
int blinkPin = 13;        // Pin 13 is the on-board LED

String mSSID = "LibyaADSL-9a86";    //initial ssid and password
String mPASS = "BYRTPCRJAHPWQ";

//http request code
int service_code;        


//wifi listen variables
String wifiBuf = "";        
char character;
int connectionId = 0 ;

//sensor values
float sensor_mlx, sensor_heart, sensor_lm35;
int sensor_force;

void setup() {
  //init LCD  
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  randomSeed(analogRead(7));

  //init MLX90614
  mlx.begin();

  //init serial
  Serial.begin(115200);           //Arduino-PC
  Serial3.begin(115200);          //Arduino-ESP8266\

  //init esp8266
  init8266(); 

  pinMode(blinkPin,OUTPUT);         // pin that will blink to your heartbeat!
    
  delay(200);
}

//init esp8266
void init8266()
{    
    Serial.println("Init ESP...");
    String stationConCmd = make8266InitCommand();
   
    sendCommand("AT+RST\r\n",2000,DEBUG);       // reset module
    sendCommand("AT+CWMODE=1\r\n",1000,DEBUG);  // configure as access point   غيرت 1 لي 3
   // sendCommand("AT+CWDHCP=1,1\r\n",1000,DEBUG);  // HI اني ضفته
   // sendCommand("AT+CIPSTA=192.168.0.101,192.168.0.1,255,255,255,0\r\n",1000,DEBUG);    // HI اني ضفته  
    sendCommand(stationConCmd, 1000, DEBUG);
    
   
    delay(1000);
    sendCommand("AT+CIFSR\r\n",1000,DEBUG);     // get ip address    
///
    sendCommand("AT+CIPMUX=1\r\n",1000,DEBUG);  // configure for multiple connections
    sendCommand("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80    
}

//Make command string for connect to AP
String make8266InitCommand()
{         
    String cmd = "AT+CWJAP=\"" ;        
    cmd += mSSID;
    cmd += "\",\"";
    cmd += mPASS;
    cmd += "\"";
    cmd += ",11,0\r\n";

    return cmd;
}

Can anyone help please ?

Thank you

You are not setting up the ESP9266 as Access Point ESP8266 - AT Command Reference · room-15

ieee488:
You are not setting up the ESP9266 as Access Point ESP8266 - AT Command Reference · room-15

Thank you for your answer

can you please tell me how to do that?

what's wrong in my code? what i'm missing ?

ieee488:
You are not setting up the ESP9266 as Access Point ESP8266 - AT Command Reference · room-15

CWMODE 1 is STA. OP wants to connect to AP. how should starting SoftAP help?

>AT+CWMODE=1

OK
>AT+CWJAP="XYZ","xyz"
WIFI CONNECTED
WIFI GOT IP

OK
>AT+CIFSR
+CIFSR:STAIP,"192.168.1.114"
+CIFSR:STAMAC,"ec:fa:bc:c4:1c:42"

OK

do you get the
WIFI CONNECTED
WIFI GOT IP
messages? it takes some seconds until they show up. only then it is connected and has IP

Juraj:

>AT+CWMODE=1

OK

AT+CWJAP="XYZ","xyz"
WIFI CONNECTED
WIFI GOT IP

OK

AT+CIFSR
+CIFSR:STAIP,"192.168.1.114"
+CIFSR:STAMAC,"ec:fa:bc:c4:1c:42"

OK



do you get the 
WIFI CONNECTED
WIFI GOT IP
messages? it takes some seconds until they show up. only then it is connected and has IP

I updated the post, please check, i changed the code and add the terminal output

i really tried many things, always i got 0.0.0.0

ieee488:
You are not setting up the ESP9266 as Access Point ESP8266 - AT Command Reference · room-15

Can you please modify my code to make it work ?
i'm really a beginner

what is 11,0 at the end of the CWJAP command?

Juraj:
what is 11,0 at the end of the CWJAP command?

channel,mode
i removed it and i still get 0.0.0.0

mmohamed2:
channel,mode
i removed it and i still get 0.0.0.0

show the current code and output

Juraj:
show the current code and output

sorry for the late reply, i was working on it without success

here's my latest code

#include <LCD5110_Graph.h>
#include <Adafruit_MLX90614.h>

#define DEVICE_ID "Monitor1"

#define DEBUG true
#define REQ_CODE_ACK 1
#define REQ_CODE_VALUES 2

//84w * 48h
LCD5110 myGLCD(8,9,10,12,11);
extern uint8_t SmallFont[];   //8h * 6w font

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
int pinLM35 = A0;         //Pin A0 is for LM35
int fsrAnalogPin = A2;    //Pin A2 is for force sensor
int blinkPin = 13;        // Pin 13 is the on-board LED

String mSSID = "LibyaADSL-9a86";    //initial ssid and password
String mPASS = "BYRTPCRJAHPWQ";

//http request code
int service_code;        


//wifi listen variables
String wifiBuf = "";        
char character;
int connectionId = 0 ;

//sensor values
float sensor_mlx, sensor_heart, sensor_lm35;
int sensor_force;

void setup() {
 //init LCD  
 myGLCD.InitLCD();
 myGLCD.setFont(SmallFont);
 randomSeed(analogRead(7));

 //init MLX90614
 mlx.begin();

 //init serial
 Serial.begin(115200);           //Arduino-PC
 Serial3.begin(115200);          //Arduino-ESP8266\

 //init esp8266
 init8266(); 

 pinMode(blinkPin,OUTPUT);         // pin that will blink to your heartbeat!
   
 delay(200);
}

//init esp8266
void init8266()
{    
   Serial.println("Init ESP...");

   sendCommand("AT+RST\r\n",2000,DEBUG);       // reset module
   sendCommand("AT+CWMODE=1\r\n",1000,DEBUG);  // configure as access point   غيرت 1 لي 3
   sendCommand("AT+CWDHCP=1,1\r\n",1000,DEBUG);  // HI اني ضفته
   sendCommand("AT+CWQAP\r\n",1000,DEBUG);     // quit the AP   
   delay(1000);  
   sendCommand("AT+CWJAP=\""+ mSSID +"\",\""+ mPASS +"\"",20,"OK"); // join the AP
   delay(10000);
   sendCommand("AT+CIFSR\r\n",1000,DEBUG);     // get ip address    

   sendCommand("AT+CIPMUX=1\r\n",1000,DEBUG);  // configure for multiple connections
   sendCommand("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80    
}


/*
* Name: sendCommand
* Description: Function used to send data to ESP8266.
* Params: command - the data/command to send; timeout - the time to wait for a response; debug - print to Serial window?(true = yes, false = no)
* Returns: The response from the esp8266 (if there is a reponse)
*/
String sendCommand(String command, const int timeout, boolean debug)
{
   String response = "";
          
   Serial3.print(command); // send the read character to the esp8266
   
   long int time = millis();
   
   while( (time+timeout) > millis())
   {
     while(Serial3.available())
     {        
       // The esp has data so display its output to the serial window 
       char c = Serial3.read(); // read the next character.
       response+=c;
     }  
   }
   
   if(debug)
   {
     Serial.print(response);
   }
   
   return response;
}

//Process wifi request
void procWifiRequest(String content)
{
   int indexEnd;
  int dataSize = content.length();
   char data[dataSize];
   content.toCharArray(data,dataSize);
   Serial.println("-------------------- Received Request --------------------");
   Serial.write(data, dataSize);
   int index = content.indexOf("+IPD,");    
   connectionId = content.charAt(index+5) - 48;

   index = content.indexOf("action=");
   service_code = content.charAt(index+7) - 48;

   Serial.println("Service code = " + service_code);
       
   if(service_code == REQ_CODE_VALUES)
   {
       responseSensors();
   }
   else 
   {
        String response;
        response = "result=ACK";           
        response += "&id=";
        response += DEVICE_ID;             
        sendHTTPResponse(connectionId,response); 
   }
}

void responseSensors()
{
   Serial.println("Responding Sensors...");
    String response;
    response = "result=success";
    response += "&mlx=";
    response += sensor_mlx;
    response += "&heartbeart=";
    response += sensor_heart;
    response += "&lm35=";
    response += sensor_lm35;
    response += "&pressure=";
    response += sensor_force;
    
    sendHTTPResponse(connectionId,response);   
}

/*
* Name: sendHTTPResponse
* Description: Function that sends HTTP 200, HTML UTF-8 response
*/
void sendHTTPResponse(int connectionId, String content)
{     
    // build HTTP response
    String httpResponse;
    String httpHeader;
    // HTTP Header
    httpHeader = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n"; 
    httpHeader += "Content-Length: ";
    httpHeader += content.length();
    httpHeader += "\r\n";
    httpHeader +="Connection: close\r\n\r\n";
    httpResponse = httpHeader + content + " "; // There is a bug in this code: the last character of "content" is not sent, I cheated by adding this extra space
    sendCIPData(connectionId,httpResponse);
}

/*
* Name: sendCIPDATA
* Description: sends a CIPSEND=<connectionId>,<data> command
*
*/
void sendCIPData(int connectionId, String data)
{
  String cipSend = "AT+CIPSEND=";
  cipSend += connectionId;
  cipSend += ",";
  cipSend +=data.length();
  cipSend +="\r\n";
  sendCommand(cipSend,1000,DEBUG);
  sendData(data,1000,DEBUG);
}

String sendData(String command, const int timeout, boolean debug)
{
   String response = "";
   
   int dataSize = command.length();
   char data[dataSize];
   command.toCharArray(data,dataSize);
          
   Serial3.write(data,dataSize); // send the read character to the esp8266             
   if(debug)
   {
     Serial.println("\r\n====== HTTP Response From Arduino ======");
     Serial.write(data,dataSize);
     Serial.println("\r\n========================================");
   }
   
   long int time = millis();
   
   while( (time+timeout) > millis())
   {
     while(Serial3.available())
     {
       
       // The esp has data so display its output to the serial window 
       char c = Serial3.read(); // read the next character.
       response+=c;
     }  
   }
   
   if(debug)
   {
     Serial.print(response);
   }
   
   return response;
}

void loop() {  
  //Listen http reques   while(Serial3.available()) 
  while(Serial3.available()){        
         character = Serial3.read();       
         wifiBuf.concat(character);        
  }    
  if (wifiBuf != "") 
  {
       wifiBuf.trim();
       
       if(wifiBuf.indexOf("action=") > 0)      
       {          
         if (wifiBuf.indexOf("action=2") > 0)
         {
           responseSensors();
         } 
         else 
         {
           procWifiRequest(wifiBuf);
         }
         wifiBuf.remove(0);      
       }            
  } 

  //read sensors
  sensor_mlx = mlx.readObjectTempC();

  int val = analogRead(pinLM35);
  float mv = (val*500)/1023;   
  sensor_lm35 = mv;
  /*vout=analogRead(sensor); //Reading the value from sensor

vout=(vout*500)/1023;

tempc=vout; // Storing value in Degree Celsius*/
  sensor_heart = 80;

  sensor_force = analogRead(fsrAnalogPin);

  //display values  
  myGLCD.print("MLX:", LEFT, 0);
  myGLCD.printNumF(sensor_mlx, 1, 6*5, 0);   
  myGLCD.print("°C", RIGHT, 0);

  myGLCD.print("LM35:", LEFT, 8);
  myGLCD.printNumF(sensor_lm35, 1, 6*6, 8);   
  myGLCD.print("°C", RIGHT, 8);

  myGLCD.print("HEART:", LEFT, 0);
  myGLCD.printNumF(sensor_heart, 1, 6*7, 16);   
  myGLCD.print("BPM", RIGHT, 0);

  myGLCD.update();
  
  delay(50);
}

and here's the output

what is 20, "OK" in sendCommand("AT+CWJAP=""+ mSSID +"",""+ mPASS +""",20,"OK");?

Juraj:
what is 20, "OK" in sendCommand("AT+CWJAP=""+ mSSID +"",""+ mPASS +""",20,"OK");?

i really don't know, i found it in the interent

i'll do a mistake in quotes if i removed it

please poste the line/code without it and i'll test and show you the output

mmohamed2:
i really don't know, i found it in the interent

i'll do a mistake in quotes if i removed it

please poste the line/code without it and i'll test and show you the output

you get nowhere if you don't understand the code.

Juraj:
you get nowhere if you don't understand the code.

i understand the code, but only that two params, i think 20 is the channel and OK is the response

mmohamed2:
i understand the code, but only that two params, i think 20 is the channel and OK is the response

I don't see a function with this parameters

Ok, how can i fix that? what's the right code to do that ?