Noob dificulties

Hi there, new to platformio (coming from Arduino).

I’m trying to use the following git library, (which is a fork from the official Adafruit_Fona library)

and i’ve added the following code to the platformio.ini file

lib_deps =

GitHub - botletics/SIM7000-LTE-Shield: Botletics SIM7000 LTE CAT-M1/NB-IoT Shield for Arduino

The library seem to be uploaded ok (i can see it in the folder structure .pio), but the compile fails giving the following errors, (basically it is not finding the.h file)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION:
PLATFORM: Atmel AVR 2.0.0 > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
PACKAGES: toolchain-atmelavr 1.50400.190710 (5.4.0), framework-arduino-avr 5.0.0
LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 12 compatible libraries
Scanning dependencies…
Dependency Graph
|-- #3a94833
|-- 1.0
Building in release mode
Compiling
src\main.cpp:29:95: fatal error: Adafruit_FONA.h: No such file or directory


  • Looking for Adafruit_FONA.h dependency? Check our library registry!
  • CLI > platformio lib search “header:Adafruit_FONA.h”
  • Web >

compilation terminated.
*** [.pio\build\uno\src\main.cpp.o] Error 1
===================================================================================== [FAILED] Took 3.46 seconds =====================================================================================
The terminal process terminated with exit code: 1

Any pointers most welcome!

(Sorry, I had to butcher the output as a new user can only have 2 links in a post!!!)

The repository doesn’t have the required folder structure so that cloning it results in a PlatformIO library. You need to manually download the repository (GitHub - botletics/SIM7000-LTE-Shield: Botletics SIM7000 LTE CAT-M1/NB-IoT Shield for Arduino) and copy the Code folder as a new library in lib/ to your project.

1 Like

Thank you very much for the reply Max,

ok - I’ve done that and now it no longer complains about missing header files! One step forward…

I’m however presented with a raft of warnings (in yellow)? and some errors in red.

The compiler doesn’t seem to see the functions in the main.cpp it compiles ok in Arduino and I thought using the same framework it would be the same or are there different syntax arrangements for platformio?

I really wan to get into Platformio but the learning curve is proving painful, I’ve gone through all the tutorials and read some of the manual but just getting my 1st project to compile is hard.

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR 2.0.0 > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
PACKAGES: toolchain-atmelavr 1.50400.190710 (5.4.0), framework-arduino-avr 5.0.0
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 15 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Adafruit FONA Library> 1.3.3
|-- <SoftwareSerial> 1.0
Building in release mode
Compiling .pio\build\uno\src\main.cpp.o
Compiling .pio\build\uno\lib328\Code\Adafruit_FONA.cpp.o
Compiling .pio\build\uno\lib47b\SoftwareSerial\SoftwareSerial.cpp.o
Archiving .pio\build\uno\libFrameworkArduinoVariant.a
Compiling .pio\build\uno\FrameworkArduino\CDC.cpp.o
In file included from lib\Code\includes/platform/FONAPlatStd.h:32:0,
                 from lib\Code\includes/platform/FONAPlatform.h:31,
                 from lib\Code\Adafruit_FONA.h:22,
                 from lib\Code\Adafruit_FONA.cpp:19:
lib\Code\Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::sendUSSD(char*, char*, uint16_t, uint16_t*)':
C:\Users\simon.jowett\.platformio\packages\framework-arduino-avr\cores\arduino/Arduino.h:92:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define min(a,b) ((a)<(b)?(a):(b))
                      ^
lib\Code\Adafruit_FONA.cpp:829:28: note: in expansion of macro 'min'
       uint16_t lentocopy = min(maxlen-1, strend - p);
                            ^
lib\Code\Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::getTime(char*, uint16_t)':
C:\Users\simon.jowett\.platformio\packages\framework-arduino-avr\cores\arduino/Arduino.h:92:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define min(a,b) ((a)<(b)?(a):(b))
                      ^
lib\Code\Adafruit_FONA.cpp:893:24: note: in expansion of macro 'min'
   uint16_t lentocopy = min(maxlen-1, (int)strlen(p));
                        ^
lib\Code\Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::getGPS(float*, float*, float*, float*, float*, uint16_t*, uint8_t*, uint8_t*, uint8_t*, uint8_t*, float*)':
lib\Code\Adafruit_FONA.cpp:1081:11: warning: variable 'tok' set but not used [-Wunused-but-set-variable]
     char *tok;
           ^
In file included from lib\Code\includes/platform/FONAPlatStd.h:32:0,
                 from lib\Code\includes/platform/FONAPlatform.h:31,
                 from lib\Code\Adafruit_FONA.h:22,
                 from lib\Code\Adafruit_FONA.cpp:19:
lib\Code\Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::getGSMLoc(uint16_t*, char*, uint16_t)':
C:\Users\simon.jowett\.platformio\packages\framework-arduino-avr\cores\arduino/Arduino.h:92:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define min(a,b) ((a)<(b)?(a):(b))
                      ^
lib\Code\Adafruit_FONA.cpp:1661:24: note: in expansion of macro 'min'
   uint16_t lentocopy = min(maxlen-1, (int)strlen(p));
                        ^
lib\Code\Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::postData(const char*, const char*, const char*, const char*, uint32_t)':
lib\Code\Adafruit_FONA.cpp:1723:23: warning: comparison with string literal results in unspecified behaviour [-Waddress]
   if (request_type == "GET") {
                       ^
lib\Code\Adafruit_FONA.cpp:1727:28: warning: comparison with string literal results in unspecified behaviour [-Waddress]
   else if (request_type == "POST" && bodylen > 0 ) { // POST with content body
                            ^
lib\Code\Adafruit_FONA.cpp:1742:52: warning: format '%d' expects argument of type 'int', but argument 3 has type 'uint32_t {aka long unsigned int}' [-Wformat=]
   sprintf(dataBuff, "AT+HTTPDATA=%d,10000", bodylen);
                                                    ^
lib\Code\Adafruit_FONA.cpp:1754:28: warning: comparison with string literal results in unspecified behaviour [-Waddress]
   else if (request_type == "POST" && bodylen == 0) { // POST with query parameters
                            ^
lib\Code\Adafruit_FONA.cpp:1758:28: warning: comparison with string literal results in unspecified behaviour [-Waddress]
   else if (request_type == "HEAD") {
                            ^
lib\Code\Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::postData(const char*, uint16_t, const char*, const char*, const char*)':
lib\Code\Adafruit_FONA.cpp:1793:13: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   if (_type == SIM7500A | _type == SIM7500E || _type == SIM7600A || _type == SIM7600C || _type == SIM7600E) {
             ^
lib\Code\Adafruit_FONA.cpp:1827:13: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   if (_type == SIM7500A | _type == SIM7500E || _type == SIM7600A || _type == SIM7600C || _type == SIM7600E) {
             ^
lib\Code\Adafruit_FONA.cpp:1858:13: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   if (_type == SIM7500A | _type == SIM7500E || _type == SIM7600A || _type == SIM7600C || _type == SIM7600E) {
             ^
lib\Code\Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::MQTTunsubscribe(const char*)':
lib\Code\Adafruit_FONA.cpp:2416:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
lib\Code\Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::MQTTreceive(const char*, const char*, int)':
lib\Code\Adafruit_FONA.cpp:2420:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
lib\Code\Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::MQTTdisconnect()':
lib\Code\Adafruit_FONA.cpp:2424:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
lib\Code\Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA_LTE::MQTT_dataFormatHex(bool)':
lib\Code\Adafruit_FONA.cpp:2495:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
src\main.cpp: In function 'void setup()':
src\main.cpp:106:11: error: 'powerOn' was not declared in this scope
   powerOn(); // See function definition at the very end of the sketch
           ^
src\main.cpp: In function 'void loop()':
src\main.cpp:239:72: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     } while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaNotificationBuffer)-1)));
                                                                        ^
src\main.cpp:266:46: error: 'sendText' was not declared in this scope
           sendText("Treasure chest unlocked!");
                                              ^
src\main.cpp:271:42: error: 'sendText' was not declared in this scope
           sendText("Opening secret door!");
                                          ^
src\main.cpp:283:31: error: 'sendText' was not declared in this scope
           sendText(textMessage);
                               ^
Archiving .pio\build\uno\lib47b\libSoftwareSerial.a
*** [.pio\build\uno\src\main.cpp.o] Error 1

ok - I’ve partially answered my own question - YES there is a significant difference between Arduino and Platformio in that functions have to appear above the loop command whereas in Arduino they can appear anywhere in the code.

Now I have moved the powerOn() and sendText(textMessage) functions I only get a few errors:

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION:
PLATFORM: Atmel AVR 2.0.0 > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
PACKAGES: toolchain-atmelavr 1.50400.190710 (5.4.0), framework-arduino-avr 5.0.0
LDF: Library Dependency Finder ->
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 15 compatible libraries
Scanning dependencies…
Dependency Graph
|-- 1.3.3
|-- 1.0
Building in release mode
Compiling .pio\build\uno\src\main.cpp.o
src\main.cpp: In function ‘void sendText(const char*)’:
src\main.cpp:117:21: error: ‘callerIDbuffer’ was not declared in this scope
if (!fona.sendSMS(callerIDbuffer, textMessage)) {
^
src\main.cpp:126:22: error: ‘slot’ was not declared in this scope
if (fona.deleteSMS(slot)) {
^
src\main.cpp: In function ‘void loop()’:
src\main.cpp:277:72: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
} while ((*bufPtr++ != ‘\n’) && (fona.available()) && (++charCount < (sizeof(fonaNotificationBuffer)-1)));
^
*** [.] Error 1

…and finally I have also resolved the other issues with Platformio, you can’t declare global variables anywhere in the sketch, they have to be before the setup().

I am however left with one warning on this line of code which I think I understand:

src\main.cpp: In function ‘void loop()’:
src\main.cpp:279:72: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
} while ((*bufPtr++ != ‘\n’) && (fona.available()) && (++charCount < (sizeof(fonaNotificationBuffer)-1)));

The warning indicator arrow is pointing to

++charCount < (sizeof(fonaNotificationBuffer)

and I guess its warning that there might be a conflict in comparing 2 different types of integer (signed and unsigned). Maybe for accuracy I could change that in the library?

I’m posting these answers to my own questions in the hope that it will help another beginner out there!

You can. Look for the declaration of charCount variable. It probably has signed integer type. sizeof operator is always unsigned. Since the negative number of characters doesn’t make any sense, I think you can safely make it unsigned too.

Actually they should be declared before the place where they are used.
Welcome to real C++, not the Arduino dialect :wink:

As stated in the FAQ, Arduino is not pure C/C++, put generates function prototypes for you, so you don’t have to declare them. PlatformIO doesn’t do such preprocessing and you have to write actually correct C/C++. That’s where your error comes from. In C/C++ you cannot call a function which you haven’t declared before, so code like

void setup() {
   sendText("test");
} 

void sendText(const char* s) {
//
}

is illegal. Above setup() / before calling it, there must be the prototype declaration

void sendText(const char*);