ykasidit / ecodroidgps

Turns a GNU\Linux computer (or RPi, Orange Pi etc) into a Bluetooth GPS/GNSS device - supplying location from USB GPS device to mobile phones/tablets over Bluetooth.
GNU General Public License v2.0
7 stars 2 forks source link

GPS sharing #1

Open ser opened 2 years ago

ser commented 2 years ago

Hi! My use case is I must use attached GPS for a few independent analysis and a few services running on the host. Sharing to android is only one of them. Don't you think it's worth to replace current direct use of serial port to read data from gpsd service instead of, which gpsd observes and parses data serving it to ecodroidgps, among other services? Would you accept PR if I try to work on it?

ser commented 2 years ago

OK, I've just realised that it's possible to run a pseudo serial port forwarding data from gpsd via gpspipe - https://gpsd.io/gpspipe.html - so it should make a trick to share a GPS to many destinations including ecodroidgps.

But anyway it would be I think cool if ecodroidgps utilises gpsd instead of reading the sensor directly itself.

ykasidit commented 2 years ago

Great to hear that you got a solution via gpsd! Although I'm not sure if it would be helpful in your case, but just wanted to mention that ecodroidgps has a tcp server mode where you can let multiple clients connect concurrently to read the nmea - you can enable this by either changing the config file or the code "tcp_server": "0", to be "tcp_server": "1", in line 38 of https://github.com/ykasidit/ecodroidgps/blob/master/ecodroidgps_server.py (and stop the server, delete the "/config/config.ini" file if exists) then start the server and you can connect to tcp port 8888 on the host (implemented in file https://github.com/ykasidit/ecodroidgps/blob/master/edg_socket_server.py) to get the nmea concurrently via multiple tcp socket (or socat) clients. About using gpsd that's a great idea thanks! I'm still not sure if it will be able to relay all the non-nmea binary UBX or NTRIP protocol payloads (for RTK mode) to/from the device or not (and never tested yet haha so will keep as is for now).

ser commented 2 years ago

Thanks for the hints, I will study carefully your software on days, I have not noticed your socket server indeed. The most amazing is the fact you did exactly what I planned to do :) My use case is I am preparing a motorcycle computer which has access to internal bike computer and GPS in the same time, where I can relate for example engine RPM to precise location given by F9P sensor with large antennae attached and also fed my Andorid phone with more precise location than its internal sensor.

ser commented 2 years ago

It's a pipe which serves data from gpsd to ecodroidgps, if somebody will be interested

[Unit]
Description=GPSD pipe for ecodroidgps
After=network.target
After=bluetooth.service
After=gpsd.service

[Service]
Type=simple
ExecStart=socat exec:"'gpspipe --nmea'" pty,rawer,link=/tmp/ecodroidgps0
Restart=always
RestartSec=10
User=pi

[Install]
WantedBy=multi-user.target
ser commented 2 years ago

@ykasidit could you please tell me where this name.txt comes from and how it should look like?

https://github.com/ykasidit/ecodroidgps/blob/3b8b7a95cbffd32bd95f39be148a3b2b7e302cd5/start.sh#L25

ser commented 2 years ago

OK, I realised by trying and testing I need to set in config ble=1.

I can see that error:

python3: can't open file '/home/pi/bluez-gatt-server/bluez-gatt-server.py': [Errno 2] No such file or directory

Does it mean that some other repos than ecodroidgps and bluez-compassion are required?

And later I am continuously getting this error:

('WARNING: las_gen_func exception:', ['Traceback (most recent call last):\n', '  File "/home/pi/ecodroidgps/edg_gps_parser.py", line 203, in gen_ble_location_and_speed_chrc_bytes\n    ret = func(flag_bit_list, logger_state_dict)\n', '  File "/home/pi/ecodroidgps/edg_gps_parser.py", line 281, in gen_inst_speed\n    ret = np.getbuffer(np.uint16(meters_per_second))\n', '  File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 214, in __getattr__\n    raise AttributeError("module {!r} has no attribute "\n', "AttributeError: module 'numpy' has no attribute 'getbuffer'\n"])
('WARNING: las_gen_func exception:', ['Traceback (most recent call last):\n', '  File "/home/pi/ecodroidgps/edg_gps_parser.py", line 203, in gen_ble_location_and_speed_chrc_bytes\n    ret = func(flag_bit_list, logger_state_dict)\n', '  File "/home/pi/ecodroidgps/edg_gps_parser.py", line 300, in gen_position_status_and_location\n    if fix_type >= 2:\n', "TypeError: '>=' not supported between instances of 'str' and 'int'\n"])
('WARNING: las_gen_func exception:', ['Traceback (most recent call last):\n', '  File "/home/pi/ecodroidgps/edg_gps_parser.py", line 203, in gen_ble_location_and_speed_chrc_bytes\n    ret = func(flag_bit_list, logger_state_dict)\n', '  File "/home/pi/ecodroidgps/edg_gps_parser.py", line 250, in gen_elevation\n    ret = np.getbuffer(np.getbuffer(\n', '  File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 214, in __getattr__\n    raise AttributeError("module {!r} has no attribute "\n', "AttributeError: module 'numpy' has no attribute 'getbuffer'\n"])
can't create return buffer
('chrc_bytes none:', None)

I am using current version of RasperrypiOS/bullseye

ykasidit commented 2 years ago

Hello,

Yes, sorry for the lack of documentation on this, for ble mode to work, it requires https://github.com/ykasidit/bluez-gatt-server repo at same location as the folder of this project. (I devved these repos this since the old days when docker wasnt a thing yet, maybe in the future it would greatly help if all the dependencies are wrapped into the same docker image hopefully...)

Seems also that the numpy.getbuffer was removed from the newer numpy versions ( https://stackoverflow.com/questions/21821045/numpy-getbuffer-causes-attributeerror-module-object-has-no-attribute-getbuff) might have to change that too. I still hadn't got a chance to try this project on newer platforms, you might try using older vers of numpy or changing getbuffer to newer alternatives (a patch would be greatly appreciated!).

On Mon, Jun 27, 2022 at 11:48 PM ᎠᎡ. Ѕϵrgϵ Ѵictor @.***> wrote:

OK, I realised by trying and testing I need to set in config ble=1.

I can see that error:

python3: can't open file '/home/pi/bluez-gatt-server/bluez-gatt-server.py': [Errno 2] No such file or directory

Does it mean that some other repos than ecodroidgps and bluez-compassion are required?

And later I am continuously getting this error:

('WARNING: las_gen_func exception:', ['Traceback (most recent call last):\n', ' File "/home/pi/ecodroidgps/edg_gps_parser.py", line 203, in gen_ble_location_and_speed_chrc_bytes\n ret = func(flag_bit_list, logger_state_dict)\n', ' File "/home/pi/ecodroidgps/edg_gps_parser.py", line 281, in gen_inst_speed\n ret = np.getbuffer(np.uint16(meters_per_second))\n', ' File "/usr/lib/python3/dist-packages/numpy/init.py", line 214, in getattr\n raise AttributeError("module {!r} has no attribute "\n', "AttributeError: module 'numpy' has no attribute 'getbuffer'\n"]) ('WARNING: las_gen_func exception:', ['Traceback (most recent call last):\n', ' File "/home/pi/ecodroidgps/edg_gps_parser.py", line 203, in gen_ble_location_and_speed_chrc_bytes\n ret = func(flag_bit_list, logger_state_dict)\n', ' File "/home/pi/ecodroidgps/edg_gps_parser.py", line 300, in gen_position_status_and_location\n if fix_type >= 2:\n', "TypeError: '>=' not supported between instances of 'str' and 'int'\n"]) ('WARNING: las_gen_func exception:', ['Traceback (most recent call last):\n', ' File "/home/pi/ecodroidgps/edg_gps_parser.py", line 203, in gen_ble_location_and_speed_chrc_bytes\n ret = func(flag_bit_list, logger_state_dict)\n', ' File "/home/pi/ecodroidgps/edg_gps_parser.py", line 250, in gen_elevation\n ret = np.getbuffer(np.getbuffer(\n', ' File "/usr/lib/python3/dist-packages/numpy/init.py", line 214, in getattr\n raise AttributeError("module {!r} has no attribute "\n', "AttributeError: module 'numpy' has no attribute 'getbuffer'\n"]) can't create return buffer ('chrc_bytes none:', None)

I am using current version of RasperrypiOS/bullseye

— Reply to this email directly, view it on GitHub https://github.com/ykasidit/ecodroidgps/issues/1#issuecomment-1167363035, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2P3WHJW3NXJIGYTAFEETVRHLMNANCNFSM5Z3SP5TA . You are receiving this because you were mentioned.Message ID: @.***>

ykasidit commented 2 years ago

Regarding name.txt it would be just a plain text file containing the desired alternative name or you can change the default name in the sh itself too. Changing the hostname of the machine also helps for some cases too if I recall correctly.

On Tue, Jun 28, 2022 at 8:34 AM Kasidit Yusuf @.***> wrote:

Hello,

Yes, sorry for the lack of documentation on this, for ble mode to work, it requires https://github.com/ykasidit/bluez-gatt-server repo at same location as the folder of this project. (I devved these repos this since the old days when docker wasnt a thing yet, maybe in the future it would greatly help if all the dependencies are wrapped into the same docker image hopefully...)

Seems also that the numpy.getbuffer was removed from the newer numpy versions ( https://stackoverflow.com/questions/21821045/numpy-getbuffer-causes-attributeerror-module-object-has-no-attribute-getbuff) might have to change that too. I still hadn't got a chance to try this project on newer platforms, you might try using older vers of numpy or changing getbuffer to newer alternatives (a patch would be greatly appreciated!).

On Mon, Jun 27, 2022 at 11:48 PM ᎠᎡ. Ѕϵrgϵ Ѵictor < @.***> wrote:

OK, I realised by trying and testing I need to set in config ble=1.

I can see that error:

python3: can't open file '/home/pi/bluez-gatt-server/bluez-gatt-server.py': [Errno 2] No such file or directory

Does it mean that some other repos than ecodroidgps and bluez-compassion are required?

And later I am continuously getting this error:

('WARNING: las_gen_func exception:', ['Traceback (most recent call last):\n', ' File "/home/pi/ecodroidgps/edg_gps_parser.py", line 203, in gen_ble_location_and_speed_chrc_bytes\n ret = func(flag_bit_list, logger_state_dict)\n', ' File "/home/pi/ecodroidgps/edg_gps_parser.py", line 281, in gen_inst_speed\n ret = np.getbuffer(np.uint16(meters_per_second))\n', ' File "/usr/lib/python3/dist-packages/numpy/init.py", line 214, in getattr\n raise AttributeError("module {!r} has no attribute "\n', "AttributeError: module 'numpy' has no attribute 'getbuffer'\n"]) ('WARNING: las_gen_func exception:', ['Traceback (most recent call last):\n', ' File "/home/pi/ecodroidgps/edg_gps_parser.py", line 203, in gen_ble_location_and_speed_chrc_bytes\n ret = func(flag_bit_list, logger_state_dict)\n', ' File "/home/pi/ecodroidgps/edg_gps_parser.py", line 300, in gen_position_status_and_location\n if fix_type >= 2:\n', "TypeError: '>=' not supported between instances of 'str' and 'int'\n"]) ('WARNING: las_gen_func exception:', ['Traceback (most recent call last):\n', ' File "/home/pi/ecodroidgps/edg_gps_parser.py", line 203, in gen_ble_location_and_speed_chrc_bytes\n ret = func(flag_bit_list, logger_state_dict)\n', ' File "/home/pi/ecodroidgps/edg_gps_parser.py", line 250, in gen_elevation\n ret = np.getbuffer(np.getbuffer(\n', ' File "/usr/lib/python3/dist-packages/numpy/init.py", line 214, in getattr\n raise AttributeError("module {!r} has no attribute "\n', "AttributeError: module 'numpy' has no attribute 'getbuffer'\n"]) can't create return buffer ('chrc_bytes none:', None)

I am using current version of RasperrypiOS/bullseye

— Reply to this email directly, view it on GitHub https://github.com/ykasidit/ecodroidgps/issues/1#issuecomment-1167363035, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2P3WHJW3NXJIGYTAFEETVRHLMNANCNFSM5Z3SP5TA . You are receiving this because you were mentioned.Message ID: @.***>

ser commented 2 years ago

Hi! Thanks for another hints.

https://github.com/ykasidit/bluez-gatt-server uses python2 which is not available at newer operating system versions :(

I will have a look today if my programming skills are enough to propose patches :)

ser commented 2 years ago

OK, i made a pull request for bluez-gatt-server fixing compatibility with python3 in files used by ecodroidgps.

But I don't not fully understand how to replace getbuf with memoryview - maybe you could have a quick look into that? it should be a minor issue for you as it appears in three lines only and you understand your own code for sure :) 👍🏿 :)

ser commented 2 years ago

Hi mate! Are you making any progress? If not - could you please say if your intention is to continue this project or I should rather treat it as abandoned and seek other solutions?

ykasidit commented 2 years ago

Hello, Sorry for the late reply, my real work was quite demanding and coincidentally this week I'm on a family vacation, will try to fix the getbuf thing when I get back. At the moment, you need the ble feature or the nmea over tcp server feature?

On Sat, Jul 9, 2022, 15:57 ᎠᎡ. Ѕϵrgϵ Ѵictor @.***> wrote:

Hi mate! Are you making any progress? If not - could you please say if your intention is to continue this project or I should rather treat it as abandoned and seek other solutions?

— Reply to this email directly, view it on GitHub https://github.com/ykasidit/ecodroidgps/issues/1#issuecomment-1179508304, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2P3UVYTJXQOQMOUNO7TDVTE5G3ANCNFSM5Z3SP5TA . You are receiving this because you were mentioned.Message ID: @.***>

ser commented 2 years ago

Hi! Please do not understand me wrong, it's a free opensource project and I realise that all of us are doing it for fun - so no pressure. I was just curious if you still planning to work on it. If yes - fantastic as it's the best one I found. My main interest is a bluetooth service to mock location on Android. I'm working meanwhile on using influxdb to store geo-temporal data available from all sensors on my motorbike, but it's completely independent from ecodroidgps. It also will be GPLed when I have something useful to share.

ykasidit commented 2 years ago

Hello Serge,

Totally understand ;-) Thanks, will be back apx next week and try migrate the remaining components to py3. In the meantime, just to confirm, does it work without the ble configuration (so it wont need bluez-compassion)? together with your gpsd clone device method? it should work with the 'bluetooth gnss' (or other) apps toe provide mock gps on android as this default config feature (using bt-classic rfcomm) is being used in quite a number of live devices giving mock to apx 7 android connected devices at once (for telecom network test/benchmarking).

On Sun, Jul 10, 2022 at 10:01 PM ᎠᎡ. Ѕϵrgϵ Ѵictor @.***> wrote:

Hi! Please do not understand me wrong, it's a free opensource project and I realise that all of us are doing it for fun - so no pressure. I was just curious if you still planning to work on it. If yes - fantastic as it's the best one I found. My main interest is a bluetooth service to mock location on Android. I'm working meanwhile on using influxdb to store geo-temporal data available from all sensors on my motorbike, but it's completely independent from ecodroidgps. It also will be GPLed when I have something useful to share.

— Reply to this email directly, view it on GitHub https://github.com/ykasidit/ecodroidgps/issues/1#issuecomment-1179744587, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2P3RDJIN6B2X27NT2WB3VTLQU7ANCNFSM5Z3SP5TA . You are receiving this because you were mentioned.Message ID: @.***>

ser commented 2 years ago

OMG it works!

I was absolutely sure I need BLE to have it running!!!!!!!!!!!!!!!!!!!!!! I have not even tried with ble=0 before.

I can confirm it works with unselected "ecodroidgps broadcast device mode" in your Bluetooth GNSS app with this /config/config.ini:

[main]
spp = 1
ble = 0
gap = 0
tcp_server = 0
gpx = 0
nmea = 0
baud_rate = 115200
pyserial_read_timeout = 1.0
max_readline_size = 4096
max_read_buff_size = 20480

It seems that for my purposes everything is working as it should now. I am shocked and really grateful for your help :)

ser commented 2 years ago

If you plan to fix the other features, please remember that GPSD is doing 90% of your job already and provides very stable API. Please use the newest version of it as comparing to package available in Debian it fixed many bugs.