T-vK / Electric-Unicycle-Interface

Arduino library to interface electric unicycles (e.g. read speed and temperature or change unicycle's settings) via Serial or Bluetooth
20 stars 3 forks source link

Bluetooth is collecting values and not HEX #5

Closed Jakub-prg closed 3 years ago

Jakub-prg commented 3 years ago

Hi T-vK,

first of all thank you for your effort here, it is really amazing what you did there.

I am trying to get this interface working with my Arduino - Gotway EUC. However, upon connection, bluetooth (HM-10 in master mode) is getting only "values", not HEX. I was wondering maybe you did something to receive only raw data rather than values which are anyway weird characters, or no character at all. I am really struggling here so I thought that you may have a quick answer how to change that behavior :)

Thank you a lot for your time, you are the best.

Jakub

T-vK commented 3 years ago

I don't understand. Is this a question about the library?

Jakub-prg commented 3 years ago

Yes... I think so. But if I am wrong, please correct me. What I think is that all the data are being collected by bluetooth module and received packets are being changed within the library from hex value to some character type like ascii... Is it so? Or when I think about it, actually the other way? That I need to force bluetooth adapter to receive Hex data rather than a "value" ?

T-vK commented 3 years ago

No, not really. You have to understand that binary, hex, decimal and ascii are just different methods to display the exact same data.

For example:

binary: 01100010
hex: 62
decimal: 98 
acsii: b

all of these values are identical. They are just represented in in different formats.

I'm not changing the data received from the EUC at all.

C++ for example uses the acsii representation for variables of the type char and decimal representation when using the type integer when printing the values.

E.g.

int myData = 0x62;
std::cout << myData;

prints 98.

char myData = 0x62;
std::cout << myData;

prints b.

Jakub-prg commented 3 years ago

Hi again. Thank you for this great hint. I am new in arduino/bluetooth and this is my first project. Now that I have couple of days of investigation behind me, it was a bit silly miskate on my side when I was trying to debug why your library is not writing any data to serial monitor. I am wondering if I may ask one more thing. How did you figure out where within the packet is the speed, distance etc and as a matter of fact in which packet 🤪 as there are couple being sent at the same time and then wait 200ms.Was there any official documentation available, or you just did reverse engineering? It seems that these new unicycles (i have Tesla2) are hugely different protocol for data and I will need to dig deep into that to find out those data that I need.

All in all your work in this library is really great, it helped me a lot in my progress. Would you mind if I would use parts of it? Not sure if that will happen, but if I would use something, I will mention ofcourse where it is from. I like the verification of received data. I find it very elegant really despite your comment 😁

Thank you for your effort and this amazing job.

Jakub

T-vK commented 3 years ago

There is no documentation that I'm aware of. I simply reverse engineered it by analyzing the data it sends. If you want to find out which part of the packet is the speed, you compare a packet that was sent while you were driving slow and anotber one while you were driving faster. You will quickly find a byte in the packet that always has a higher value when you drive faster and a lower value when you drive slower. Now you know which part of the packet is the speed. To find the distance you have to find a byte or maybe two bytes that always increase after you drove for a while, but never decreases.

Feel free to use, modify and republish the code however you like. Just read the disclaimer at the end of the readme.

Jakub-prg commented 3 years ago

Thank you a lot. I thought that this will wait me 😁

Have a nice day.

Jakub