NodeMCU + pushingbox (pushbullet) + smartphone // works but doesn´t work :D

Hey everybody,

I´m trying to develop with my tinxi® NodeMCU Lua WIFI Internet Development Board Based on ESP8266 ESP-12E CP2102 a system, that reacts that will react on two sensors or in my first case a pushbutton and will send me a notification over wifi using pushingbox on my smartphone.

I tested the scenario on pushingox notification works perfectly fine. (Not even more than a couple seconds)
Also, the pushbutton, when I press the blue LED is on, but first it seems no notification.
Double checked SSID, password, and DeviceID all should be ok.

But I receive it feels somehow out of nowhere the correct pushingbox message. How can this be ? :smiley:
Also the serial port doesn´t connect

closing connection
Waiting…
Connecting

closing connection
Waiting…
Connecting

Using Arduino 1.8.5
Baudrate and so on 115000 checked it already as well again should be fine :confused:

#include <ESP8266WiFi.h>

String apiKey = “v2B”; //DevID changed it
const char* ssid = “WLAN-Name”; //SSID of your router changed it but in real it´s correct
const char* password = “7456555665666”; //WEP/WPA/WPA2 code for router changed it as well

const char* server = “api.pushingbox.com”;

int buttonPush = 0;
int button = D0;

WiFiClient client;

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

WiFi.begin(ssid, password);

Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println(“WiFi connected”);
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

}
void loop() {

if (digitalRead(button) == HIGH) {

if (client.connect(server,80)) {
Serial.println(“Connecting”);
client.print(“GET /pushingbox?devid=”);
client.print(apiKey);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println(“User-Agent: Arduino”);
client.println();
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil(’\r’);
Serial.print(line);
buttonPush = 1;
}

Serial.println();
Serial.println(“closing connection”);
}
}

client.stop();
Serial.println(“Waiting…”);
// thingspeak needs minimum 15 sec delay between updates
delay(1000);
buttonPush = 0;
}

I just checked it with my other Devide ID option.
As soon as the sketch is uploaded it will send two messages.

I pressed my button a couple times nothing new happens. :confused:

Every comparable source code would also highly be appreciated :slight_smile:

Thanks for any support.
Cheers from Upper Bavaria

Patrick

// thingspeak needs minimum 15 sec delay between updates
delay(1000);

So, 1 is good enough. Hmmm...

if (client.connect(server,80)) {
Serial.println("Connecting");

It is stupid to print "Connecting" only after you are "Connected".

  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  buttonPush = 1;
    }

After you made the GET request, EXACTLY how long did you wait for the server to generate a response? Is it even remotely likely that the server generated, AND returned, a response in that time?

What you are SUPPOSED to do after making a GET request is to use TWO while loops:

   while(client.connected())
   {
      while(client.available() > 0)
      {
         // Read the response WITHOUT pissing away resources on the stupid String class
      }
   }

The outer while loop will spin until the server has closed the connection, which it does NOT do until the complete response has been sent.