Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

"PDP Deact" Error with Fona808 and MQTT
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

"PDP Deact" Error with Fona808 and MQTT

by haku15 on Sat Feb 06, 2016 7:58 pm

I wanted to post a possible solution to the "PDP Deact" error. It is also listed on GitHub as issue: https://github.com/adafruit/io-issues/issues/65
My setup was based on an Arduino and a Fona808v2 and the basic sketch derived from this https://github.com/adafruit/Track_Your_Treats/blob/master/Track_Your_Treats_FONA808/Track_Your_Treats_FONA808.ino
When trying to connect to the io.adafruit.com server using TCP 1883 for MQTT, I always got a "Connection Failed" error from the Serial.println(mqtt.connectErrorString(ret)); and a "AT+CIPSTATUS <--- OK
<--- STATE: PDP DEACT"
The fact that PDP was deactivated is bad because this means you cannot send or receive data.
At the beginning I thought the 2G network provider was blocking the TCP port, but that isn't the case.
After reading the SIM808 TCPIP App note https://www.adafruit.com/images/product-files/2637/SIM800%20Series_TCPIP_Application%20Note_V1.01.pdf and doing some tests, I finally got a MQTT connection and could succesfully publish data to a feed on the Adafruit MQTT Server.
Following is the solution that seems to work for me. Disclaimer: I haven't tested it enough yet, code is still alpha and not so clean, but I wanted to share the solution asap because it is better than nothing. You should please check and test the solution yourself, before using it. It might not work for your network, I don't know. Any correction or improvement is welcome.
In the Adafruit_FONA library in Adafruit_Fona.cpp there is the method boolean Adafruit_FONA::enableGPRS(boolean onoff) that basically uses the command AT+SAPBR to set APN and activate GPRS context. This worked just fine when using REST and HTTP posts, but not with MQTT.
Looking at page 6 of the manual cited above, you see other commands listed for a TCP connection.
So I put these commands to a new method called boolean Adafruit_FONA::enableGPRSforMQTT() in Adafruit_Fona.cpp:
Code: Select all | TOGGLE FULL SIZE
boolean Adafruit_FONA::enableGPRSforMQTT() {

  char csttString[130] = "AT+CSTT=\"";  // this string is to contain the command AT+CSTT="apn","user","pw"


 // set username/password
      if (apn) {
   
     char *strp = csttString + strlen(csttString);
     strcpy_P(strp, (prog_char *)apn);
     strp+=strlen_P((prog_char *)apn);
     strp[0] = '\"';
     strp++;
     strp[0] = 0;
   
     if (apnusername) {
       strp[0] = ','; strp++;
       strp[0] = '\"'; strp++;
       strcpy_P(strp, (prog_char *)apnusername);
       strp+=strlen_P((prog_char *)apnusername);
       strp[0] = '\"';
       strp++;
       strp[0] = 0;

       if (apnpassword) {
         strp[0] = ','; strp++;
         strp[0] = '\"'; strp++;
         strcpy_P(strp, (prog_char *)apnpassword);
         strp+=strlen_P((prog_char *)apnpassword);
         strp[0] = '\"';
         strp++;
         strp[0] = 0;
       }
     }
   
   }
 
  //attach to GPRS
  if (! sendCheckReply(F("AT+CGATT=1"), F("OK"), 10000)) return false;

    // single connection at a time
  if (! sendCheckReply(F("AT+CIPMUX=0"), F("OK")) ) return false;
   
   // manually read data
  if (! sendCheckReply(F("AT+CIPRXGET=1"), F("OK")) ) return false;
 
  //AT+CSTT command to set APN   
  if (! sendCheckReply(csttString, "OK", 10000))  return false;
        
  //bring up wireless connection (GPRS)    
  if (! sendCheckReply(F("AT+CIICR"), F("OK"), 10000))  return false;
    
  //return assigned ip address. This is necessary, otherwise "operation not allowed" error
  getReply(F("AT+CIFSR"));
 
  return true;
}

Please notice that the command sequence matters. Moving an AT Command before or after might returns errors.

- Add the new method boolean enableGPRSforMQTT(); to Adafruit_FONA.h

- Then in the Arduino sketch, be sure to call these methods, but don't use the default fona.enableGPRS():
Code: Select all | TOGGLE FULL SIZE
fona.setGPRSNetworkSettings(F("apn"), F("user"), F("pw"));
fona.unlockSIM(PIN);  //only if you have PIN on SIM
fona.enableGPRSforMQTT();

I hope this can help you.
Sincerely

haku15
 
Posts: 72
Joined: Mon Jun 25, 2012 12:45 pm

Re: "PDP Deact" Error with Fona808 and MQTT

by haku15 on Sat Feb 06, 2016 8:38 pm

I forgot to post one step, sorry.
In Adafruit_Fona.CPP I also removed the following lines from boolean Adafruit_FONA::TCPconnect(char *server, uint16_t port)
Code: Select all | TOGGLE FULL SIZE
 
// close all old connections
  if (! sendCheckReply(F("AT+CIPSHUT"), F("SHUT OK"), 5000) ) return false;

  // single connection at a time
  if (! sendCheckReply(F("AT+CIPMUX=0"), F("OK")) ) return false;

  // manually read data
  if (! sendCheckReply(F("AT+CIPRXGET=1"), F("OK")) ) return false;

haku15
 
Posts: 72
Joined: Mon Jun 25, 2012 12:45 pm

Re: "PDP Deact" Error with Fona808 and MQTT

by haku15 on Sat Feb 06, 2016 9:06 pm

Ladyada has just answered on GitHub that this issue might have been fixed with the release of 20Jan 2016 of the Fona library.
I am using a version dowloaded on the 1st Jan.
Users experiencing the "PDP Deact" problem are kindly invited to test the latest release.

haku15
 
Posts: 72
Joined: Mon Jun 25, 2012 12:45 pm

Re: "PDP Deact" Error with Fona808 and MQTT

by jameskdoherty009 on Mon Feb 08, 2016 12:44 am

Just wanted to make a note that using the ESP8266 for the basic input test, I can connect to IO and serial monitor shows success but the button in my dashboard shows ###, not getting data.

jameskdoherty009
 
Posts: 7
Joined: Fri Sep 19, 2014 2:19 pm

Re: "PDP Deact" Error with Fona808 and MQTT

by adafruit2 on Mon Feb 08, 2016 12:56 am

james, if you're not using a fona808 then please start a new thread

adafruit2
Site Admin
 
Posts: 19399
Joined: Fri Mar 11, 2005 7:36 pm

Re: "PDP Deact" Error with Fona808 and MQTT

by haku15 on Mon Feb 08, 2016 7:01 pm

I've tested the latest FONA library release (committed on 20 Jan).
It works, very good! I don't see "PDP DEACT" anymore: now I see "STATE: CONNECT OK" and that's correct.
I've tried MQTT and REST and both work, I could post data to feeds successfully.
Thank you very much!

haku15
 
Posts: 72
Joined: Mon Jun 25, 2012 12:45 pm

Re: "PDP Deact" Error with Fona808 and MQTT

by sunderj91 on Sat Apr 23, 2016 9:54 am

I tried using the change mentioned above in my cpp and.h files and I m still seeing the MQTT connection fail issue.
Disabling GPRS
Enabling GPRS
---> AT+CGATT=1
<--- OK
---> AT+CIPMUX=0
<--- OK
---> AT+CIPRXGET=1
<--- OK
---> AT+CSTT="airtelgprs.com"
<--- OK
---> AT+CIICR
<--- OK
---> AT+CIFSR
<--- 100.80.173.221
Connected to Cellular!
AT+CIPSTART="TCP","io.adafruit.com","1883"
<--- OK
<--- CONNECT OKÿ
Connection failed
MQTT connection failed, resetting...

I can also see that https://github.com/adafruit/Adafruit_FO ... fe57fd3d8d doesnt have the GPRS change mentioned. Can someone point me to the right github link thats has the changes .

sunderj91
 
Posts: 1
Joined: Wed Apr 20, 2016 8:17 am

Please be positive and constructive with your questions and comments.