Pushingbox notification doesn't work through iPhone hotspot [SOLVED]

The pushingbox example host on the github works well under my WIFI environment.
But when I try to use my iPhone hotspot, it doesn’t work all the time, maybe success once while trying twenty times. But the original program works well under hotpot connection.
Does anyone have any suggestion?

Below link is the pushingbox example.
https://github.com/Clement87/PushingBox-for-Spark-Core/blob/master/PushingBox-for-Spark.ino

I have a similar problem, due to the DNS lookup taking so long… its intermittent at home and only works if i do it twice in a row, and at work it never works, unless i specify the IP.

Im trying to make a workaround for that in another post…

But you can see if you have the same

try changing the

const char * servername  = "api.pushingbox.com"

to

byte serverame[] = {213, 186, 33, 19};

And see if that fixes it for you…

1 Like

@Hootie81, Thanks for your advise, I’ve try it, but it didn’t work.

Actually it could pass the connection code “client.connect(serverName, 80)” just like before.
But I still can’t receive notification with hotspot connection, but WIFI connection does.

Ok… next step… Im guessing you have Debug on… see what the server is returning if anything, between the client.println(); and the client.flush(); add these lines

while (!client.available()) SPARK_WLAN_Loop();
while (client.available()) {
      char c = client.read();
      Serial.print(c);
}

Should give you a response like

HTTP/1.1 200 OK
Set-Cookie: 60gpBAK=R1225225159; path=/; expires=Fri, 27-Jun-2014 18:20:25 GMT
Date: Fri, 27 Jun 2014 17:21:58 GMT
Content-Type: text/html
Content-Length: 0
Connection: close
Set-Cookie: 60gp=R475267376; path=/; expires=Fri, 27-Jun-2014 18:37:01 GMT
Server: Apache
Content-Location: pushingbox.php
Vary: negotiate,Accept-Encoding
TCN: choice
X-Powered-By: PHP/5.2.17

@Hootie81 While I use the normal WIFI connection, it do show the response like your post as below message.
But when I use the hotspot connection, looks that it’s occupied at the first while loop.

HTTP/1.1 200 OK
Set-Cookie: 60gpBAK=R1224193598; path=/; expires=Fri, 27-Jun-2014 18:52:24 GMT
Content-Type: text/html
Set-Cookie: 60gp=R2337163091; path=/; expires=Fri, 27-Jun-2014 19:03:06 GMT
Server: Apache
Content-Location: pushingbox.php
Vary: negotiate,Accept-Encoding
TCN: choice
Transfer-Encoding: chunked
Date: Fri, 27 Jun 2014 17:42:22 GMT
Connection: keep-alive
X-Geo: varn37.rbx5
X-Geo-Port: 1010
X-Cacheable: Not cacheable: no cache headers from backend 

@Hootie81 Behind reply is use the original server name instead of IP.
When I use your modification by IP with hotspot connection, it reply below message, looks different than previous.

HTTP/1.1 200 OK
Set-Cookie: 60gpBAK=R1224225179; path=/; expires=Fri, 27-Jun-2014 19:15:38 GMT
Server: nginx
Date: Fri, 27 Jun 2014 17:58:45 GMT
Content-Type: text/html; charset=utf8
Connection: keep-alive
content-length: 463
pragma: no-cache
cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
connection: close

<HTML><HEAD><TITLE>webmail http://webmail.ovh.net</TITLE>
<META NAME="Description" CONTENT="description de votre site">
<META NAME="KeyWords" CONTENT="les mots ">
</HEAD>
<FRAMESET rows="100%,*" frameborder=no border=0>
<!-- mettez le lien de votre choix -->
<FRAME SRC="http://webmail.ovh.net">
<FRAME SRC="" scrolling="No" noresize>
</FRAMESET>
<NOFRAME>
<BODY>
<a href="http:/ 

hmmm try adding a little delay before each client.print group like below.

if(DEBUG){Serial.println("connected");}        
delay(20);
client.print("GET /pushingbox?devid=");        
client.print(devid);        
client.println(" HTTP/1.1");        
delay(20);
client.print("Host: ");        
client.println(serverName);     
delay(20);   
client.println("User-Agent: Spark");           
delay(20);
client.println();

So did the hotspot work when you used the IP? the http response of 200 would suggest it did… but i dont know what the html part is about…

Just noticed that connection closed is commented out on the pushing box code now… its different to see the connection: keep alive, I have that connection: close line in my code and its working well as long as i specify the IP and not the hostname.

ovh is the site that hosts pushingbox so must be hitting his server, i think things get a bit truncated sometimes if we empty the buffer faster than it comes in and the while loop sees client available drop to 0. I dont know if it will tell you anything more but try adding a 5ms delay in the while loop that reads the response

@Hootie81, many thanks for your advice, below is my test result.

1, When used the IP still can’t work under the hotspot connection, after add “delay(20)” in the Serial.print while loop, it prints the same message as below.

HTTP/1.1 200 OK
Set-Cookie: 60gpBAK=R1224190331; path=/; expires=Sat, 28-Jun-2014 04:07:22 GMT
Server: nginx
Date: Sat, 28 Jun 2014 03:05:13 GMT
Content-Type: text/html; charset=utf8
Connection: keep-alive
content-length: 463
pragma: no-cache
cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
connection: close

<HTML><HEAD><TITLE>webmail http://webmail.ovh.net</TITLE>
<META NAME="Description" CONTENT="description de votre site">
<META NAME="KeyWords" CONTENT="les mots ">
</HEAD>
<FRAMESET rows="100%,*" frameborder=no border=0>
<!-- mettez le lien de votre choix -->
<FRAME SRC="http://webmail.ovh.net">
<FRAME SRC="" scrolling="No" noresize>
</FRAMESET>
<NOFRAME>
<BODY>
<a href="http:/ 

2, When include the code connection: close with IP. It is occupied in the while loop.
3, When include the code delay(20) after each client.println with server name, it is occupied in the while loop under the hotspot connection.
4, When include the code delay(20) after each client.println with IP, it prints the same message as behind message, and still can’t receive the push notification under the hotspot connection.

Well thats me just about out of idea’s… except maybe 20ms is a bit long, maybe try dropping it down to 2ms, and adding a timeout to the while loop that waits for a response, that way you can confirm that your not getting a response and its not hanging up on the connect somewhere.

change the

while (!client.available()) SPARK_WLAN_Loop();
while (client.available()) {
      char c = client.read();
      Serial.print(c);
}

to

unsigned long timer = millis();
while (!client.available() && millis() <= timer + 5000); SPARK_WLAN_Loop();
if (millis() >= timer + 5000) {
    if(DEBUG) Serial.println("Timed Out, waiting for response");
    return;
}
while (client.available() && DEBUG) {
    char c = client.read();
    Serial.print(c);
    delay(2);
}

maybe @clem will be able to give some insight?

2 Likes

@Hootie81~~Thanks for your code and suggestion.
Use your new code under the hotspot connection, it always display timeout message just like it occupied at while loop before.

Then I use your new debug code to do many combination test to see what is the difference between WIFI and my iPhone hotspot connection.

Finally…I found the difference!!!. Just need to add one line client.println(); after the client.println(serverName); and then it will work well as WIFI network.
I do really thanks for your help, without your advise and code I can’t make it work in just one day. Thank you^^

But I am still confuse about why the behavior of hotspot is different from WIFI.

1 Like

Glad to hear you got it sorted!

I do mine a bit different and use… thats why i couldn’t cut and paste straight from my code, i didn’t want to confuse things. mine has the extra new line + carriage return added on at the end, after the User-agent line.
strcpy(line, “Connection: close\r\n”);
strcat(line, “User-Agent: Spark\r\n\r\n”);
client.print(line);

Do you have any idea about why there is a bit difference between wifi and hotspot?
I do really curious about it.

No idea!

normally the empty line feed would be after all the http headers have been sent,

Did you get it working with the hostname or do you still have to use the IP Address?

After add a additional empty line, hostname works, too.

I will monitor it by more test.

@Hootie81 After days of testing, it do really work under hostname by adding a empty line after the host: serverName.
Thanks for your help^^.

1 Like