Cannot get ESP8266 WiFi module to connect to my access point


i running code below, in arduino pro mini, keep getting following results, ssid createc no password:

at+cwjap="createc",""
b
not connected wifi.
at+cwjap="createc",""
ÿ
not connected wifi.
at+cwjap="createc",""
b
not connected wifi.
at+cwjap="createc",""
b
not connected wifi.
at+cwjap="createc",""
ÿ
not connected wifi.
halted...   wifi not connected

the code following, can see, code using serial1 (i guess hardware rxi/txo perhaps arduino uno) , instead replaced each of lines use 2 digital pins according softwareserial ss(3, 2), code supposed send text messages cell phone using pushingbox.com api;

code: [select]


#include <softwareserial.h>

#define ssid "createc"  //name of wireless access point connect to
#define pass ""  //wifi password
#define dst_ip "213.186.33.19" // ip of api.pushingbox.com maybe changes, take dst_host
#define dst_host "api.pushingbox.com"

#define led 13

string smessage_1 = "vxyxyxaxjasdasdas";
string smessage_2 = "vsfdkjfkjsdhfkdsjfh";
string smessage_3 = "sdkfhshfkdshfksdas";
softwareserial ss(3, 2);

void setup()  //initialise device & connect access point in setup
{
  pinmode(led,output);

 
  reset();
 
  //serial1.begin(115200);    // hardware serial connects esp8266 module
  ss.begin(9600);
  serial.begin(9600); // usb serial connects to pc
 
  delay(4000);    //wait usb serial enumeration on 'serial' & device startup

  boolean wifi_connected=false;  //not connected yet...
  for(int i=0;i<5;i++)    //attempt 5 times connect wifi - idea
  {
    if(connectwifi())  //are connected?
    {
      wifi_connected = true;  //yes
      break;              //get outta here!
    }
  }
  if (!wifi_connected) hang("wifi not connected");  //these seem ok - never had problem
  delay(250);   
  if(!cipmux0()) hang("cipmux0 failed");
  delay(250);
  if(!cipmode0()) hang("cipmode0 failed");
  delay(250);
}

void loop()
{

//  !!!! testing of method push messages phone :-)

sendtopushingbox(smessage_1);
delay(1000);
sendtopushingbox(smessage_2);
delay(1000);
sendtopushingbox(smessage_3);
delay(1000);

while(1);   
}

//------------------------------------------------------------------------------------

void sendtopushingbox(string devid)
{
  string cmd = "at+cipstart=\"tcp\",\"";
  cmd += dst_host;
  cmd += "\",80";

  //serial1.println(cmd);  //send command device
  ss.println(cmd);  //send command device

  delay(2000);  //wait little while 'linked' response - makes difference

  cmd =  "get /pushingbox?devid=";
  cmd += devid;
  cmd += " http/1.1\r\n";  //construct http request
  cmd += "host: api.pushingbox.com\r\n\r\n";       
  //serial1.print("at+cipsend=");
  ss.print("at+cipsend=");             
  //serial1.println(cmd.length());  //esp8266 needs know message length of incoming message - .length provides this
  ss.println(cmd.length());

  //if(serial1.find(">"))    //prompt offered esp8266
  if(ss.find(">"))
  {
    //serial1.println(cmd);  //this our http request
    ss.println(cmd);
  }
  else
  {
    //serial1.println("at+cipclose");  //doesn't seem work here?
    ss.println("at+cipclose");
    //serial.println("no '>' prompt received after at+cpisend");
    ss.println("at+cipclose");
  }
 
  //serial1.println("at+cipclose");
  ss.println("at+cipclose");
}

boolean connectwifi()
{
  string cmd="at+cwjap=\"";  //form eg: at+cwjap="dynamode","55555555555555555555555555"
  cmd+=ssid;
  cmd+="\",\"";
  cmd+=pass;
  cmd+="\"";
  //serial1.println(cmd);
 
  serial.println(cmd);
 
  ss.println(cmd);
  delay(5000); //give time - access point can slow sometimes

  serial.println(char(ss.read()));
 
  //if(serial1.find("ok"))  //healthy response
  if(ss.find("ok"))
  {
    serial.println("connected wifi...");
    return true;
  }
  else
  { 
    serial.println("not connected wifi.");
    return false;
  }
}

//-------------------------------------------------------------------------------- 
//ditch in favour of hardware reset. done

boolean softwarereset()
{
  //serial1.println("at+rst");
  ss.println("at+rst");
  //if (serial1.find("ready"))
  if (ss.find("ready"))
  {
    return true;
  }
  else
  {
    return false;
  }
}

//--------------------------------------------------------------------------------

void reset()
{
  //serial1.println("at+rst");
  ss.println("at+rst");
 
  digitalwrite(led,high);
  delay(100);
  digitalwrite(led,low);
}

//------------------------------------------------------------------------------

boolean cwmode3()
// odd one. cwmode=3 means configure device access point & station. function can't fail?

{
  //serial1.println("at+cwmode=3");
  ss.println("at+cwmode=3");
  //if (serial1.find("no change"))  //only works if cwmode 3 previously
  if (ss.find("no change"))
  {
    return true;
  }
  else
  {
    return false;
  }
}

//----------------------------------------------------------------------------------

boolean cipmux0()
{
  //serial1.println("at+cipmux=0");
  ss.println("at+cipmux=0");
  //if (serial1.find("ok"))
  if (ss.find("ok"))
  {
    return true;
  }
  else
  {
    return false;
  }
}

//-----------------------------------------------------------------------

boolean cipmode0()
{
  //serial1.println("at+cipmode=0");
  ss.println("at+cipmode=0");
  //if (serial1.find("ok"))
  if (ss.find("ok"))
  {
    return true;
  }
  else
  {
    return false;
  }
}

//------------------------------------------------------------------------

void hang(string error_string)    //for debugging
{
  serial.print("halted...   ");
  serial.println(error_string);
  while(1)
  {
    digitalwrite(led,high);
    delay(100);
    digitalwrite(led,low);
    delay(100);
  }
}

//----------------------------------------------------------------------------

void hangreset (string error_string)    //for debugging
{
  serial.print(error_string);
  serial.println(" - resetting");
  reset();
}

code: [select]
  //serial1.begin(115200);    // hardware serial connects esp8266 module
  ss.begin(9600);

did configure esp8266 baud rate 115200 9600?


Arduino Forum > Using Arduino > Project Guidance > Cannot get ESP8266 WiFi module to connect to my access point


arduino

Comments