top of page

FONA 808 and Adafruit IO Debugging

The Adafruit's IO Dashboard, Adafruit IO, is an excellent platform for easily reading data into a cloud platform and transmitting data back to devices. I personally have had great success using Adafruit IO with ESP8266-based development boards via Wifi. The downside of Wifi is you need to be in range of a network, and for some projects that is an unreasonable requirement.


This is where the Adafruit FONA comes in. Based on the SIM 808 cellular chip, the FONA can connect your devices to the internet via GPRS using a 2G SIM card. Additionally, it has integrated GPS as well. These characteristics make this breakout the idea choice for anything needing real-time geo-location information.


I have two projects that I am attempting to use two different variations of the FONA board for, the FONA 808 Arduino sheild, and the FONA 808 breakout. Though I am able to connect the chips to the internet, I have had no success connecting the boards to Adafruit IO. Here, I will detail my troubleshooting process as I attempt to connect my devices via the FONA 808 to Adafruit IO.




HARDWARE




The Hardware primarily used in the debugging thus far is as follows:

- Adafruit Metro

- FONA 808 Shield for Arduino (v2)

- Long sticker-type cellular antenna

- GPS antenna

- 500 mAh LiPo battery

- 2G Prepaid SIM card from Tmobile

- 2G Prepaid SIM card from Ting (Tmobile wholesaler)


The bulk of my debugging attempts have been made with the aforementioned hardware. The FONA 808 shield is the second version, which is significant because the AT commands for the GPS are different - though the new FONA library accounts for this.




TCP ERROR?


The basic project I was attempting was the Geofencing Project by Marc-Oliver Schwartz. When using the SIM card from Ting Wireless, I repeatedly encountered an issue with finding consistent signal. When I did find signal, it was weak, intermittent, and was not able to connect to the internet. This was despite having data enabled on my plan.


Marc-Oliver Schwartz suggested a possible solution to this in a Github discussion where he indicated he had to use a SIM card for another carrier for the tutorial, though he doesn't indicate which providers he was using. To see if this was my problem as well, I changed over to a prepaid SIM from Tmobile directly (vs. a Tmobile wholesaler). If the Tmobile was limiting port access for wholesalers, this should have resolved the issue.


Upgrading the SIM to Tmobile greatly improved service reception and reliability. For this reason, I would recommend that others go directy with Tmobile (which provides pre-paid cards at very reasonable prices). It enabled connection to the network quickly, but of course, presented its own error...




TURNING ON MQTT DEBUG


If you are having an issue connecting your devices to the Adafruit IO platform, you can enable a verbose debug output to the serial monitor by simply uncommenting a single line of code.


1. Navigate to your Adafruit_MQTT.h library. Your library is under the "Arduino" folder, which is typically located in "Documents" on Windows platforms.


Arduino > libraries > Adafruit_MQTT_Library > Adafruit_MQTT.h


2. Open the Adafruit_MQTT.h library using your text editor of choice. I use Atom.


3. Uncomment line 37, this will print the debug output messages to the serial monitor so that you can better deduce the source of failure when connecting to Adafruit IO. Don't forget to save!



4. Re-upload your code. You should see more verbose output when connecting to Adafruit IO (after network connection is made).




COMMON ISSUES


Below are some of the common issues you may run into and the solutions that I found when working with the FONA808 and the Adafruit Metro board.



Couldn't Find FONA


This is commonly because the service is not sufficient for connection - or because there is too much noise in the area for the given signal strength. You can verify it is a service issue by uploading the FONA test example and querying the RSSI which will give you 2 numbers, signal strength and noise. USAT has a good description of how the signal strength works, and what constitutes a "good" signal; you can find that website here.


RSSI Signal Strength (in dBm)

Excellent above -65 (closer to zero is better

Good -65 to -75

Fair -75 to -85

Poor below -85


If your signal strength is poor, you need to stop whatever else you're working on and resolve it immediately, as it will prevent you from making any progress. This may mean you need a new SIM card (contract carriers such as Ting, and USAcellular do not have as good of tower access as Tmobile), need a new antenna (or a longer one... antenna needs to be away from the IC on the microcontrollers, move to a better service area (check by popping the SIM into your phone to verify lack of service), or you may have a hardware problem.


If you upload the FONA test sketch and open the serial monitor, you will get a read out of the network status by typing "n" and then hitting enter. Be sure the monitor is set up for "Both NL & CR" in the bottom right-hand corner of the window in the drop down menu. You will see something like:


---> AT+CREG? <--- +CREG: 0,2


The outgoing "AT+CREG?" command queries your SIM808 chip for the network status. The incoming "+CREG: 0,2" is the response that indicates network registration status. The first number indicates the access technology being used. Because we are using 2G it should always be 0.


Possible Values for Access Technology

0 GSM

1 GSM Compact

2 UTRAN

3 GSM w/EGPRS

4 UTRAN w/HSDPA

5 UTRAN w/HSUPA

6 UTRAN w/HSDPA and HSUPA

7 E-UTRAN


The second number is the one to watch for, it indicates the registration status with the network. This is not the "activation" of your SIM or account, but rather can the device communicate with the closest tower, i.e. do you have service on your device?


Possible Values of Registration Status

0 Not registered - not connected to or searching for service

1 Registered - service found and connected

2 Not registered - not connected but searching for service

3 Registration Denied - not connected to the network, could be an account or SIM card issue

4 Unknown - out of coverage range, roaming

5 Registered Roaming - connected using another provider's network other than your own

6 Registered SMS Only - only for E-UTRAN

7 Registered SMS Only Roaming - only for E-UTRAN

8 Emergency Services Only - not applicable

9 CSFB Not Preferred - E-UTRAN only, home network

10 CSFB Not Preferred - E-UTRAN only, roaming


M2M Support Net does a great job of explaining mobile communications and AT commands in depth. If you want to dig into these details further, visit their website.



MQTT Connection Failed - TCP Port Error


If you get something like the following on your Serial Monitor output (after successful cellular connection), you may be having issues accessing the SSL ports for Adafruit IO (1883 or 8883).


AT+CIPSTART="TCP","","1883"

<--- +CME ERROR: operation not allowed

Connection failed

MQTT connection failed, resetting...


This is more than likely the result of an improper APN setting in your code. The APN setting lets your device access the internet via cellular data. For Tmobile, I used the following APN settings with success:


APN Name: "internet"

Username: ""

Password: ""


Even though there isn't a username or password, you need the empty quotations in order to feed that information into the library appropriately. I have seen many places that suggested using an APN name of "epc.t-mobile.com". It is my understanding that, while this may work with LTE networks, this did not work for me using Tmobile prepaid 2G.


There is one more possible explanation of this error. If your serial monitor output looks more like the following:


AT+CIPSTART="TCP","io.adafruit.com","1883" <--- OK <--- CONNECT OK ---> AT+CIPSTATUS <--- OK <--- STATE: CONNECT OK AT+CIPSEND=61 0x10 0x3B 0x0 0x4 0x4D 0x51 0x54 0x54 0x4 0xFFFFFFC2 0x1 0x2C 0x0 0x2 0x2D 0x20 0x0 0x9 0x73 0x75 0x6E 0x64 0x65 0x72 0x6A 0x39 0x31 0x0 0x20 0x38 0x30 0x61 0x62 0x65 0x63 0x66 0x30 0x66 0x63 0x35 0x64 0x34 0x62 0x61 0x37 0x61 0x35 0x32 0x65 0x65 0x64 0x39 0x64 0x36 0x32 0x32 0x37 0x30 0x31 0x35 0x66 <--- Connection failed -1 Retrying MQTT connection in 5 seconds...


This output is likely the result of your contract carrier (Ting, USAcellular, Cricket, etc.) blocking access to the ports that Adafruit IO uses for connection (1883 and 8883). I encountered this issue with Ting , and was happy to find the issue had resolved upon switching to Tmobile. Marco Shwartz had encountered this same issue when building his geofencing project, and his issue was also resolved by switching carriers.



Can Connect to Network but Cannot Send SMS Using FONA Test Example


If you can connect to your network but you are unable to send or receive SMS's (other than the free ones sent by your carrier) you likely have SMS blocking on your account. This could be because the SIM card was not activated properly, or because your plan does not include SMS. You can resolve this issue by contacting your carrier. You can confirm this issue by placing the SIM in your phone and trying to send yourself a text message. If you do have SMS blocked, you will get a text message from your carrier saying just that. I struggled with this issue for two days using my Tmobile SIM card. The SIM wasn't activated properly; a quick trip to the Tmobile store fixed the problem.


Additionally, if you upload the FONA test example code, and enter "s" in the serial monitor, and you are prompted to enter a number, but can't - you need to change a simple feature in the monitor. On the bottom right of the serial monitor, change the drop down to "Both NL & CR". This means that hitting the "enter" key on your keyboard both begins a new line, but also submits that line as an outgoing command. Without the proper setting selected, you are just submitting multiple lines of commands that cannot be read!



Failed to Send Disconnect Packet


The origin of this error is still a mystery to me, but luckily other members of the Adafruit community have found a work-around. If you get anything to the effect of the following in your serial monitor, and all of your libraries and board managers are up to date:


Retrying MQTT connection in 5 seconds... MQTT disconnect packet: [0xE0], [0x00], Connection failed! Unable to send disconnect packet


You need to roll your Adafruit_MQTT library back to version 15.0. I resisted doing this for the longest time, but it does quickly resolve the issue. In the Arduino IDE, go to


Tools > Include Library > Manage Libraries...


In the search bar, type in MQTT. When you see the Adafruit_MQTT library come up, select it. Select version "15.0" from the drop down menu and then click the "Install" button to the right. Save all of your work, and completely close the Arduino IDE. When you restart the Arduino IDE, recompile your code and upload it to your board. Everything should work!


If you don't fully restart the Arduino IDE you may get issues with "rate connectivity". If this is the case, restart the IDE, recompile, and the problem should be resolved.

Featured Posts
Recent Posts
Archive
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page