Bluetooth Communication with GPS Tracker GPSlim236

E1nste1n
Posts: 3
Joined: Wed Oct 31, 2018 10:02 pm

Bluetooth Communication with GPS Tracker GPSlim236

Postby E1nste1n » Wed Oct 31, 2018 10:31 pm

Hey guys,

I've already tried several examples for esp32 classic BT connections but nothing worked out for me. I hope you can help.

First of all, what do I want to achieve? -> I have a GPSlim236 GPS tracker and want to receive with my esp32 the NMEA messages broadcasted by the GPSlim236. Therefore, my idea is to establish a BT connection between the esp32 and the GPSlim236 and read the data received via BT.

According to the GPSlim236 manual (https://fccid.io/RJIGPSLIM236/User-Manu ... ual-547971) it is "completely compatible with Bluetooth Serial Port Profile (SPP)". Further, it states the output protocol baudrate is 38400bps.

With that information i tried to open a SerialBT Interface on my esp32 with baudrate=38400 and perform SerialBT.read() but that didn't work out. I'm still not sure how to "connect" or pair with the GPSlim236?!

For example, using my android phone and a Bluetooth Terminal App, I can simply connect to the GPSlim236 via BT and receive the broadcasted messages, e.g.:

Code: Select all

22:59:09.278 Connecting to HOLUX GPSlim236 ...
22:59:10.191 Connected
22:59:10.336 $GPGGA,000009.059,0000.0000,N,00000.0000,E,0,00,,0.0,M,0.0,M,,0000*46 
22:59:10.436 $GPRMC,000009.059,V,0000.0000,N,00000.0000,E,,,160406,,,N*76 
22:59:10.617 $GPVTG,,T,,M,,N,,K,N*2C 
22:59:11.336 $GPGGA,000010.065,0000.0000,N,00000.0000,E,0,00,,0.0,M,0.0,M,,0000*41 
22:59:11.410 $GPRMC,000010.065,V,0000.0000,N,00000.0000,E,,,160406,,,N*71 
22:59:11.485 $GPVTG,,T,,M,,N,,K,N*2C 
22:59:12.337 $GPGGA,000011.063,0000.0000,N,00000.0000,E,0,00,,0.0,M,0.0,M,,0000*46 
22:59:12.386 $GPRMC,000011.063,V,0000.0000,N,00000.0000,E,,,160406,,,N*76 
22:59:12.485 $GPVTG,,T,,M,,N,,K,N*2C 
22:59:13.336 $GPGGA,000012.059,0000.0000,N,00000.0000,E,0,00,,0.0,M,0.0,M,,0000*4C 
22:59:13.436 $GPGSA,A,1,,,,,,,,,,,,,,,*1E 
22:59:13.536 $GPGSV,3,1,12,20,00,000,,10,00,000,,25,00,000,,27,00,000,*79 
22:59:13.610 $GPGSV,3,2,12,22,00,000,,07,00,000,,21,00,000,,24,00,000,*79 
22:59:13.685 $GPGSV,3,3,12,16,00,000,,28,00,000,,26,00,000,,29,00,000,*78 
22:59:13.761 $GPRMC,000012.059,V,0000.0000,N,00000.0000,E,,,160406,,,N*7C 
22:59:13.837 $GPVTG,,T,,M,,N,,K,N*2C 
22:59:14.111 Disconnected from device
On the esp32 I tried the "bt_discovery" example (https://github.com/espressif/esp-idf/tr ... _discovery) and the serial monitor output was:

Code: Select all

ets Jun  8 2016 00:22:57
18:35:18.665 -> 
18:35:18.665 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
18:35:18.665 -> configsip: 0, SPIWP:0xee
18:35:18.665 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
18:35:18.665 -> mode:DIO, clock div:2
18:35:18.665 -> load:0x3fff0018,len:4
18:35:18.665 -> load:0x3fff001c,len:6328
18:35:18.665 -> load:0x40078000,len:10084
18:35:18.665 -> load:0x40080400,len:6476
18:35:18.665 -> entry 0x40080764
[0;32mI (29) boot: ESP-IDF v3.2-dev-1250-g221eced06 2nd stage bootloader[0m
18:35:18.734 -> [0;32mI (29) boot: compile time 22:01:43[0m
18:35:18.734 -> [0;32mI (29) boot: Enabling RNG early entropy source...[0m
18:35:18.734 -> [0;32mI (35) boot: SPI Speed      : 40MHz[0m
18:35:18.734 -> [0;32mI (39) boot: SPI Mode       : DIO[0m
18:35:18.734 -> [0;32mI (43) boot: SPI Flash Size : 4MB[0m
18:35:18.734 -> [0;32mI (47) boot: Partition Table:[0m
18:35:18.734 -> [0;32mI (51) boot: ## Label            Usage          Type ST Offset   Length[0m
18:35:18.734 -> [0;32mI (58) boot:  0 nvs              WiFi data        01 02 00009000 00006000[0m
18:35:18.734 -> [0;32mI (66) boot:  1 phy_init         RF data          01 01 0000f000 00001000[0m
18:35:18.734 -> [0;32mI (73) boot:  2 factory          factory app      00 00 00010000 00100000[0m
18:35:18.734 -> [0;32mI (81) boot: End of partition table[0m
18:35:18.734 -> [0;32mI (85) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x2306c (143468) map[0m
[0;32mI (144) esp_image: segment 1: paddr=0x00033094 vaddr=0x3ff80000 size=0x00000 (     0) load[0m
18:35:18.838 -> [0;32mI (144) esp_image: segment 2: paddr=0x0003309c vaddr=0x3ff80000 size=0x00000 (     0) load[0m
18:35:18.838 -> [0;32mI (151) esp_image: segment 3: paddr=0x000330a4 vaddr=0x3ffbdb60 size=0x02f30 ( 12080) load[0m
18:35:18.838 -> [0;32mI (164) esp_image: segment 4: paddr=0x00035fdc vaddr=0x3ffc0a90 size=0x00000 (     0) load[0m
18:35:18.838 -> [0;32mI (169) esp_image: segment 5: paddr=0x00035fe4 vaddr=0x40080000 size=0x00400 (  1024) load[0m
18:35:18.838 -> [0;32mI (178) esp_image: segment 6: paddr=0x000363ec vaddr=0x40080400 size=0x09c24 ( 39972) load[0m
18:35:18.838 -> [0;32mI (203) esp_image: segment 7: paddr=0x00040018 vaddr=0x400d0018 size=0x76638 (484920) map[0m
[0;32mI (373) esp_image: segment 8: paddr=0x000b6658 vaddr=0x4008a024 size=0x081cc ( 33228) load[0m
[0;32mI (387) esp_image: segment 9: paddr=0x000be82c vaddr=0x400c0000 size=0x00000 (     0) load[0m
18:35:19.116 -> [0;32mI (387) esp_image: segment 10: paddr=0x000be834 vaddr=0x50000000 size=0x00000 (     0) load[0m
18:35:19.116 -> [0;32mI (394) esp_image: segment 11: paddr=0x000be83c vaddr=0x50000000 size=0x00000 (     0) load[0m
18:35:19.116 -> [0;32mI (414) boot: Loaded app from partition at offset 0x10000[0m
18:35:19.116 -> [0;32mI (414) boot: Disabling RNG early entropy source...[0m
18:35:19.116 -> [0;32mI (415) cpu_start: Pro cpu up.[0m
18:35:19.116 -> [0;32mI (418) cpu_start: Starting app cpu, entry point is 0x40081040[0m
18:35:19.116 -> [0;32mI (0) cpu_start: App cpu up.[0m
18:35:19.116 -> [0;32mI (429) heap_init: Initializing. RAM available for dynamic allocation:[0m
18:35:19.116 -> [0;32mI (436) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM[0m
18:35:19.116 -> [0;32mI (442) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM[0m
18:35:19.116 -> [0;32mI (448) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM[0m
18:35:19.116 -> [0;32mI (454) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM[0m
18:35:19.116 -> [0;32mI (460) heap_init: At 3FFCB5D8 len 00014A28 (82 KiB): DRAM[0m
18:35:19.116 -> [0;32mI (466) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM[0m
18:35:19.116 -> [0;32mI (472) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[0m
18:35:19.116 -> [0;32mI (479) heap_init: At 400921F0 len 0000DE10 (55 KiB): IRAM[0m
18:35:19.116 -> [0;32mI (485) cpu_start: Pro cpu start user code[0m
[0;32mI (168) cpu_start: Starting scheduler on PRO CPU.[0m
18:35:19.150 -> [0;32mI (0) cpu_start: Starting scheduler on APP CPU.[0m
[0;32mI (236) BTDM_INIT: BT controller compile version [a348a1e][0m
18:35:19.187 -> [0;32mI (236) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE[0m
[0;32mI (316) phy: phy_version: 4000, b6198fa, Sep  3 2018, 15:11:06, 0, 0[0m
[0;32mI (936) GAP: Discovery started.[0m
[0;32mI (3116) GAP: Device found: 00:0b:0d:85:ed:72[0m
18:35:22.063 -> [0;32mI (3116) GAP: --Class of Device: 0x1f00[0m
18:35:22.063 -> [0;32mI (3116) GAP: --RSSI: -62[0m
[0;32mI (3346) GAP: Device found: 00:0b:0d:85:ed:72[0m
18:35:22.310 -> [0;32mI (3346) GAP: --Class of Device: 0x1f00[0m
18:35:22.310 -> [0;32mI (3346) GAP: --RSSI: -64[0m
[0;32mI (8226) GAP: Device found: 00:0b:0d:85:ed:72[0m
18:35:27.190 -> [0;32mI (8226) GAP: --Class of Device: 0x1f00[0m
18:35:27.190 -> [0;32mI (8226) GAP: --RSSI: -58[0m
[0;32mI (13756) GAP: Device discovery stopped.[0m
[0;32mI (15396) GAP: Device found: 00:0b:0d:85:ed:72[0m
18:35:34.321 -> [0;32mI (15396) GAP: Device discovery stopped.[0m
As you can see, the bt_discovery example worked out so far, because the correct device (GPSlim236) with its MAC address=00:0b:0d:85:ed:72 was found.
But again, I don't know how to establish a BT connection on my eps32 to a device with exactly that mac address?

I also tried the bt_spp_initiator and bt_spp_acceptor examples (https://github.com/espressif/esp-idf/tr ... /bluetooth) - but again I didn't receive any data with my esp32.

I hope you can help and give me a hint how to establish a connection to my GPS tracker.
Thank you very much in advance!

ESP_Tianhao
Posts: 28
Joined: Thu Jan 05, 2017 10:46 am

Re: Bluetooth Communication with GPS Tracker GPSlim236

Postby ESP_Tianhao » Thu Nov 01, 2018 3:40 am

Hi, E1nste1n,
From your description, you should use "bt_spp_initiator" demo. Since your android phone and terminal application can work with GPSlim236, it seems GPSlim235 start a SPP service, you should use "bt_spp_initator" to discover and connect to it.
Could you try it? Welcome to discuss any problem. Thanks.

E1nste1n
Posts: 3
Joined: Wed Oct 31, 2018 10:02 pm

Re: Bluetooth Communication with GPS Tracker GPSlim236

Postby E1nste1n » Thu Nov 01, 2018 9:31 pm

Hey ESP_Tianhao,

thank you very much for your fast reply!
I thought, since the GPS Tracker broadcasts the NMEA messages via BT I have to run the bt_spp_acceptor on my esp32.
However, I tried the bt_spp_initiator demo (https://github.com/espressif/esp-idf/bl ... tor_demo.c) and this is what I get:

Code: Select all

I (29) boot: ESP-IDF v3.2-dev-1250-g221eced06 2nd stage bootloader
I (29) boot: compile time 19:27:41
I (29) boot: Enabling RNG early entropy source...
I (35) boot: SPI Speed      : 40MHz
I (39) boot: SPI Mode       : DIO
I (43) boot: SPI Flash Size : 4MB
I (47) boot: Partition Table:
I (51) boot: ## Label            Usage          Type ST Offset   Length
I (58) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (65) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (73) boot:  2 factory          factory app      00 00 00010000 00100000
I (80) boot: End of partition table
I (85) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x26800 (157696) map
I (149) esp_image: segment 1: paddr=0x00036828 vaddr=0x3ff80000 size=0x00000 (     0) load
I (149) esp_image: segment 2: paddr=0x00036830 vaddr=0x3ff80000 size=0x00000 (     0) load
I (155) esp_image: segment 3: paddr=0x00036838 vaddr=0x3ffbdb60 size=0x02f60 ( 12128) load
I (169) esp_image: segment 4: paddr=0x000397a0 vaddr=0x3ffc0ac0 size=0x00000 (     0) load
I (173) esp_image: segment 5: paddr=0x000397a8 vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _WindowOverflow4 at /Users/richardhauer/Documents/Arduino/libraries/esp/esp-idf/components/freertos/xtensa_vectors.S:1685

I (183) esp_image: segment 6: paddr=0x00039bb0 vaddr=0x40080400 size=0x06460 ( 25696) load
I (202) esp_image: segment 7: paddr=0x00040018 vaddr=0x400d0018 size=0x80dc4 (527812) map
0x400d0018: _flash_cache_start at ??:?

I (387) esp_image: segment 8: paddr=0x000c0de4 vaddr=0x40086860 size=0x0b990 ( 47504) load
0x40086860: r_lld_evt_restart at ??:?

I (407) esp_image: segment 9: paddr=0x000cc77c vaddr=0x400c0000 size=0x00000 (     0) load
I (407) esp_image: segment 10: paddr=0x000cc784 vaddr=0x50000000 size=0x00000 (     0) load
I (414) esp_image: segment 11: paddr=0x000cc78c vaddr=0x50000000 size=0x00000 (     0) load
I (433) boot: Loaded app from partition at offset 0x10000
I (434) boot: Disabling RNG early entropy source...
I (435) cpu_start: Pro cpu up.
I (438) cpu_start: Starting app cpu, entry point is 0x40081040
0x40081040: call_start_cpu1 at /Users/richardhauer/Documents/Arduino/libraries/esp/esp-idf/components/esp32/cpu_start.c:234

I (0) cpu_start: App cpu up.
I (449) heap_init: Initializing. RAM available for dynamic allocation:
I (455) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (462) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (468) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (474) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM
I (480) heap_init: At 3FFCDEE8 len 00012118 (72 KiB): DRAM
I (486) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (492) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (499) heap_init: At 400921F0 len 0000DE10 (55 KiB): IRAM
I (505) cpu_start: Pro cpu start user code
I (188) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (255) BTDM_INIT: BT controller compile version [a348a1e]
I (255) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (335) phy: phy_version: 4000, b6198fa, Sep  3 2018, 15:11:06, 0, 0
I (915) SPP_INITIATOR_DEMO: ESP_SPP_INIT_EVT
I (935) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_STATE_CHANGED_EVT
I (5995) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_RES_EVT
I (5995) SPP_INITIATOR_DEMO: 00 0b 0d 85 ed 72 
I (6035) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_RES_EVT
I (6035) SPP_INITIATOR_DEMO: 00 0b 0d 85 ed 72 
I (11115) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_RES_EVT
I (11115) SPP_INITIATOR_DEMO: 00 0b 0d 85 ed 72 
I (21345) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_RES_EVT
I (21345) SPP_INITIATOR_DEMO: 00 0b 0d 85 ed 72 
I (36715) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_RES_EVT
I (36715) SPP_INITIATOR_DEMO: 00 0b 0d 85 ed 72 
I (39345) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_STATE_CHANGED_EVT
I (41325) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_RES_EVT
I (41325) SPP_INITIATOR_DEMO: 00 0b 0d 85 ed 72 
I (41325) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_STATE_CHANGED_EVT
I guess the GPS tracker is visible to my esp32 because the mac address seems to be the correct one, but I don't receive any data!
Don't I have to specify to which device my esp32 should connect or listen?

In the code of the bt_spp_initiator there is this line

Code: Select all

static esp_bd_addr_t peer_bd_addr;
but I don't understand where this variable peer_bd_addr is set?

Any further hints for me?

E1nste1n
Posts: 3
Joined: Wed Oct 31, 2018 10:02 pm

Re: Bluetooth Communication with GPS Tracker GPSlim236

Postby E1nste1n » Sun Nov 18, 2018 1:56 pm

Does anybody else have an idea how I can connect to my GPS Tracker (MAC address known) and receive the data via BT SPP with my esp32?

liklev
Posts: 2
Joined: Thu Jul 18, 2019 11:37 am

Re: Bluetooth Communication with GPS Tracker GPSlim236

Postby liklev » Thu Jul 02, 2020 10:49 pm

hi Einstein,
(i know its late but maybe you set aside your project and take it out from drawer)
i have an iBT-GPS tracker with bluetooth spp service, might be similar to your device.

in arduino ide the esp32 wrover modules examples > bluetoothserial > serialtoserialBTM
this has worked for me


in the example i changed the name, the address, and to connect to addres instead of connect to name.
and i removed the delay(20) from the bottom end (caused missed "new lines"
and i also removed the writing toward gps part.

so it nicely printing the nmea messages from the gps into the serial monitor.


[Codebox]
//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Victor Tchistiak - 2019
//
//This example demostrates master mode bluetooth connection and pin
//it creates a bridge between Serial and Classical Bluetooth (SPP)
//this is an extention of the SerialToSerialBT example by Evandro Copercini - 2018
//

#include "BluetoothSerial.h"

BluetoothSerial SerialBT;

String MACadd = "AA:BB:CC:11:22:33";
uint8_t address[6] = {0x00, 0x0B, 0x0D, 0x89, 0x0B, 0x8A};

String name = "iBT-GPS";
char *pin = "0000"; //<- standard pin would be provided by default
bool connected;

void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32test", true);
SerialBT.setPin(pin);
Serial.println("The device started in master mode, make sure remote BT device is on!");

// connect(address) is fast (upto 10 secs max), connect(name) is slow (upto 30 secs max) as it needs
// to resolve name to address first, but it allows to connect to different devices with the same name.
// Set CoreDebugLevel to Info to view devices bluetooth address and device names

//connected = SerialBT.connect(name);
connected = SerialBT.connect(address);

if(connected) {
Serial.println("Connected Succesfully!");
} else {
while(!SerialBT.connected(10000)) {
Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app.");
}
}
// disconnect() may take upto 10 secs max
if (SerialBT.disconnect()) {
Serial.println("Disconnected Succesfully!");
}
// this would reconnect to the name(will use address, if resolved) or address used with connect(name/address).
SerialBT.connect();
}

void loop() {
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}

}
[/Codebox]

Who is online

Users browsing this forum: daveian and 39 guests