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

Fona 32u4 multiple_feeds
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.

Fona 32u4 multiple_feeds

by blang on Tue Sep 01, 2020 10:30 am

Hi!

I want to build a GSM-based weather station, but I am unable to get the adafruio_03_multiple_feeds example to run on the Feather Fona 32u4. Commenting out all feeds but one works, as soon as I add a second feed the Feather seems to hang, I don't get any serial console output any more (the COM-port vanishes in the device manager and windows does the ding-dong-sound), also flashing a new sketch is only possible with double clicking the reset button and using DFU mode. I also tried other examples from the Adafruit IO library with the same behavior - single feed ok, 1+N feeds Feather hangs.

Can any body else verify this behavior and/or offer any possible solution?

blang
 
Posts: 4
Joined: Fri Oct 18, 2019 8:22 am

Re: Fona 32u4 multiple_feeds

by brubell on Mon Sep 07, 2020 9:58 am

Does the same USB disconnection occur with this sketch, too? Similar sketch - uses two feeds

https://github.com/adafruit/Adafruit_MQ ... t_fona.ino

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

Re: Fona 32u4 multiple_feeds

by blang on Wed Sep 09, 2020 10:14 am

The mqtt-example does compile and run, no issues with the serial output, but it seems I don't get any network connection with it, so I never ever get to publish/subscribe

15:04:36.121 -> Adafruit FONA MQTT demo
15:04:41.132 -> Initializing FONA....(May take 3 seconds)
15:04:41.234 -> Attempting to open comm with ATs
15:04:41.301 -> ---> AT
15:04:41.805 -> <---
15:04:41.872 -> ---> AT
15:04:42.383 -> <---
15:04:42.954 -> ---> AT
15:04:43.257 -> <--- AT
15:04:43.291 -> ---> AT
15:04:43.325 -> <--- AT
15:04:43.393 -> ---> ATE0
15:04:43.428 -> <--- ATE0
15:04:43.565 -> ---> ATE0
15:04:43.598 -> <--- OK
15:04:43.632 -> ---> AT+CVHU=0
15:04:43.701 -> <--- OK
15:04:43.835 -> ---> ATI
15:04:44.410 -> <--- SIM800 R13.08
15:04:44.410 ->
15:04:44.410 -> OK
15:04:44.410 ->
15:04:44.410 -> RDY
15:04:44.410 ->
15:04:44.410 -> +CFUN: 1
15:04:44.410 ->
15:04:44.410 -> ---> AT+GMM
15:04:45.020 -> <--- SIMCOM_SIM800H
15:04:45.020 ->
15:04:45.020 -> OK
15:04:45.020 ->
15:04:45.020 -> +CPIN: READY
15:04:45.020 ->
15:04:45.054 -> ---> AT+CPMS="SM","SM","SM"
15:04:45.122 -> <--- ERROR
15:04:45.156 -> FONA is OK
15:04:45.156 -> Checking for network...
15:04:45.224 -> ---> AT+CREG?
15:04:45.291 -> <--- +CREG: 0,2
15:04:45.831 -> ---> AT+CREG?
15:04:45.900 -> <--- +CREG: 0,2
15:04:46.476 -> ---> AT+CREG?
15:04:46.510 -> <--- +CREG: 0,2
15:04:47.086 -> ---> AT+CREG?
15:04:47.154 -> <--- +CREG: 0,2
15:04:47.695 -> ---> AT+CREG?
15:04:47.763 -> <--- +CREG: 0,2
15:04:48.306 -> ---> AT+CREG?
15:04:48.374 -> <--- +CREG: 0,2
15:04:48.914 -> ---> AT+CREG?
15:04:48.984 -> <--- +CREG: 0,2
15:04:49.527 -> ---> AT+CREG?
15:04:49.596 -> <--- +CREG: 0,2
15:04:50.169 -> ---> AT+CREG?
15:04:50.203 -> <--- +CREG: 0,2
15:04:50.778 -> ---> AT+CREG?
15:04:50.846 -> <--- +CREG: 0,2
15:04:51.388 -> ---> AT+CREG?
15:04:51.455 -> <--- +CREG: 0,2
15:04:51.998 -> ---> AT+CREG?
15:04:52.064 -> <--- +CREG: 0,2
15:04:52.604 -> ---> AT+CREG?
15:04:52.674 -> <--- +CREG: 0,5
15:04:53.250 -> ---> AT+CREG?
15:04:53.284 -> <--- +CREG: 0,5
15:04:53.862 -> ---> AT+CREG?
15:04:53.896 -> <--- +CREG: 0,5
15:04:54.468 -> ---> AT+CREG?
15:04:54.536 -> <--- +CREG: 0,5
15:04:55.081 -> ---> AT+CREG?
15:04:55.150 -> <--- +CREG: 0,5
15:04:55.691 -> ---> AT+CREG?
15:04:55.759 -> <--- +CREG: 0,5
15:04:56.306 -> ---> AT+CREG?
15:04:56.374 -> <--- +CREG: 0,5
15:04:56.918 -> ---> AT+CREG?
15:04:56.986 -> <--- +CREG: 0,5
15:04:57.561 -> ---> AT+CREG?
15:04:57.594 -> <--- +CREG: 0,5
15:04:58.172 -> ---> AT+CREG?
15:04:58.239 -> <--- +CREG: 0,5
15:04:58.781 -> ---> AT+CREG?

The Fona-Test example https://github.com/adafruit/Adafruit_FO ... NAtest.ino works

blang
 
Posts: 4
Joined: Fri Oct 18, 2019 8:22 am

Re: Fona 32u4 multiple_feeds

by brubell on Wed Sep 09, 2020 10:41 am

The mqtt-example does compile and run, no issues with the serial output, but it seems I don't get any network connection with it, so I never ever get to publish/subscribe


You may want to check with your carrier if data is enabled for that SIM card.

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

Re: Fona 32u4 multiple_feeds

by blang on Fri Sep 11, 2020 10:14 am

Yep, another SIM card did the trick for MQTT with multiple feeds - I had a free 20MB a day SIM which seems to have gotten deactivated after not using it for more than a year.

I am pulling the BME280 data and anemometer/wind vane via i2c from a Arduino Pro Mini as I might not have enough IOs on the FONA

Code: Select all | TOGGLE FULL SIZE
/***************************************************
  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.
  MIT license, all text above must be included in any redistribution
 ****************************************************/
#include <Adafruit_SleepyDog.h>
#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_FONA.h"
#include <EasyTransferI2C.h>

//create object
EasyTransferI2C ET;

struct RECEIVE_DATA_STRUCTURE {
  //put your variable definitions here for the data you want to send
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  float temperature;
  float pressure;
  float humidity;
  float windspeed;
  int16_t winddirection;
};

//give a name to the group of data
RECEIVE_DATA_STRUCTURE weatherdata;
//define slave i2c address
#define I2C_SLAVE_ADDRESS 9

float barometer_val = 0;
float batvoltage_val = 0;                                     // Floating values to be transmitted via MQTT
float humidity_val = 0;
float solarvoltage_val = 0;
float temperature_val = 0;
int winddirection_val = 0;
float windspeed_val = 0;
uint8_t precision = 2;

/*************************** FONA Pins ***********************************/

// Default pins for Feather 32u4 FONA
#define FONA_RX  9
#define FONA_TX  8
#define FONA_RST 4
#define FONA_RI  7
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

/************************* WiFi Access Point *********************************/

// 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       ""
#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         "xxx"

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

// Setup the FONA MQTT class by passing in the FONA class and MQTT server and login details.
Adafruit_MQTT_FONA mqtt(&fona, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

// 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 ***************************************/

Adafruit_MQTT_Publish barometer_feed = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/barometer");
Adafruit_MQTT_Publish batvoltage_feed = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/batvoltage");
Adafruit_MQTT_Publish humidity_feed = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/humidity");
Adafruit_MQTT_Publish solarvoltage_feed = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/solarvoltage");
Adafruit_MQTT_Publish temperature_feed = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/temperature");
Adafruit_MQTT_Publish winddirection_feed = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/winddirection");
Adafruit_MQTT_Publish windspeed_feed = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/windspeed");

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

// probe pins
int sensorPowerPin = 0;                            // GPIO pin that powers ProMini before measurements

int batteryVoltagePin = A0;                             // ADC pin that receives battery voltage data
int solarVoltagePin = A1;                             // ADC pin that receives solar voltage data

// How many transmission failures in a row we're willing to be ok with before reset
uint8_t txfailures = 0;
#define MAXTXFAILURES 3

void receive(int numBytes) {}

// Read temperature from temperature probe
void read_sensors(void) {
  float vbat_out = 0;                                // Voltage output from battery
  float vsolar_out = 0;                             // Voltage output from solar

  for (int i = 0; i < 20; i++) {
    delay(1);                                     // Wait 1 ms for sensor to stabilize
    vbat_out += analogRead(0);                       // Read the input pin and add to multiple measurement aggregate
  }
  vbat_out /= 20;                                    // Divide by # of measurements to find average value. Done to smooth noisy measurements

  for (int i = 0; i < 20; i++) {
    delay(1);                                     // Wait 1 ms for sensor to stabilize
    vsolar_out += analogRead(1);                       // Read the input pin and add to multiple measurement aggregate
  }
  vsolar_out /= 20;                                    // Divide by # of measurements to find average value. Done to smooth noisy measurements

  vbat_out *= .0064;
  vsolar_out *= .0032;                                 // Convert ADC points to volts (3.3/1023 because AREF is set to 3.3V)

  batvoltage_val = vbat_out;
  solarvoltage_val = vsolar_out;

  digitalWrite(sensorPowerPin, HIGH);             // Power-on sensor

  delay(5000);

  //check and see if a data packet has come in.
  if (ET.receiveData()) {
    //this is how you access the variables. [name of the group].[variable name]
    //since we have data:
    Serial.println();
    Serial.print("Pressure = ");
    Serial.print(weatherdata.pressure);
    Serial.println(" mbar");
    barometer_val = weatherdata.pressure;

    Serial.print("Battery = ");
    Serial.print(batvoltage_val);
    Serial.println(" V");

    Serial.print("Humidity = ");
    Serial.print(weatherdata.humidity);
    Serial.println(" %");
    humidity_val = weatherdata.humidity;

    Serial.print("Solar = ");
    Serial.print(solarvoltage_val);
    Serial.println(" V");

    Serial.print("Temperature = ");
    Serial.print(weatherdata.temperature);
    Serial.println(" *C");
    temperature_val = weatherdata.temperature;

    Serial.print("Winddirection = ");
    Serial.print(weatherdata.winddirection);
    Serial.println(" Degrees");
    winddirection_val = weatherdata.winddirection;

    Serial.print("Windspeed = ");
    Serial.print(weatherdata.windspeed);
    Serial.println(" m/s");
    windspeed_val = weatherdata.windspeed;
    Serial.println();
    digitalWrite(sensorPowerPin, LOW);              // Power-off sensor
    Watchdog.reset();
  }
}

void setup() {
  while (!Serial);

  // Watchdog is optional!
  //Watchdog.enable(8000);

  Serial.begin(115200);

  Serial.println(F("Adafruit FONA MQTT weather"));

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

  pinMode(sensorPowerPin, OUTPUT);

  Wire.begin(I2C_SLAVE_ADDRESS);
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ET.begin(details(weatherdata), &Wire);
  //define handler function on receiving data
  Wire.onReceive(receive);

  // 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();

  //digitalWrite(batteryVoltagePin, LOW);           // Set pull-up on analog input pin
  //digitalWrite(solarVoltagePin, LOW);           // Set pull-up on analog input pin
}

void loop() {

  barometer_val = 0;
  batvoltage_val = 0;                                     // Floating values to be transmitted via MQTT
  humidity_val = 0;
  solarvoltage_val = 0;
  temperature_val = 0;
  winddirection_val = 0;
  windspeed_val = 0;

  // Make sure to reset watchdog every loop iteration!
  Watchdog.reset();

  // Ensure the connection to the MQTT server is alive (this will make the first
  // connection and automatically reconnect when disconnected).  See the MQTT_connect
  // function definition further below.
  MQTT_connect();

  Watchdog.reset();
  // Now we can publish stuff!
  read_sensors();
  Serial.print(F("\nSending val "));
  if (! barometer_feed.publish(barometer_val, precision) || ! batvoltage_feed.publish(batvoltage_val, precision) || ! humidity_feed.publish(humidity_val, precision) || ! solarvoltage_feed.publish(solarvoltage_val, precision) || ! temperature_feed.publish(temperature_val, precision) || ! winddirection_feed.publish(winddirection_val, precision) || ! windspeed_feed.publish(windspeed_val, precision)) {
    Serial.println(F("Failed"));
    txfailures++;
  } else {
    Serial.println(F("OK!"));
    txfailures = 0;
  }

  delay(60000);

  Watchdog.reset();

  // ping the server to keep the mqtt connection alive, only needed if we're not publishing
  //if(! mqtt.ping()) {
  //  Serial.println(F("MQTT Ping failed."));
  //}

}

// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
  int8_t ret;

  // Stop if already connected.
  if (mqtt.connected()) {
    return;
  }

  Serial.print("Connecting to MQTT... ");

  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
    Serial.println(mqtt.connectErrorString(ret));
    Serial.println("Retrying MQTT connection in 5 seconds...");
    mqtt.disconnect();
    delay(5000);  // wait 5 seconds
  }
  Serial.println("MQTT Connected!");
}

blang
 
Posts: 4
Joined: Fri Oct 18, 2019 8:22 am

Please be positive and constructive with your questions and comments.