B4R Question Compilation error at GPS module

pokhraj_d

Member
Hello,
I am facing compilation error while working with GPS module.
First of all I am working with additional software serial port to test my GPS module.

I am facing the below error:
======================
Verifying...
C:\Users\USER\AppData\Local\Temp\ccG2O1Lp.ltrans1.ltrans.o: In function `__static_initialization_and_destruction_0':
E:\B4R\PROGRA~1\SOFTWA~1\Objects\bin\sketch/b4r_main.cpp:16: undefined reference to `DFRobot_SIM808: DFRobot_SIM808(unsigned char, unsigned char, unsigned long)'
collect2.exe: error: ld returned 1 exit status
exit status 1
=======================

Below is my code:
B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    Public Serial1 As Serial
    Private Serial2 As SoftwareSerial 'Declaring Additional Software serial port at Arduino UNO
    'Private bc As ByteConverter
    Public astream As AsyncStreams
    Private lat, lon  As Float
End Sub

Private Sub AppStart
    'Serial1.Initialize(115200)
    Serial2.Initialize(9600,6,5)  'TX is pin 5 and RX is pin 6
    Log("AppStart")
    astream.Initialize(Serial2.Stream,"astream_newdata",Null)
    RunNative("setup",Null)
    'RunNative("read",Null)
End Sub

Sub astream_newdata(Buffer() As Byte)
    Log(Buffer)
End Sub

#if C
#include "DFRobot_sim808.h"
#define PIN_TX 5
#define PIN_RX 6
DFRobot_SIM808 sim808(PIN_TX, PIN_RX);

void setup(B4R::Object* o){
sim808.attachGPS();
}
void read (B4R::Object* o) {
   b4r_main::_lat = sim808.GPSdata.lat;
   b4r_main::_lon = sim808.GPSdata.lon;
}
#End if

I know that this is a linker issue and the linker cannot find the desired function. But the function "DFRobot_SIM808: DFRobot_SIM808" is already there.

Anyone please suggest.

Thanks-
Pokhraj Das
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The constructor you are calling is not implemented in the cpp file.

Change your code to:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   'Private bc As ByteConverter
   Private lat, lon  As Float
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   RunNative("setup",Null)
   'RunNative("read",Null)
End Sub

Sub astream_newdata(Buffer() As Byte)
   Log(Buffer)
End Sub

#if C
#include "DFRobot_sim808.h"
#define PIN_TX 5
#define PIN_RX 6
SoftwareSerial serial2(PIN_TX, PIN_RX);
DFRobot_SIM808 sim808(&serial2);
void setup(B4R::Object* o){
serial2.begin(9600);
sim808.attachGPS();
}
void read (B4R::Object* o) {
   b4r_main::_lat = sim808.GPSdata.lat;
   b4r_main::_lon = sim808.GPSdata.lon;
}
#End if

There are however other errors. See how it should be called:
https://www.dfrobot.com/wiki/index.php/SIM808_GPS/GPRS/GSM_Shield_SKU:_TEL0097#Get_GPS_Data
 
Upvote 0
Top