Hi There,
I am using a Fona addon board with an Arduino Uno to try and upload data to the Adafruit IO. I have been following this tutorial https://learn.adafruit.com/adafruit-io-basics-digital-input/arduino-cellular and have come across an issue where it says that the Fona Failed to turn GPRS On.
Disabling GPRS
---> AT+CIPSHUT
<--- SHUT OK
---> AT+SAPBR=0,1
<--- +CME ERROR: operation not allowed
Enabling GPRS
---> AT+CIPSHUT
<--- SHUT OK
---> AT+CGATT=1
<--- +CME ERROR: unknown
Failed to turn GPRS on
And then it starts the whole process over again. I have compared to code that attempts to connect to GPRS to the test example included in the FONA library and the code looks identical to me.
Does anyone know why I am getting this error?
The code I am using;
/***************************************************
Adafruit MQTT Library FONA Example
Designed specifically to work with the Adafruit FONA
----> http://www.adafruit.com/products/1946
----> http://www.adafruit.com/products/1963
----> http://www.adafruit.com/products/2468
----> http://www.adafruit.com/products/2542
These cellular modules use TTL Serial to communicate, 2 pins are
required to interface.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
Adafruit IO example additions by Todd Treece.
MIT license, all text above must be included in any redistribution
****************************************************/
#include <Adafruit_SleepyDog.h>
#include <SoftwareSerial.h>
/* #include <Adafruit_SleepyDog.h>
#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_FONA.h"
*/
/****************************** Pins ****************************************/
#include <Adafruit_MQTT_FONA.h>
//#include <Adafruit_MQTT_Client.h>
//#include <Adafruit_MQTT_CC3000.h>
#include <Adafruit_MQTT.h>
#include <Adafruit_FONA.h>
#define BUTTON 8
#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
/*************************** Cellular APN *************************************/
// Optionally configure a GPRS APN, username, and password.
// You might need to do this to access your network's GPRS/data
// network. Contact your provider for the exact APN, username,
// and password values. Username and password are optional and
// can be removed, but APN is required.
#define FONA_APN "payandgo.o2.co.uk"
#define FONA_USERNAME "payandgo"
#define FONA_PASSWORD "password"
/************************* Adafruit.io Setup *********************************/
#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "stevieg"
#define AIO_KEY "b2107871084a43c7841f4c222fb285a3"
/************ Global State (you don't need to change this!) ******************/
// Store the MQTT server, client ID, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
// Set a unique MQTT client ID using the AIO key + the date and time the sketch
// was compiled (so this should be unique across multiple devices for a user,
// alternatively you can manually set this to a GUID or other random value).
const char MQTT_CLIENTID[] PROGMEM = __TIME__ AIO_USERNAME;
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
// Setup the FONA MQTT class by passing in the FONA class and MQTT server and login details.
Adafruit_MQTT_FONA mqtt(&fona, MQTT_SERVER, AIO_SERVERPORT, MQTT_CLIENTID, MQTT_USERNAME, MQTT_PASSWORD);
// You don't need to change anything below this line!
#define halt(s) { Serial.println(F( s )); while(1); }
// FONAconnect is a helper function that sets up the FONA and connects to
// the GPRS network. See the fonahelper.cpp tab above for the source!
boolean FONAconnect(const __FlashStringHelper *apn, const __FlashStringHelper *username, const __FlashStringHelper *password);
/****************************** Feeds ***************************************/
// Setup a feed called 'button' for publishing changes.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
const char BUTTON_FEED[] PROGMEM = AIO_USERNAME "/feeds/button";
Adafruit_MQTT_Publish button = Adafruit_MQTT_Publish(&mqtt, BUTTON_FEED);
/*************************** Sketch Code ************************************/
// button state
int current = 0;
int last = -1;
void setup() {
// set button pin as an input
pinMode(BUTTON, INPUT_PULLUP);
Serial.begin(115200);
Serial.println(F("Adafruit IO Example"));
// Initialise the FONA module
while (! FONAconnect(F(FONA_APN), F(FONA_USERNAME), F(FONA_PASSWORD)))
halt("Retrying FONA");
Serial.println(F("Connected to Cellular!"));
Watchdog.reset();
delay(3000); // wait a few seconds to stabilize connection
Watchdog.reset();
// connect to adafruit io
connect();
}
void loop() {
// Make sure to reset watchdog every loop iteration!
Watchdog.reset();
// ping adafruit io a few times to make sure we remain connected
if(! mqtt.ping(3)) {
// reconnect to adafruit io
if(! mqtt.connected())
connect();
}
// grab the current state of the button
current = digitalRead(BUTTON);
// return if the value hasn't changed
if(current == last)
return;
int32_t value = (current == LOW ? 1 : 0);
// Now we can publish stuff!
Serial.print(F("\nSending button value: "));
Serial.print(value);
Serial.print("... ");
if (! button.publish(value))
Serial.println(F("Failed."));
else
Serial.println(F("Success!"));
// save the button state
last = current;
}
// connect to adafruit io via MQTT
void connect() {
Serial.print(F("Connecting to Adafruit IO... "));
int8_t ret, retries = 5;
while ((ret = mqtt.connect()) != 0) {
switch (ret) {
case 1: Serial.println(F("Wrong protocol")); break;
case 2: Serial.println(F("ID rejected")); break;
case 3: Serial.println(F("Server unavail")); break;
case 4: Serial.println(F("Bad user/pass")); break;
case 5: Serial.println(F("Not authed")); break;
case 6: Serial.println(F("Failed to subscribe")); break;
default: Serial.println(F("Connection failed")); break;
}
if(ret >= 0)
mqtt.disconnect();
retries--;
if (retries == 0)
halt("Resetting system");
Serial.println(F("Retrying connection..."));
delay(5000);
}
Serial.println(F("Adafruit IO Connected!"));
}
FonaHelper Code;
#include <Adafruit_SleepyDog.h>
#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"
#define halt(s) { Serial.println(F( s )); while(1); }
extern Adafruit_FONA fona;
extern SoftwareSerial fonaSS;
boolean FONAconnect(const __FlashStringHelper *apn, const __FlashStringHelper *username, const __FlashStringHelper *password) {
Watchdog.reset();
Serial.println(F("Initializing FONA....(May take 3 seconds)"));
fonaSS.begin(4800); // if you're using software serial
if (! fona.begin(fonaSS)) { // can also try fona.begin(Serial1)
Serial.println(F("Couldn't find FONA"));
return false;
}
fonaSS.println("AT+CMEE=2");
Serial.println(F("FONA is OK"));
Watchdog.reset();
Serial.println(F("Checking for network..."));
while (fona.getNetworkStatus() != 1) {
delay(500);
}
Watchdog.reset();
delay(5000); // wait a few seconds to stabilize connection
Watchdog.reset();
fona.setGPRSNetworkSettings(apn, username, password);
Serial.println(F("Disabling GPRS"));
fona.enableGPRS(false);
Watchdog.reset();
delay(5000); // wait a few seconds to stabilize connection
Watchdog.reset();
Serial.println(F("Enabling GPRS"));
if (!fona.enableGPRS(true)) {
Serial.println(F("Failed to turn GPRS on"));
return false;
}
Watchdog.reset();
return true;
}