2004 to 2016 Mazda 3 Forum and Mazdaspeed 3 Forums banner

1 - 20 of 55 Posts

·
Registered
Joined
·
60 Posts
Discussion Starter #1
It is possible to add live bluetooth based temperature/pressure sensors to your wheels and capture the data to your CMU/Infotainment via a bluetooth board with with USB CDC support that is plugged to the car's USB port. The only thing is missing is the UI. Though it is possible to integrate this with the speedometer application screen :)

The sensors are BLE TPMS VC601 Wireless Wheel Pressure and Temperature sensors.

The bluetooth board is recognized by the linux OS and uses the libusb library which is already built in with the OS binaries.

The bluetooth boards are from Redbear Labs BLE Mini configured as HCI Bluetooth Central via USB CDC 115200 bps

A C code is written that actually reads the data from the bluetooth board which is configured to captured bluetooth BLE advertisements from the sensors.


memcpy(&tmpval, buf+27, 4);
memcpy(&tmpval2, buf+31, 4);

pressure = (double) ((tmpval / 100000.00) * 14.5);
temperature = (double) (tmpval2 / 100.00);

Pressure and temperature data is retrieved from the BLE GAP advertisement using the above formula.

The only thing is missing is the UI. Care to help me on this one ? :)
 

Attachments

·
Registered
Joined
·
60 Posts
Discussion Starter #2
When you plug these Bluetooth boards (configured as HCI USB CDC) to your car cmu, it is automatically recognized as a USB device which can now be accessed via libusb :)
 

Attachments

·
Registered
Joined
·
302 Posts
When you plug these Bluetooth boards (configured as HCI USB CDC) to your car cmu, it is automatically recognized as a USB device which can now be accessed via libusb :)
Should be easy to format the data and put into some variables to read in the speedometer. For a quick test you could just get one value and substitute it for one of the existing values read in speedometer.sh. Also the update would not have to be very fast if you did not want to have alarming in the CMU. I was looking for these on Amazon and they are out of stock and I was not wanting to have to unmount and remount the tires. I found these and am wondering if they upset the balance much. I may give them a try in any case.
 

·
Registered
Joined
·
60 Posts
Discussion Starter #4
UI Integration tests Done :)

Was able to integrate the code for the Bluetooth board which only creates a 1 liner text file (tpms.out) based on the BLE Advertisement scan results. Only the MAC addresses of the four wheel sensors are allowed and processed. Temperature and pressure data of all four wheel are computed and stored in the text file. The one liner text file is then read/parsed via speedometer.sh and parsed values are then passed to the UI interface.

The code part that polls the BLE advertisements are also inserted inside speedometer.sh What it does is it sends commands to the bluetooth board and then exits. The good thing about this board that the last command is executed even if the host app is not active. Thus you can actually read the results on the next iteration of speedometer.sh and a new set of bluetooth scan commands is sent to the board and the code then exits again without waiting for the scan results . Results are read on the next iteration.

Everytime a valid sensor packet is received, the tpms.out file is updated.
 

Attachments

·
Registered
Joined
·
60 Posts
Discussion Starter #5
Should be easy to format the data and put into some variables to read in the speedometer. For a quick test you could just get one value and substitute it for one of the existing values read in speedometer.sh. Also the update would not have to be very fast if you did not want to have alarming in the CMU. I was looking for these on Amazon and they are out of stock and I was not wanting to have to unmount and remount the tires. I found these and am wondering if they upset the balance much. I may give them a try in any case. https://www.amazon.com/KUFUNG-Pressure-Monitoring-Wireless-Temperature/dp/B077NXNHZS/ref=pd_lpo_sbs_263_t_0?_encoding=UTF8&psc=1&refRID=ADVNN24XS5RS3YBXK11S
Yes. I saw those bluetooth TPMS caps too. As per documentation, they dont upset the balance. The only issue i could think from these caps is how big they look on the rims :) but they do work :) In my case, i chose the setup that is hidden inside the rims as i was due for a tire replacement when i had them installed. :)

btw, just one quick question anderml1955 being you as one of the developers of the speedometer application, may i know what is the green horizontal bar on the top of the infotainment screen ? It came out after i installed the speedometer app :) I did not see that part described in the documentation. Thanks.
 

·
Registered
Joined
·
302 Posts
Yes. I saw those bluetooth TPMS caps too. As per documentation, they dont upset the balance. The only issue i could think from these caps is how big they look on the rims :) but they do work :) In my case, i chose the setup that is hidden inside the rims as i was due for a tire replacement when i had them installed. :)

btw, just one quick question anderml1955 being you as one of the developers of the speedometer application, may i know what is the green horizontal bar on the top of the infotainment screen ? It came out after i installed the speedometer app :) I did not see that part described in the documentation. Thanks.
Yea, they look a bit strange hanging out there on my MX-5. I may move them to my significant other's Prius!
My speedometer work is ages ago. I believe @Trezdog44 answered your question - he has enhanced it significantly past my hacking skills.

Could you point me to the CDC HCI applications you are using? My BLE board did not have any links to sample applications. Update - is it this https://github.com/RedBearLab/BLE_HCI
 

·
Registered
Joined
·
60 Posts
Discussion Starter #7
Yea, they look a bit strange hanging out there on my MX-5. I may move them to my significant other's Prius!
My speedometer work is ages ago. I believe @Trezdog44 answered your question - he has enhanced it significantly past my hacking skills.

Could you point me to the CDC HCI applications you are using? My BLE board did not have any links to sample applications. Update - is it this https://github.com/RedBearLab/BLE_HCI

Yes the firmware code loaded on the board is from github's redbearlabs;

https://github.com/RedBearLab/BLE_HCI/blob/master/cc2540_hci_fw/HCI_USBCDC_115200_20130429.bin.zip

The base code to which i used to initialize and the put the board in discovery mode was from the arduino C codes ;

https://github.com/RedBearLab/BLE_HCI/blob/master/arduino/libraries/BLEHCI/examples/BLE_HCI_BiscuitCentral/BLE_HCI_BiscuitCentral.ino

Then i ported that part of the arduino code to a libusb handler code;

https://github.com/tytouf/libusb-cdc-example/blob/master/cdc_example.c

then compiled it using the m3 toolchain under ubuntu :)

./m3-toolchain/bin/arm-cortexa9_neon-linux-gnueabi-g++ -MD -s -O3 -s -rdynamic -pthread --sysroot=./m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot -DCMU=1 -D__STDC_FORMAT_MACROS -march=armv7-a -mtune=cortex-a9 -mfpu=neon -std=c++11 -static-libstdc++ -D_GLIBCXX_USE_C99 -pthread -DDBUS_API_SUBJECT_TO_CHANGE -I./m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/include/gstreamer-0.10 -I./m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/include/libxml2 -I./m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/include/libusb-1.0 -I./m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/local/ssl/include -I./m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/include/glib-2.0 -I./m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/glib-2.0/include -I./m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/include/dbus-c++-1 -I./m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/include/dbus-1.0 -I./m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/dbus-1.0/include -I./m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/include/alsa -I/root/headunit_004/headunit/hu -I/root/headunit_004/headunit/common -I/root/headunit_004/headunit/hu/generated.arm -I./protobuf-2.6.1-arm/include -I./libunwind-1.2-rc1/include -c mazda_tpms.c -o mazda_tpms.o


./m3-toolchain/bin/arm-cortexa9_neon-linux-gnueabi-g++ -MD -s -o mazda_tpms mazda_tpms.o --sysroot=./m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot -s -rdynamic -pthread -ldl -static-libstdc++ -L./m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/local/ssl/lib -lgstapp-0.10 -lgstvideo-0.10 -lgstbase-0.10 -lgstreamer-0.10 -lgobject-2.0 -lgmodule-2.0 -pthread -lrt -lgthread-2.0 -pthread -lrt -lxml2 -lusb-1.0 -lssl -lcrypto -lglib-2.0 -ldbus-c++-1 -ldbus-1 -ludev -lrt -lasound -l:libdbus-c++-glib-1.a -L./protobuf-2.6.1-arm/lib -lprotobuf -L./libunwind-1.2-rc1/lib -lunwind

Will post the final test code after i clean it up. It looks nasty from all that testing :D
 

·
Registered
Joined
·
60 Posts
Discussion Starter #8 (Edited)
The test code i used attached here ... (it wont allow me to copy c files thus renamed it to .txt)

Edit: (wrong info on the code comment ) the interface was set to 115200 (0x1c200) and not 9600

/* - set line encoding: here 9600 8N1
* 9600 = 0x2580 ~> 0x80, 0x25 in little endian
*/


unsigned char encoding[] = { 0x00, 0xc2, 0x01, 0x00, 0x00, 0x00, 0x08 };
rc = libusb_control_transfer(devh, 0x21, 0x20, 0, 0, encoding,
sizeof(encoding), 0);
 

Attachments

·
Registered
Joined
·
60 Posts
Discussion Starter #9
Almost done here. Just one last task. If google has blocked other apps from pushing data on the AA screen, how about pushing the text data as a separate layer on the AA headunit application ? Hi Trez, what do you think ?
 

·
Treveloper
Joined
·
528 Posts
Almost done here. Just one last task. If google has blocked other apps from pushing data on the AA screen, how about pushing the text data as a separate layer on the AA headunit application ? Hi Trez, what do you think ?
Ha! I didn't know you wrote it in c! That makes it way easy to write into AA but you're going to have to figure out the gstreamer text overlay feature yourself because I don't really know how to do it and here's some more answer I gave earlier http://mazda3revolution.com/forums/2014-2017-mazda-3-skyactiv-audio-electronics/122458-aio-all-one-tweaks.html#post2357098

If you do figure that out I'm sure you can do it all you have to do is make the text your data!
 

·
Registered
Joined
·
60 Posts
Discussion Starter #11
Ha! I didn't know you wrote it in c! That makes it way easy to write into AA but you're going to have to figure out the gstreamer text overlay feature yourself because I don't really know how to do it and here's some more answer I gave earlier http://mazda3revolution.com/forums/2014-2017-mazda-3-skyactiv-audio-electronics/122458-aio-all-one-tweaks.html#post2357098

If you do figure that out I'm sure you can do it all you have to do is make the text your data!
Thanks Trez. I am currently setting up a debug environment for Android Auto Headunit using your UBUNTU version of the headunit to test gstreamer text overlay but i seem to be encountering trouble establishing an ADB USB link between virtualbox ubuntu running windows 10 and a huwawei p9 phone with Android Auto. The link is active but becomes disconnected the moment i activate the headunit application. This used to work with a laptop with a lower windows version (win8) and an older phone (samsung).

In the meantime, one option i did is to play warning audios using the ALSA aplay whenever the tire pressure falls outside the desired range. This way i can use android auto while the speedometer.sh runs in the background and simply get the audio notifications while on android auto.

speedometer.sh polling starts right after bootup right ? This means i dont have to start the speedometer application to initiate the polling process before going straight to android auto right ?
 

Attachments

·
Treveloper
Joined
·
528 Posts
Thanks Trez. I am currently setting up a debug environment for Android Auto Headunit using your UBUNTU version of the headunit to test gstreamer text overlay but i seem to be encountering trouble establishing an ADB USB link between virtualbox ubuntu running windows 10 and a huwawei p9 phone with Android Auto. The link is active but becomes disconnected the moment i activate the headunit application. This used to work with a laptop with a lower windows version (win8) and an older phone (samsung).

In the meantime, one option i did is to play warning audios using the ALSA aplay whenever the tire pressure falls outside the desired range. This way i can use android auto while the speedometer.sh runs in the background and simply get the audio notifications while on android auto.

speedometer.sh polling starts right after bootup right ? This means i dont have to start the speedometer application to initiate the polling process before going straight to android auto right ?
Did you make sure to check your Hyper-V settings and everything?
sand yes it sstarts on boot called by /jci/scripts/stage_wifi.sh which is where all the apps' websocket connections are called from
 

·
Registered
Joined
·
60 Posts
Discussion Starter #13
Did you make sure to check your Hyper-V settings and everything?
sand yes it sstarts on boot called by /jci/scripts/stage_wifi.sh which is where all the apps' websocket connections are called from
ubuntu headunit side (hu_usb.cpp) reported an error: <usbdevice> responded with protocol ver 2

and then it exited.

Checking the code, it will continue of the protocol number is < 1.

I tried it with both phones, a huwawei and samsung, both returned same usb error code.
 

·
Registered
Joined
·
60 Posts
Discussion Starter #14 (Edited)
Did you make sure to check your Hyper-V settings and everything?
sand yes it sstarts on boot called by /jci/scripts/stage_wifi.sh which is where all the apps' websocket connections are called from
and the gstreamer textoverlay works :laugh2: Now to port this on the ARM version :)

Update:
I just need to toggle it on/off via the console controls :) One thing i noticed that the gstreamer pipeline crashes if the videofocus changes back to the infotainment. This happens if the code contiually sends a textoverlay data on the pipeline when the video player is already out of focus. Trez, May i know the function i could call to check if the AA screen is already out of video focus so that i can stop sending the overlay data ?
 

Attachments

·
Treveloper
Joined
·
528 Posts
and the gstreamer textoverlay works :laugh2: Now to port this on the ARM version :)

Update:
I just need to toggle it on/off via the console controls :) One thing i noticed that the gstreamer pipeline crashes if the videofocus changes back to the infotainment. This happens if the code contiually sends a textoverlay data on the pipeline when the video player is already out of focus. Trez, May i know the function i could call to check if the AA screen is already out of video focus so that i can stop sending the overlay data ?
OK do you want to call the function from the c++ or from the javasctript side?
In the c++ you get it from
Code:
bool MazdaCommandServerCallbacks::HasVideoFocus()
If you want to get it from the Javasctipt you are in luck because lmagder wrote you a function to get that from AA
Code:
hasAAVideoFocus()
 

·
Registered
Joined
·
1 Posts
Hello, I am a cx5 owner, this tire pressure work is very useful to me. But I won't compile the executable program in Linux. Can you send me a program installed with USB? Thank you!
 

·
Registered
Joined
·
26 Posts
Hi, I'm a Web Dev and I own a 124 Spider. Same software, I guess, since they share the infotainment system of the Mazda MX-5.

This is something I've been looking for, I always thought there should be readable variables already inside the system. Glad I found this thread, but I'd like to make it an app like the Speedometer app that you can open directly from the infotainment, as a custom application, not via AA.
I'm new to CASDK, though, and haven't checked it out, but I'm familiar with node.js and electron and very familiar with JS and creating web frontends and some UIs.

Unfortunately, it seems like the Redbear Labs BLE Mini isn't available anymore. And the RedBear Duo (Wi-Fi + BLE) is also sold out. Would this work with other BLE dongles as well?
 

·
Registered
Joined
·
26 Posts
And of course I totaly forgot that the OE TPMS sensors aren't bluetooth but 433 MHz. So unless someone can dig up usable codes to read the TPMS (I'm only beginning this journey), I'd have to use either a second set of bluetooth sensor caps (ew!) or ad a chip that intercepts and reads the 433 MHz sensors. When I'm going down that road, I'll probably try to also add other sensors, like oil pressure, oil temperature, boost, ...
 

·
Registered
Joined
·
26 Posts
A bit disappointed about not getting any response.

My app (see attached) is working in the simulator with a dependency on the speed value for testing, at the moment.
The bars change height and color to yellow and red depending on the offset from the setpoint.

Still trying to figure out the data side:
I got a BLE OBD2 adapter that's only somewhat reliable. I have a Bluno Nano (Arduino Nano with built-in BLE) but that's not connecting to the OBD2. So now I ordered a Readbear Labs/Particle board with built-in BLE/WiFi and I also got an Arduino Nano and an HM-10 BLE board. On top of that, since I'm not too happy with the OBD2, I ordered Bluetooth valve caps for testing (they are so ugly ...). The absolute best thing would be to receive the 433 MHz signals directly, but that seems to be extremely complicated.

I also found out about OBD2 adapters with a wired connection to an Arduino Nano, that could be the best solution with pre written code. What's still worrying me a little is having the OBD2 adapter pluged in all the time. Will it cause the car to run in diagnose mode? It's also a little bit annoying having it there in the footwell all the time.

As for the software, a few questions remain:
- Can I save settings when the car is turned off? Could I use the Arduino for storage (Can I write to it from the app or can I only read?)
The idea is to have a settings layer, for example on a track day I could put in different setpoints or I could set the value for warnings or the sensivity of the color change, ...

- Dealers/Garages can set the normal pressure for active sensor systems, right? Can I read that from the OBD2?

- How did you show the data from the board/USB in the speedometer app? Normally, you're subscribing like this:
this.subscribe(VehicleData.vehicle.speed, ...

I think I still need a little time/help on the data side.
 

Attachments

1 - 20 of 55 Posts
Top