0

Can't set up feeds
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Can't set up feeds

by jeffrey on Mon Dec 31, 2018 9:24 pm

I am trying to set up an Uno with a Fona 808 shield to make a tracker that will let me use text messages or Adafruit IO to see the location. I can get the SMS portion to work just fine. I had it working with MQTT, but apparently that has been replaced with the new Adafruit IO library.

When I put in the code to access AdafruitIO, the sketch no longer works. I get the following in the serial monitor:
Adafruit FONA IO demo
Initializing FONA....(May take 3 seconds)
Adafruit FONA IO demo
Initializing FONA....(May take 3 seconds)

And this keep repeating ad nauseum. Something keeps the sketch from even connecting to the cellular network. I started commenting out the code and then started removing the comments one by one to see where the problem might lie. It turns out the feed setup commands cause the problem. I used the example adafruitio_04_location as my example for the commands to use to send data to AdafruitIO.

This is the section of code prior to the loop().
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_SleepyDog.h>
#include <SoftwareSerial.h>
//#include "Adafruit_FONA.h"
#include "AdafruitIO_FONA.h"

/*************************** FONA ***********************************/
#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);

const int ledPin = 13; // triggered by feed from Adafruit

#define FONA_APN       "warehouse"
#define FONA_USERNAME  ""
#define FONA_PASSWORD  ""

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "xxx"
#define AIO_KEY         "xxxxx"
AdafruitIO_FONA io(AIO_USERNAME, AIO_KEY);

/************ Global State (you don't need to change this!) ******************/

// 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 ***************************************/
AdafruitIO_Feed *location = io.feed("location");
//AdafruitIO_Feed *location = io.feed("location");
//AdafruitIO_Feed *vpct = io.feed("vpct");
//AdafruitIO_Feed *onoff = io.feed("onoff");

/*************************** Sketch Code ************************************/

float latitude, longitude, speed_kph;

// Define how long we delay sending data to Adafruit.io.
#define IO_LOOP_DELAY 30000
unsigned long lastUpdate = 0; // Just in case IO_LOOP_DELAY doesn't work out.

// this is a large buffer for replies
char replybuffer[40]; // Reduced from 250.

void setup() {
  pinMode(ledPin, OUTPUT);
 
  while (!Serial);

  // Watchdog is optional!
  Watchdog.enable(30000); // 10 seconds to connect to the cell tower.
 
  Serial.begin(115200);
  Serial.println(F("Adafruit FONA IO demo"));

  // Initialise the FONA module
  while (! FONAconnect(F(FONA_APN), F(FONA_USERNAME), F(FONA_PASSWORD))) {
    Serial.println("Retrying FONA");
  }

  Serial.println(F("Connected to Cellular!"));

  Watchdog.reset();
  delay(5000);  // wait a few seconds to stabilize connection
  Watchdog.reset();

  //fona setup
  fona.enableGPS(true);

  // IO setup
//  onoff->onMessage(handleMessage);
//  Serial.print("Connecting to Adafruit IO");
//  // wait for a connection
//  while(io.status() < AIO_CONNECTED) {
//    Serial.print(".");
//    delay(500);
//  }
//
//  // we are connected
//  Serial.println();
//  Serial.println(io.statusText());
 
}


Somehow, it seems like the one line setting up my feed is preventing the fona from connecting. There is practically no delay in the restart, either. Whatever the problem is it seems to immediately restart the sketch.

jeffrey
 
Posts: 31
Joined: Sat May 12, 2012 8:04 pm

Re: Can't set up feeds

by abachman on Wed Jan 02, 2019 6:32 pm

Hi jeffrey,


If you're able to connect over MQTT (or HTTP) with another library, then you might have better luck with that library. I don't know if you're talking about the Adafruit MQTT library (AMQTT), but it hasn't been replaced by Adafruit IO Arduino (AIOA). AIOA wraps the AMQTT library and adds some helpers to make writing certain kinds of code simpler, but AMQTT is still required for AIOA to operate, so if you're comfortable using AMQTT directly there's no problem with that.

Regarding the connection failure, which line is causing problems? Do you mean the
Code: Select all | TOGGLE FULL SIZE
AdafruitIO_Feed *location = io.feed("location");
lines or do you mean something in the setup() block?

If it's the variable initialization lines, it's possible the Uno is running out of memory and restarting.


- adam b.

abachman
 
Posts: 292
Joined: Mon Feb 01, 2010 12:48 pm

Re: Can't set up feeds

by jeffrey on Thu Jan 03, 2019 8:25 pm

It is this line that causes the problem:
Code: Select all | TOGGLE FULL SIZE
AdafruitIO_Feed *location = io.feed("location");


I have enabled all the other parts that set up AIOA, so they don't seem to be causing the problem. The minute I enable the above line, I have my problem.

I decided to try the AIOA route since the AMQTT route was also having problems. One, I could never get the subscription to work (that's another question I already have on the forum), though publishing worked just fine. The other issue I had with AMQTT was after a while it would just quit, and I would get a Not Authorized error. I would have to wait 24 hours and regenerate my key. That, too, was another question on this forum. One of the tech support guys recommended AIOA. He said something about trying to connect too often. I had modified their MQTT_fona example to fit my needs. It appears that either they changed their server side after the example was written, or they didn't plan on the example being used over a period of time (a day or two).

I'll retry AMQTT, though I suppose I will have to forgo the subscription part since I never got that to work and never got an answer from tech support.

jeffrey
 
Posts: 31
Joined: Sat May 12, 2012 8:04 pm

Please be positive and constructive with your questions and comments.