Using both Adafruit_FONA and Ubidots_fona libraries at the same time


#1

I’m using the Ubidots FONA library to send data via an Adafruit FONA 808, and it’s working fine.

The problem I have is that I want to also send the battery level also, which is a function of the Adafruit library but not the Ubidots library.

Specifically: fona.getBattPercent(&vbat) (from the FONA_test program)

I can get the battery function to work if I also instantiate the FONA using the Adafruit library, but if I do this then the Ubidots library no longer sends:

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;

fonaSerial->begin(4800);

if (! fona.begin(*fonaSerial)) {
   Serial.println(F("Couldn't find FONA"));
   while (1);
}

I think that this is because both instances can’t be talking to the same device over serial. So what options do I have?


#2

Greetings @dsegel, as you say both instances use serial emulation to implement communications, I see inside your code that you declare your serial pins as FONA_TX, FONA_RX, Ubidot’s library uses these keywords too. Inside our library the serial pins for the software serial emulation are declared as you see below:

#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4

So I think that the best option for you is to create a fork of our library and implement inside it a method to obtain the battery level, then you would retrieve that value it inside your loop() routine and send it using the methods of the library.

Regards