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

Adafruit IO - Compile error
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.

Adafruit IO - Compile error

by pnobels on Wed Aug 05, 2020 5:41 pm

Hi everyone,

I was trying out one of the example projects for the Adafruit IO, i.e. project 4 - Location.

However, I keep struggling with a compile error : "cannot declare variable 'io' to be of abstract type 'AdafruitIO_FONA'"

Anyone any pointers on how to resolve this?

Thanks,

P

pnobels
 
Posts: 8
Joined: Mon Aug 03, 2020 6:08 pm

Re: Adafruit IO - Compile error

by brubell on Fri Aug 14, 2020 9:48 am

Hi, what hardware are you using with the Adafruit IO project?

brubell
 
Posts: 1043
Joined: Fri Jul 17, 2015 10:33 pm

Re: Adafruit IO - Compile error

by pnobels on Wed Aug 19, 2020 4:36 am

I'm using the Fona 808 v2

I could advance by commenting out some sections around the disconnect functionality of the WIFI code part. But continue to have connection errors. (basically it's not connecting)

pnobels
 
Posts: 8
Joined: Mon Aug 03, 2020 6:08 pm

Re: Adafruit IO - Compile error

by brubell on Wed Aug 19, 2020 10:53 am

pnobels wrote:I'm using the Fona 808 v2

I could advance by commenting out some sections around the disconnect functionality of the WIFI code part. But continue to have connection errors. (basically it's not connecting)

Could you please post your full code and the config.h file below. Please make sure they're in [code] blocks and do not include your Adafruit IO Active Key or WiFi network credentials.

brubell
 
Posts: 1043
Joined: Fri Jul 17, 2015 10:33 pm

Re: Adafruit IO - Compile error

by pnobels on Thu Aug 20, 2020 6:30 am

Hi thanks for the follow up.

See below :

Location example as adjusted config.h file :
Code: Select all | TOGGLE FULL SIZE
/************************ Adafruit IO Config *******************************/

// visit io.adafruit.com if you need to create an account,
// or if you need your Adafruit IO key.
#define IO_USERNAME "your_username"
#define IO_KEY "your_key"

/******************************* WIFI **************************************/

// the AdafruitIO_WiFi client will work with the following boards:
//   - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
//   - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
//   - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
//   - Feather M0 WiFi -> https://www.adafruit.com/products/3010
//   - Feather WICED -> https://www.adafruit.com/products/3056
//   - Adafruit PyPortal -> https://www.adafruit.com/product/4116
//   - Adafruit Metro M4 Express AirLift Lite ->
//   https://www.adafruit.com/product/4000
//   - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
//   - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
//   - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264

//#define WIFI_SSID "your_ssid"
//#define WIFI_PASS "your_pass"

// uncomment the following line if you are using airlift
// #define USE_AIRLIFT

// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// comment out the following lines if you are using fona or ethernet
/*#include "AdafruitIO_WiFi.h"

#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) ||         \
    defined(ADAFRUIT_PYPORTAL)
// Configure the pins used for the ESP32 connection
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
// Don't change the names of these #define's! they match the variant ones
#define SPIWIFI SPI
#define SPIWIFI_SS 10 // Chip select pin
#define NINA_ACK 9    // a.k.a BUSY or READY pin
#define NINA_RESETN 6 // Reset pin
#define NINA_GPIO0 -1 // Not connected
#endif
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
                   NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
#else
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif
/******************************* FONA **************************************/

// the AdafruitIO_FONA client will work with the following boards:
//   - Feather 32u4 FONA -> https://www.adafruit.com/product/3027

// uncomment the following two lines for 32u4 FONA,
// and comment out the AdafruitIO_WiFi client in the WIFI section
#include "AdafruitIO_FONA.h"
AdafruitIO_FONA io(IO_USERNAME, IO_KEY);

/**************************** ETHERNET ************************************/

// the AdafruitIO_Ethernet client will work with the following boards:
//   - Ethernet FeatherWing -> https://www.adafruit.com/products/3201

// uncomment the following two lines for ethernet,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_Ethernet.h"
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);



I didn't change anything in the location example (as not relevant).

WHen compiling I got the error as described previously - cannot declare variable 'io' to be of abstract type 'AdafruitIO_FONA'. WHen I looked a bit deeper in the error text of the compiler, it described that there was a problem with "virtual void disconnect".

So I dived into the AdafruitIO.H and AdafruitIO.cpp files and found the disconnect functions mostly relating to WIFI. Since I'm using the fona and not wifi, I commented these out. See code below

ArduinoIO.H:
Code: Select all | TOGGLE FULL SIZE
/*!
 * @file AdafruitIO.h
 *
 * This is part of the Adafruit IO library for the Arduino platform.
 *
 * Adafruit invests time and resources providing this open source code,
 * please support Adafruit and open-source hardware by purchasing
 * products from Adafruit!
 *
 * Written by Tony DiCola, Todd Treece for Adafruit Industries
 *
 * BSD license, all text here must be included in any redistribution.
 *
 */

#ifndef ADAFRUITIO_H
#define ADAFRUITIO_H

#include "AdafruitIO_Dashboard.h"
#include "AdafruitIO_Data.h"
#include "AdafruitIO_Definitions.h"
#include "AdafruitIO_Feed.h"
#include "AdafruitIO_Group.h"
#include "AdafruitIO_Time.h"
#include "Adafruit_MQTT.h"
#include "Arduino.h"
#include "ArduinoHttpClient.h"
#include "util/AdafruitIO_Board.h"

#ifndef ADAFRUIT_MQTT_VERSION_MAJOR
#error                                                                         \
    "This sketch requires Adafruit MQTT Library v1.0.0 or higher. Please install or upgrade using the Library Manager."
#endif

#if ADAFRUIT_MQTT_VERSION_MAJOR == 1 && ADAFRUIT_MQTT_VERSION_MINOR < 0
#error                                                                         \
    "This sketch requires Adafruit MQTT Library v1.0.0 or higher. Please install or upgrade using the Library Manager."
#endif

/**************************************************************************/
/*!
    @brief  Class for interacting with Adafruit IO
*/
/**************************************************************************/
class AdafruitIO {
  /**
   * @brief AdafruitIO_Feed addition.
   * @relates AdafruitIO_Feed
   */
  friend class AdafruitIO_Feed;

  /**
   * @brief AdafruitIO_Group addition.
   * @relates AdafruitIO_Group
   */
  friend class AdafruitIO_Group;

  /**
   * @brief AdafruitIO_Dashboard addition.
   * @relates AdafruitIO_Dashboard
   */
  friend class AdafruitIO_Dashboard;

  /**
   * @brief AdafruitIO_Block addition.
   * @relates AdafruitIO_Block
   */
  friend class AdafruitIO_Block;

  /**
   * @brief AdafruitIO_Time addition.
   * @relates AdafruitIO_Time
   */
  friend class AdafruitIO_Time;

public:
  AdafruitIO(const char *user, const char *key);
  virtual ~AdafruitIO();

  void connect();
 // void wifi_disconnect(); commented out for fona use
  aio_status_t run(uint16_t busywait_ms = 0, bool fail_fast = false);

  AdafruitIO_Feed *feed(const char *name);
  AdafruitIO_Feed *feed(const char *name, const char *owner);
  AdafruitIO_Group *group(const char *name);
  AdafruitIO_Dashboard *dashboard(const char *name);
  AdafruitIO_Time *time(aio_time_format_t format);

  const __FlashStringHelper *statusText();

  aio_status_t status();
  /********************************************************************/
  /*!
  @brief   Returns network module status.
  @return  0
  */
  /*******************************************************************/
  virtual aio_status_t networkStatus() = 0;

  /********************************************************************/
  /*!
  @brief  Returns MQTT connection status.
  */
  /*******************************************************************/
  aio_status_t mqttStatus(bool fail_fast = false);

  char *boardID();
  const char *boardType();
  char *version();
  char *userAgent();

  /********************************************************************/
  /*!
  @brief   Returns the Adafruit IO network module connection type.
  @return  0
  */
  /*******************************************************************/
  virtual const char *connectionType() = 0;

protected:
  /********************************************************************/
  /*!
  @brief   Establishes a connection with the Adafruit IO MQTT broker.
  @return  0
  */
  /*******************************************************************/
  virtual void _connect() = 0;

  /******************************************************/
  /*!
  @brief   Disconnects from the Adafruit IO MQTT broker.
  @return  0
  */
  /*****************************************************/
  //virtual void _disconnect() = 0; comment out for fona

  aio_status_t _status = AIO_IDLE; /*!< Adafruit IO Connection Status */
  uint32_t _last_ping =
      0; /*!< Previous time when client pinged Adafruit IO, in milliseconds */
  uint32_t _last_mqtt_connect = 0; /*!< Previous time when client connected to
                                      Adafruit IO, in milliseconds */

  Adafruit_MQTT *_mqtt; /*!< Reference to Adafruit_MQTT, _mqtt. */
  HttpClient *_http;    /*!< Reference to HTTPClient, _http */

  char _version[10]; /*!< Adafruit IO Arduino library version */

  const char *_host = "io.adafruit.com"; /*!< Adafruit IO URL */
  uint16_t _mqtt_port = 8883;            /*!< Adafruit IO MQTT SSL port */
  uint16_t _mqtt_eth_port =
      1883; /*!< Adafruit IO MQTT insecure port, used by ethernet clients. */
  uint16_t _http_port = 443; /*!< Adafruit IO HTTP SSL port */

  uint16_t _packetread_timeout; /*!< Maximum amount of time to wait before
                                   processing packets. */

  const char *_username; /*!< Adafruit IO Username. */
  const char *_key;      /*!< Adafruit IO Key. */

  char *_err_topic;      /*!< Adafruit IO MQTT error message topic. */
  char *_throttle_topic; /*!< Adafruit IO MQTT throttle message topic. */
  char *_user_agent;     /*!< Identifies the Adafruit IO client. */

  Adafruit_MQTT_Subscribe
      *_err_sub; /*!< Subscription to Adafruit IO Error topic. */
  Adafruit_MQTT_Subscribe
      *_throttle_sub; /*!< Subscription to Adafruit IO Throttle topic. */

private:
  void _init();
};

#endif // ADAFRUITIO_H


and the .cpp file :
Code: Select all | TOGGLE FULL SIZE
/*!
 * @file AdafruitIO.cpp
 *
 * @mainpage Adafruit IO Arduino Client Library
 *
 * @section intro_sec Introduction
 *
 * This is the documentation for the Adafruit IO Arduino library. This library
 * provides a simple device independent interface for interacting with Adafruit
 * IO using Arduino. It allows you to switch between WiFi (ESP8266, ESP32,
 * AirLift, WINC1500, & WICED), Cellular (32u4 FONA), and Ethernet (Ethernet
 * FeatherWing)
 *
 * Adafruit invests time and resources providing this open source code,
 * please support Adafruit and open-source hardware by purchasing
 * products from Adafruit!
 *
 * @section dependencies Dependencies
 *
 * This library depends on <a
 * href="https://github.com/arduino-libraries/ArduinoHttpClient">
 * ArduinoHTTPClient</a> and <a
 * href="https://github.com/adafruit/Adafruit_MQTT_Library"> Adafruit MQTT
 * Library</a> being present on your system. Please make sure you have installed
 * the latest version before using this library.
 *
 * @section author Author
 *
 * Written by Tony DiCola, Todd Treece for Adafruit Industries
 *
 * @section license License
 *
 * BSD license, all text here must be included in any redistribution.
 *
 */
#include "AdafruitIO.h"

/**************************************************************************/
/*!
    @brief    Instantiate the AIO object.
    @param    user
              A pointer to a constant AIO user name.
    @param    key
              A pointer to a constant key for the user name.
*/
/**************************************************************************/
AdafruitIO::AdafruitIO(const char *user, const char *key) {
  _mqtt = 0;
  _http = 0;
  _username = user;
  _key = key;
  _err_topic = 0;
  _throttle_topic = 0;
  _err_sub = 0;
  _throttle_sub = 0;
  _packetread_timeout = 100;
  _user_agent = 0;

  _init();
}

/**************************************************************************/
/*!
    @brief    Initialize the AIO object.
*/
/**************************************************************************/
void AdafruitIO::_init() {

  // we have never pinged, so set last ping to now
  _last_ping = millis();

  // dynamically allocate memory for err topic
  _err_topic = (char *)malloc(
      sizeof(char) * (strlen(_username) + strlen(AIO_ERROR_TOPIC) + 1));

  if (_err_topic) {

    // build error topic
    strcpy(_err_topic, _username);
    strcat(_err_topic, AIO_ERROR_TOPIC);

  } else {

    // malloc failed
    _err_topic = 0;
  }

  // dynamically allocate memory for throttle topic
  _throttle_topic = (char *)malloc(
      sizeof(char) * (strlen(_username) + strlen(AIO_THROTTLE_TOPIC) + 1));

  if (_throttle_topic) {

    // build throttle topic
    strcpy(_throttle_topic, _username);
    strcat(_throttle_topic, AIO_THROTTLE_TOPIC);

  } else {

    // malloc failed
    _throttle_topic = 0;
  }
}

/**************************************************************************/
/*!
    @brief    Destructor to end the AIO object.
*/
/**************************************************************************/
AdafruitIO::~AdafruitIO() {
  if (_err_topic)
    free(_err_topic);

  if (_throttle_topic)
    free(_throttle_topic);

  if (_err_sub)
    delete _err_sub;

  if (_throttle_sub)
    delete _throttle_sub;
}

/**************************************************************************/
/*!
    @brief    Prints errors
    @param    err
              An error string to print.
    @param    len
              The length of the error string.
*/
/**************************************************************************/
void errorCallback(char *err, uint16_t len) {
  AIO_ERROR_PRINTLN();
  AIO_ERROR_PRINT("ERROR: ");
  AIO_ERROR_PRINTLN(err);
  AIO_ERROR_PRINTLN();
}

/**************************************************************************/
/*!
    @brief    Connects to AIO, setting up using parameters set when the
              class is instantiated.
*/
/**************************************************************************/
void AdafruitIO::connect() {

  AIO_DEBUG_PRINTLN("AdafruitIO::connect()");

  _last_mqtt_connect = 0; // need to start over fresh
  _status = AIO_IDLE;
  _last_ping = 0;

  if (_err_sub) {
    // setup error sub
    _err_sub = new Adafruit_MQTT_Subscribe(_mqtt, _err_topic);
    _mqtt->subscribe(_err_sub);
    _err_sub->setCallback(errorCallback);
  }

  if (_throttle_sub) {
    // setup throttle sub
    _throttle_sub = new Adafruit_MQTT_Subscribe(_mqtt, _throttle_topic);
    _mqtt->subscribe(_throttle_sub);
    _throttle_sub->setCallback(errorCallback);
  }

  _connect();
}

/**************************************************************************/
/*!
    @brief    Disconnects from WiFi. - COMMENTED OUT FOR FONA
*/
/**************************************************************************/
/*void AdafruitIO::wifi_disconnect() {

  AIO_DEBUG_PRINTLN("AdafruitIO::wifi_disconnect()");

  _disconnect();
}

/**************************************************************************/
/*!
    @brief    Create a new AIO feed.
    @param    name
              The AIO name of the feed.
    @return   A pointer to the feed.
*/
/**************************************************************************/
AdafruitIO_Feed *AdafruitIO::feed(const char *name) {
  return new AdafruitIO_Feed(this, name);
}

/**************************************************************************/
/*!
    @brief    Create a new AIO feed.
    @param    name
              The AIO name of the feed.
    @param    owner
              The AIO name of the user that owns the feed, if not the current
   user.
    @return   A pointer to the feed.
*/
/**************************************************************************/
AdafruitIO_Feed *AdafruitIO::feed(const char *name, const char *owner) {
  return new AdafruitIO_Feed(this, name, owner);
}

/**************************************************************************/
/*!
    @brief    Create a new AIO time.
    @param    format
              A format specifier.
    @return   A pointer to the time.
*/
/**************************************************************************/
AdafruitIO_Time *AdafruitIO::time(aio_time_format_t format) {
  return new AdafruitIO_Time(this, format);
}

/**************************************************************************/
/*!
    @brief    Create a new AIO group.
    @param    name
              The AIO name of the group.
    @return   A pointer to the group.
*/
/**************************************************************************/
AdafruitIO_Group *AdafruitIO::group(const char *name) {
  return new AdafruitIO_Group(this, name);
}

/**************************************************************************/
/*!
    @brief    Create a new AIO dashboard.
    @param    name
              The AIO name of the dashboard.
    @return   A pointer to the dashboard.
*/
/**************************************************************************/
AdafruitIO_Dashboard *AdafruitIO::dashboard(const char *name) {
  return new AdafruitIO_Dashboard(this, name);
}

/**************************************************************************/
/*!
    @brief    Provide status explanation strings.
    @return   A pointer to the status string, _status. _status is the AIO status
   value
*/
/**************************************************************************/
const __FlashStringHelper *AdafruitIO::statusText() {
  switch (_status) {

  // CONNECTING
  case AIO_IDLE:
    return F("Idle. Waiting for connect to be called...");
  case AIO_NET_DISCONNECTED:
    return F("Network disconnected.");
  case AIO_DISCONNECTED:
    return F("Disconnected from Adafruit IO.");

  // FAILURE
  case AIO_NET_CONNECT_FAILED:
    return F("Network connection failed.");
  case AIO_CONNECT_FAILED:
    return F("Adafruit IO connection failed.");
  case AIO_FINGERPRINT_INVALID:
    return F("Adafruit IO SSL fingerprint verification failed.");
  case AIO_AUTH_FAILED:
    return F("Adafruit IO authentication failed.");

  // SUCCESS
  case AIO_NET_CONNECTED:
    return F("Network connected.");
  case AIO_CONNECTED:
    return F("Adafruit IO connected.");
  case AIO_CONNECTED_INSECURE:
    return F("Adafruit IO connected. **THIS CONNECTION IS INSECURE** SSL/TLS "
             "not supported for this platform.");
  case AIO_FINGERPRINT_UNSUPPORTED:
    return F("Adafruit IO connected over SSL/TLS. Fingerprint verification "
             "unsupported.");
  case AIO_FINGERPRINT_VALID:
    return F("Adafruit IO connected over SSL/TLS. Fingerprint valid.");

  default:
    return F("Unknown status code");
  }
}

/**************************************************************************/
/*!
    @brief    Must be called frequently to keep AIO connections alive. When
              called with no arguments run() will try to repair MQTT and WiFi
              connections before returning. To avoid potentially long timeout
              delays, sketches can use the busywait_ms and fail_fast arguments
              to return an imperfect status quickly. The calling sketch will
              then need to respond appropriately to that status.
    @param    busywait_ms
              The packet read timeout, optional.
    @param    fail_fast
              Set true to skip retries and return with status immediately,
   optional.
    @return   AIO status value
*/
/**************************************************************************/
aio_status_t AdafruitIO::run(uint16_t busywait_ms, bool fail_fast) {
  uint32_t timeStart = millis();
  if (status() < AIO_NET_CONNECTED) { // If we aren't network connected...
    if (fail_fast)
      return status(); // return status and fail quickly
    else {             // or try to reconnect from the start
      AIO_ERROR_PRINT("run() connection failed -- retrying");
      unsigned long started = millis();
      connect();
      // wait for a full AIO connection then carry on
      while (status() < AIO_CONNECTED) {
        // or return an error if the reconnection times out
        if (millis() - started > AIO_NET_CONNECTION_TIMEOUT)
          return status();
        delay(500);
      }
    }
  }

  // loop until we have a connection
  // mqttStatus() will try to reconnect before returning
  while (mqttStatus(fail_fast) != AIO_CONNECTED &&
         millis() - timeStart < AIO_MQTT_CONNECTION_TIMEOUT) {
  }
  if (mqttStatus(fail_fast) != AIO_CONNECTED)
    return status();

  if (busywait_ms > 0)
    _packetread_timeout = busywait_ms;

  _mqtt->processPackets(_packetread_timeout);

  // ping to keep connection alive if needed
  if (millis() > (_last_ping + AIO_PING_INTERVAL)) {
    _mqtt->ping();
    _last_ping = millis();
  }
  return status();
}

/**************************************************************************/
/*!
    @brief    Status check.
    @return   An AIO status value. Lower values represent poorer connection
              status.
*/
/**************************************************************************/
aio_status_t AdafruitIO::status() {
  aio_status_t net_status = networkStatus();

  // if we aren't connected, return network status
  if (net_status != AIO_NET_CONNECTED) {
    _status = net_status;
    return _status;
  }

  // check mqtt status and return
  _status = mqttStatus();
  return _status;
}

/**************************************************************************/
/*!
    @brief    Identify the board.
    @return   A board ID
*/
/**************************************************************************/
char *AdafruitIO::boardID() { return AdafruitIO_Board::id(); }

/**************************************************************************/
/*!
    @brief    Identify the board type.
    @return   A board type
*/
/**************************************************************************/
const char *AdafruitIO::boardType() { return AdafruitIO_Board::type(); }

/**************************************************************************/
/*!
    @brief    Identify the software version.
    @return   A pointer to a version number string.
*/
/**************************************************************************/
char *AdafruitIO::version() {
  sprintf(_version, "%d.%d.%d", ADAFRUITIO_VERSION_MAJOR,
          ADAFRUITIO_VERSION_MINOR, ADAFRUITIO_VERSION_PATCH);
  return _version;
}

/**************************************************************************/
/*!
    @brief    Identify the user agent.
    @return   A pointer to a user agent string.
*/
/**************************************************************************/
char *AdafruitIO::userAgent() {
  if (!_user_agent) {
    _user_agent =
        (char *)malloc(sizeof(char) * (strlen(version()) + strlen(boardType()) +
                                       strlen(connectionType()) + 24));
    strcpy(_user_agent, "AdafruitIO-Arduino/");
    strcat(_user_agent, version());
    strcat(_user_agent, " (");
    strcat(_user_agent, boardType());
    strcat(_user_agent, "-");
    strcat(_user_agent, connectionType());
    strcat(_user_agent, ")");
  }
  return _user_agent;
}

/**************************************************************************/
/*!
    @brief    Checks connection status with Adafruit IO's MQTT broker.
    @param    fail_fast
              Set true to skip retries and return with status immediately.
    @return   True if connected, otherwise False.
*/
/**************************************************************************/
aio_status_t AdafruitIO::mqttStatus(bool fail_fast) {
  // if the connection failed,
  // return so we don't hammer IO
  if (_status == AIO_CONNECT_FAILED) {
    AIO_ERROR_PRINT("mqttStatus() failed to connect");
    AIO_ERROR_PRINTLN(_mqtt->connectErrorString(_status));
    return _status;
  }

  if (_mqtt->connected())
    return AIO_CONNECTED;

  // prevent fast reconnect attempts, except for the first time through
  if (_last_mqtt_connect == 0 ||
      millis() - _last_mqtt_connect > AIO_THROTTLE_RECONNECT_INTERVAL) {
    _last_mqtt_connect = millis();
    switch (_mqtt->connect(_username, _key)) {
    case 0:
      return AIO_CONNECTED;
    case 1: // invalid mqtt protocol
    case 2: // client id rejected
    case 4: // malformed user/pass
    case 5: // unauthorized
      return AIO_CONNECT_FAILED;
    case 3: // mqtt service unavailable
    case 6: // throttled
    case 7: // banned -> all MQTT bans are temporary, so eventual retry is
            // permitted
      // delay to prevent fast reconnects and fast returns (backward
      // compatibility)
      if (!fail_fast)
        delay(AIO_THROTTLE_RECONNECT_INTERVAL);
      return AIO_DISCONNECTED;
    default:
      return AIO_DISCONNECTED;
    }
  }
  return AIO_DISCONNECTED;
}


so far that allows me to compile the file... But when I upload, I get the following in the serial monitor :

Connecting to Adafruit IOAttempting to open comm with ATs
---> AT
<---

---> AT
<---
---> AT
<---
Timeout: No response to AT... last ditch attempt.
---> AT
<---
---> AT
<---
---> AT
<---
---> ATE0
<---
---> ATE0
<---
......................


I was wondering... shouldn't there be any code to unlock the SIM and enable gprs to be able to send the data?

What I'm basically trying to achieve is to send data from my LIS3DH sensor and GPS to Adafruit IO while biking...

I'm pretty noob in this thing, so really struggling :-S

pnobels
 
Posts: 8
Joined: Mon Aug 03, 2020 6:08 pm

Re: Adafruit IO - Compile error

by brubell on Mon Aug 24, 2020 10:51 am

Are you able to so far that allows me to compile the file... But when I upload, I get the following in the serial monitor :


Ok, this may be a wiring/battery/fona issue.

Could you load up the arduino test: https://learn.adafruit.com/adafruit-fon ... duino-test

and then run this test to verify if the SIM card is registered with the network: https://learn.adafruit.com/adafruit-fon ... twork-test

brubell
 
Posts: 1043
Joined: Fri Jul 17, 2015 10:33 pm

Re: Adafruit IO - Compile error

by pnobels on Mon Aug 24, 2020 11:25 am

Hi

Yes I have been able to connect to network etc using fona test (with the one letter commands over serial monitor)

But I always need to unlock my pin and activate gprs before I can connect

pnobels
 
Posts: 8
Joined: Mon Aug 03, 2020 6:08 pm

Re: Adafruit IO - Compile error

by brubell on Wed Aug 26, 2020 11:51 am

GPRS will need to be activated before connecting to the cellular data network.

Are you able to connect to Adafruit IO using this sketch: https://github.com/adafruit/Adafruit_MQ ... t_fona.ino?

brubell
 
Posts: 1043
Joined: Fri Jul 17, 2015 10:33 pm

Re: Adafruit IO - Compile error

by pnobels on Wed Aug 26, 2020 6:01 pm

OK I got the MQTT working after making the following adjustments :

- First I had the same issue as described above (the endless AT--> flying through)... Then I noticed that the pins that are defined are the default pins for Fona Feather. So I adjusted the pins to the Fona 808 pins (based on the fonatest library)

Code: Select all | TOGGLE FULL SIZE
/*************************** FONA Pins ***********************************/

// Default pins for Feather 32u4 FONA - ADJUSTED TO FONA 808
#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);


That got me the following result in my serial monitor :

Initializing FONA....(May take 3 seconds)
Attempting to open comm with ATs
---> AT
<---
---> AT
<---
---> AT
<--- ⸮
---> AT
<--- AT
---> ATE0
<--- ATE0
---> ATE0
<--- OK
---> AT+CVHU=0
<--- HHTHHhiU9⸮ 1
---> ATI
<--- SIM808 R14.18

OK

---> AT+CPMS="SM","SM","SM"
<--- +CPIN: SIM PIN
FONA is OK
Checking for network...
---> AT+CREG?
<--- +CREG: 0,2
---> AT+CREG?
<--- +CREG: 0,2
---> AT+CREG?
<--- +CREG: 0,2
---> AT+CREG?
<--- +CREG: 0,2
---> AT+CREG?


So then I tried to build in the unlock SIM command by adding the PIN hardcoded in the fonahelper.cpp :

Code: Select all | TOGGLE FULL SIZE
//added to unlock sim
delay (2000);
char PIN [4]={####}; //replace # by PIN code for SIM
fona.unlockSIM(PIN);

delay (5000); //waiting time to ensure connection*/


And I adjusted the Adafruit_FONA.cpp as follows :

Code: Select all | TOGGLE FULL SIZE
********* SIM ***********************************************************/

/**
 * @brief Unlock the sim with a provided PIN
 *
 * @param pin Pointer to a buffer with the PIN to use to unlock the SIM
 * @return uint8_t
 */
uint8_t Adafruit_FONA::unlockSIM(char *pin) {
  char sendbuff[14] = "AT+CPIN=####"; //replace # by PIN code for SIM
 /* sendbuff[8] = pin[0];
  sendbuff[9] = pin[1];
  sendbuff[10] = pin[2];
  sendbuff[11] = pin[3];
  */sendbuff[12] = '\0';

  return sendCheckReply(sendbuff, ok_reply);
}


Probably far from optimal in terms of code structure, but I still have a lot of ground to discover in C++, and most importantly, it seems to do the trick now... I have now a feed photocell in Adafruit IO dashboard which is adding data...


So I guess I would now need to adjust the location example with the same pieces of code?

pnobels
 
Posts: 8
Joined: Mon Aug 03, 2020 6:08 pm

Re: Adafruit IO - Compile error

by brubell on Fri Aug 28, 2020 10:31 am

So I guess I would now need to adjust the location example with the same pieces of code?


Yep! Great job getting it working.

Would you be interested in adding the Adafruit_Fona::unlockSim() function to the Adafruit IO Arduino library via a pull request? I'll be able to make suggestions to your c++ code and we can merge this useful function into the library for others to use.

brubell
 
Posts: 1043
Joined: Fri Jul 17, 2015 10:33 pm

Re: Adafruit IO - Compile error

by pnobels on Fri Aug 28, 2020 1:07 pm

would be happy to... but would need a bit of help on which steps to take to get there... currently also still using the MQTT library, not yet the example ones I started of with

pnobels
 
Posts: 8
Joined: Mon Aug 03, 2020 6:08 pm

Re: Adafruit IO - Compile error

by brubell on Mon Sep 07, 2020 10:33 am

pnobels wrote:would be happy to... but would need a bit of help on which steps to take to get there... currently also still using the MQTT library, not yet the example ones I started of with


I'd try adding it here:

https://github.com/adafruit/Adafruit_IO ... tIO_FONA.h

brubell
 
Posts: 1043
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.