ESP8266 PushingBox problem

Hello,
has anyone managed to send a GET command to generate a notification with pushingbox.com?
or send a email with the ESP8266 (has someone a example code?)

#define SSID "WIFI_AP"
#define WIFIPASS "WIFI_PASSWD"

#define DSTIP "213.186.33.19"
#define DSTHOST "api.pushingbox.com"
#define DSTPORT 80

#define SERIAL_BUFFER_SIZE 256

int counter = 0;
char incomingByte;

void setup() {
 Serial.begin(115200);
 Serial1.begin(115200);
 espInit();
}

void loop() {

 sendIotData();
  
  while (Serial1.available())
  {
    char c = Serial1.read();
    Serial.print(c);
    if (c == '\r') Serial.print('\n');
  }

while(1);

}

void espInit() {
 Serial1.println("AT+RST");
 Serial.println("AT+RST");
if(Wait4String("ready", 5000)) {
        while(Serial1.available()) { Serial1.read();}
        Serial.println("WiFi - Module is ready");
    }else{
        Serial.println("Module dosn't respond.");
        while(1);
    }
    delay(500);
    
 Serial1.println("AT+CWMODE=1");
 Serial.println("AT+CWMODE=1");
 delay(500);
 // Join WiFi Network
 Serial.println("Join WiFi");
 Serial1.print("AT+CWJAP=\"");
 Serial1.print(SSID);
 Serial1.print("\",\"");
 Serial1.print(WIFIPASS);
 Serial1.println("\"");
if(Wait4String("OK", 5000)) {
        while(Serial1.available()) { Serial1.read();}
        Serial.println("WiFi - connected");
    }else{
        Serial.println("WiFi - not connected");
        while(1);
    }
    delay(500);

}

void sendIotData(){

 String startcommand = "AT+CIPSTART=\"TCP\",\"" + String(DSTHOST) + "\", 80"; 
     
 Serial1.println(startcommand);
 Serial.println(startcommand);
 
 
 
 //test for a start error
     if(Serial1.find("Error")){
       Serial.println("error on start");
       return;
     }
     
     //create the request command
     String sendcommand = "GET /pushingbox?devid=<MYDEVID> HTTP/1.1\r\nHost: api.pushingbox.com\r\nUser-Agent: ESP8266\r\n";
     
     
     
     //send 
     Serial1.print("AT+CIPSEND=");
     Serial1.println(sendcommand.length());
     Serial.print("\nlaenge:");
     Serial.println(sendcommand.length());

while (Serial1.available())
  {
    char c = Serial1.read();
    Serial.write(c);
    if (c == '\r') Serial.print('\n');
  }
     
     Serial.print(sendcommand);
     Serial1.print(sendcommand); 
 
     while (Serial1.available())
  {
    char c = Serial1.read();
    Serial.write(c);
    if (c == '\r') Serial.print('\n');
  }
  Serial.println("====");
}

bool Wait4String(String S, int Time) {
    int L = S.length();
    String T = String(" ");
    while(Time>0) {
        if (Serial1.available()) {
            char c = Serial1.read();
            T = T + String(c);
            if (T.length() > L) T = T.substring(1);
            if (S.charAt(0) == T.charAt(0))
            if (S.compareTo(T) == 0) return true;
        }
        else {
            delay(1);
            Time--;
        }
    }
    return false;
}

String Wait4String(int Time) {
    String T = String("");
    while(Time>0) {
        if (Serial1.available()) {
            char c = Serial1.read();
            T = T + String(c);
        }
        else {
            delay(1);
            Time--;
        }
    }
    return T;
}

when i post the get code (http://api.pushingbox.com/pushingbox?devid= in my Browser then i get a notification with Pushbullet through Pushingbox....

is there a error?

ps. has someone managed to send an email with the esp8266 with/without SSL

Where do you wait for a response to sending data before you start the infinite do-nothing loop that locks the Arduino up?

there shouldn't be a response or am i wrong...

i make a TCP connection -> Send length of my GET command -> send GET command

there shouldn't be a response or am i wrong...

You posted here. You do expect a response, don't you? Even if that is nothing more than "Yes, the post worked".

It doesn't make sense to me to send a message as soon as the Arduino boots up, and then lock it up.

Add a switch. Send the data only when the switch BECOMES pressed. Spend the rest of the time reading any response. Do NOT lock the Arduino up.

Thats only a test of the method to get a notification on my mobile phone.

The esp8266 responds with OK but nothing happens, i mean i get no notification...

ok it works now, i took a example code from http://www.cse.dmu.ac.uk/~sexton/ESP8266/ and modified it a bit.

Now i will implement it to my washing machine and clothes dryer and mail box and and and ... :slight_smile:

Have Fun!

Here is the code:

#define SSID "WIFI_AP"  //name of wireless access point to connect to
#define PASS "WIFI_PASS"  //wifi password
#define DST_IP "213.186.33.19" // IP of api.pushingbox.com maybe it changes, so take DST_HOST
#define DST_HOST "api.pushingbox.com"

#define LED 13

String sMessage_1 = "vxyxyxaxjasdasdas";
String sMessage_2 = "vsfdkjfkjsdhfkdsjfh";
String sMessage_3 = "sdkfhshfkdshfksdas";

void setup()  //initialise device & connect to access point in setup
{
  pinMode(LED,OUTPUT);

  //softwarereset();
  reset();
  
  Serial1.begin(115200);    // hardware serial connects to esp8266 module
  Serial.begin(115200); // usb serial connects to to pc
  delay(4000);    //wait for usb serial enumeration on 'Serial' & device startup

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

void loop()
{


//  !!!! ONLY TESTING OF METHOD TO PUSH THE MESSAGES TO MY 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 to device

  delay(2000);  //wait a little while for 'Linked' response - this makes a difference

  cmd =  "GET /pushingbox?devid=";
  cmd += devid;
  cmd += " HTTP/1.1\r\n";  //construct http GET request
  cmd += "Host: api.pushingbox.com\r\n\r\n";       
  Serial1.print("AT+CIPSEND=");                
  Serial1.println(cmd.length());  //esp8266 needs to know message length of incoming message - .length provides this

  if(Serial1.find(">"))    //prompt offered by esp8266
  {
    Serial1.println(cmd);  //this is our http GET request
  }
  else
  {
    Serial1.println("AT+CIPCLOSE");  //doesn't seem to work here?
    Serial.println("No '>' prompt received after AT+CPISEND");
  }
  
  Serial1.println("AT+CIPCLOSE");
}

boolean connectWiFi()
{
  String cmd="AT+CWJAP=\"";  //form eg: AT+CWJAP="dynamode","55555555555555555555555555"
  cmd+=SSID;
  cmd+="\",\"";
  cmd+=PASS;
  cmd+="\"";
  Serial1.println(cmd);
  delay(5000); //give it time - my access point can be very slow sometimes
  if(Serial1.find("OK"))  //healthy response
  {
    Serial.println("Connected to WiFi...");
    return true;
  }
  else
  {
    Serial.println("Not connected to WiFi.");
    return false;
  }
}
//--------------------------------------------------------------------------------  
//ditch this in favour of hardware reset. Done
boolean softwarereset()
{
  Serial1.println("AT+RST");
  if (Serial1.find("ready"))
  {
    return true;
  }
  else
  {
    return false;
  }
}
//--------------------------------------------------------------------------------
void reset()
{
  Serial1.println("AT+RST");
  digitalWrite(LED,HIGH);
  delay(100);
  digitalWrite(LED,LOW);
}
//------------------------------------------------------------------------------
boolean cwmode3()
// Odd one. CWMODE=3 means configure the device as access point & station. This function can't fail?

{
  Serial1.println("AT+CWMODE=3");
  if (Serial1.find("no change"))  //only works if CWMODE was 3 previously
  {
    return true;
  }
  else
  {
    return false;
  }
}
//----------------------------------------------------------------------------------
boolean cipmux0()
{
  Serial1.println("AT+CIPMUX=0");
  if (Serial1.find("OK"))
  {
    return true;
  }
  else
  {
    return false;
  }
}
//-----------------------------------------------------------------------
boolean cipmode0()
{
  Serial1.println("AT+CIPMODE=0");
  if (Serial1.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();
}

i have tried using your code with esp8266 using arduino ide version 1.6.1 but i get this error message

test.ino:21:3: error: 'Serial1' was not declared in this scope
test.ino: In function 'void sendToPushingBox(String)':
test.ino:64:3: error: 'Serial1' was not declared in this scope
test.ino: In function 'boolean connectWiFi()':
test.ino:95:3: error: 'Serial1' was not declared in this scope
test.ino: In function 'boolean softwarereset()':
test.ino:112:3: error: 'Serial1' was not declared in this scope
test.ino: In function 'void reset()':
test.ino:125:3: error: 'Serial1' was not declared in this scope
test.ino: In function 'boolean cwmode3()':
test.ino:135:3: error: 'Serial1' was not declared in this scope
test.ino: In function 'boolean cipmux0()':
test.ino:148:3: error: 'Serial1' was not declared in this scope
test.ino: In function 'boolean cipmode0()':
test.ino:161:3: error: 'Serial1' was not declared in this scope
Error compiling.

can you help

Thanks

Hello,
i compiled it now without errors on Arduino 1.0.6. There are no additional libraries included.

Maybe you do not have additional Serial1 port for communication. Which board do you using?

For testing: Try to compile for other board. I used Arduino Pro Mini 328

EDIT: I tested it with 1.6.3. It compiles wthout errors

can you please share your code especially the piece that shows how you are software serial programming the Pro mini digital pins?