(Solved) Porting Arduino library for Lora1276 to Mongoose os, (getting undefined refrance error)

I’m working on porting Arduino library used for LoraWan module from NiceRF (lora1276)

I did the work based on the empty library and looking at other Arduino libraries, you can find it on this repo

what I know is the library build without errors. this is the last few lines of the output

AR /data/fwbuild-volumes/2.14.0/apps/Lora1276/esp32/build_contexts/build_ctx_817468552/build/objs/moslib/libmoslib.a
make[1]: Leaving directory '/data/fwbuild-volumes/2.14.0/apps/Lora1276/esp32/build_contexts/build_ctx_817468552/build/objs/moslib'
make: Leaving directory '/app'
Lib saved to build/lib.a

what I tried to do next is just include the link for my library in another application mos.yml file

libs:
 # Base System Libarary
  #Arduino Lib
  - origin: https://github.com/mongoose-os-libs/arduino-compat
  - origin: https://github.com/mongoose-os-libs/arduino-onewire
  - origin: https://github.com/mongoose-os-libs/arduino-spi

  #CCTRONIC Lib
  - origin: https://github.com/lidraikh/arduino-lora1276

I did not include anything in the main.c file, when I build for esp32 I get this error:

.../esp32/build_contexts/build_ctx_828592047/build/objs/mosapp/libmosapp.a(mgos_deps_init.o):(.rodata.descrs+0x44): undefined reference to `mgos_arduino_lora1276_init'
collect2: error: ld returned 1 exit status

at this point I’m not sure what is the problem, any guidance is appreciated.

Leo

1 Like

Your library has 2 branches release and master. Building with 2.14.0 will pull the release branch which is the empty library.

  - origin: https://github.com/lidraikh/arduino-lora1276
    version: master
2 Likes

@nliviu thank you very much.
I spent hours trying having no clue :confused:

@nliviu
I’m trying to use the library but I think I miss something here not sure what.
now inside my app. “main.c”

#include "mgos_arduino_lora1276.h"

.
other code 
.

/* Main Loop Call ------------------------------------------------------------------*/
enum mgos_app_init_result mgos_app_init(void)
{
	/* Pins set up */
	mgos_gpio_set_mode(mgos_sys_config_get_pins_led1(), MGOS_GPIO_MODE_OUTPUT);
	mgos_gpio_set_mode(mgos_sys_config_get_pins_led2(), MGOS_GPIO_MODE_OUTPUT);
	
...
	/* Setup Lora1276 */
	if(!mgos_LORA_init())
		LOG(LL_INFO, ("Lora Not initialized"));
...
	return MGOS_APP_INIT_SUCCESS;
}

doing this gives me several errors related to class LORA in the original header file.

build_ctx_177209192/build/objs/nvs_flash/src/nvs_api.o
build_contexts/build_ctx_177209192/deps/arduino-lora1276/include/mgos_arduino_lora1276.h:15:0,
build_contexts/build_ctx_177209192/src/main.c:12:
build_contexts/build_ctx_177209192/deps/arduino-lora1276/include/LORA.h:198:1: error: unknown type name 'class'
 class LORA
 ^
build_contexts/build_ctx_177209192/deps/arduino-lora1276/include/LORA.h:199:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
build_contexts/build_ctx_177209192/src/main.c:12:0:
build_contexts/build_ctx_177209192/deps/arduino-lora1276/include/mgos_arduino_lora1276.h:18:5: error: unknown type name 'LORA'
     LORA *mgos_LORA_create(int NSSPin, int NRESETPin, int txEnPin, int rxEnPin);
     ^
build_contexts/build_ctx_177209192/deps/arduino-lora1276/include/mgos_arduino_lora1276.h:20:26: error: unknown type name 'LORA'
     void mgos_LORA_close(LORA *lora);
                          ^
build_contexts/build_ctx_177209192/deps/arduino-lora1276/include/mgos_arduino_lora1276.h:23:25: error: unknown type name 'LORA'
     bool mgos_LORA_init(LORA *lora);
                         ^

and the same on all other lines where LORA is used.

I appreciate your guidance here.

Leo

Your library is only C++ compatible.
Rename main.c into main.cpp and modify

extern "C" enum mgos_app_init_result mgos_app_init(void)
3 Likes

@nliviu thank you very much.

I am having same problem and I am quit a beginner can you help me with exact procedure what to do?

There is no general recipe to port a library from Arduino to Mongoose OS.
Starting point: How to port an Arduino library

New error is occurred when I completed the library.
After Building and flashing Showing this following error and Esp32 Start Restarting.

Where Demo is my Library name:-
I am working RTC DS3231 and ESP32 in Arduino c.

Annotation%202019-12-16%20161104

It means the demo library init function returned false.

What will it return value ?

How can I solve this error?

The error comes from your code. The init function returns true if the initialization succeeds, false otherwise.

Please open another thread to discuss the issues in your library.

Hello, Can you share LoRa sending and receiving code using mongoose os libs.thankyou