eScooter IOT & Software Part 1 (RaspberryPi- Reading Information from Motor and Battery via Bluetooth)
Here we are again with an article about an R&D project that may interest you.. Our R&D topic is how to make escooter IOT, how to find it if not, how to integrate it, how to read data from the escooter, how to store and communicate, and how to write software that combines all these. etc etc.. Until today, I have shared with you the superficial technology of this and those who do it, but this time I am coming to the question of how we can do it..
First of all, let me share with you a conceptual picture of the system so that you can see it more clearly.
I have also seen technopark companies that make the infrastructure of such a system and give it to those who do it as a business, and they called me on time.
I finally decided to make it myself and share it with you.
As I shared a little below, you can also buy T… or Z… brand IOT cards where the entire solution is on a single card. My solutions here will be an ANALYTICAL approach based on R&D and the solution by dividing it into parts and finally getting the result by combining all the parts. It will also give you more ideas and the ability to take an engineering approach to many businesses and solutions other than scooters.
So much so that, as you will see in this and my other 2nd and 3rd article, you will see how we achieved a solution by solving Raspberry Pi + SIM808 + SmartLock (Smart Lock) solutions piece by piece and finally combining them. It will give more ideas..
I knew that I could do these things easily by purchasing the Xiaomi m365 brand escooter and I bought it from the internet. Our dear cat IRMA made the first quality control and approved it. !
First of all, if you pay attention, you will see a lock on the top of the vehicle and the IOT box on the bottom, whether it is Seagull or Bin-bin or others. The issue of how and where we connect them is also very important. You can see this by using the vehicles of these companies once. There are several regulations on this subject. .. Connecting the IOT device to the main board of the escooter.. Or accessing it via bluetooth BLE without connecting at all ..
There may even be those who connect the lock to the motherboard. For example, Bird company in the USA opens the lock via bluetooth.
On the other hand, I first worked on 2 arrangements according to Option 1. Here is how: I will buy my own IOT piece by piece, test and adjust it.. I bought the following (I will write where you can buy them from Turkey at the end of the article):
Raspberry Pi Zero W
Neo 6M GPS module
Let me give you some information about BlueTooth here so that there is no confusion. The Bluetooth we are talking about here is actually BLE and it is different from classical bluetooth.. So our device must support Bluetooth BLE.. Problems may arise with Bluetooth classic…
Raspberry Pi is a small computer and I installed the Raspian operating system on it.. Raspberry Pi Zero W has both BLE + Bluetooth classic and wifi support, so I chose it.. Connecting the Neo 6M GPS is easy too.. The 4-pin port was not soldered when I bought it. I soldered it and took the jumper cables and connected it to the raspberry pi. Again, there are connection and setup software for this on the internet with the raspberry pi.
I haven’t bought it yet (I have bought it in my 2nd article..) I will need SIM808 GSM/GPRS module for data transfer in 2G later on.. For now, I can easily do these tests with raspberry pi wifi..
My aim is to get information by connecting to Xiaomi m365 with BLE (Bluetooth Low Energy) technology on the raspberry pi or to get some values such as locking, battery level, turning on the tail lamp, turning it off, etc.
In addition, we will need to install MQTT client software on each of our IOTs, where we will need to install the MQTT client software in the raspberry pi, so that all our escooters can continuously transfer and receive data to the database in our main center .
Let’s say our hardware is not like this and you asked what kind of IOT is needed if we connect all of them directly to the machine with cables, not via bluetooth BLE? For example, you can buy and work from Quectel’s MC60-based Kits . The MC60 chip supports MQTT among other protocols and has commands we call AT. Instead of installing an MQTT client, you can work with AT commands directly there.
Or you can buy an IOT that is ready with everything.
Or there are Chinese made IOT cards that you can buy from China..
Unfortunately, since a lot of customs duties are imposed on purchases made from China, it has become a very expensive solution for R&D people like me to make these purchases.
At this stage, the most difficult task is to connect to the Bluetooth BLE module on the top of the Xiaomi m365 we have just bought and read the data. For this, raspberry pi uses the raspian operating system, which is a linux derivative, for this there is a library like bluepy and python is also used. There is also a tool called GATTTOOL . it’s also very useful..
Let’s talk about this: Escooters have 3 controls: Bluetooth BLE, Engine and Battery. . Some can even replace almost all of them with what they have done or had them do.
Connecting to Xiaomi m365 with bluepy library support and python software sometimes causes death.. It is impossible not to have problems. The problem is that I have 091 version of BLE controls, and the package protocol has been changed and encryption is supported.. I think they did it to prevent hacking events. You connect but you can’t read and there is not a single information about how to read it. I tried hard to overcome this and finally solved it.
After solving the BLE problem, it’s time for Services, Characteristics and descriptors in BLE. Learn this.. Service and characteristics are represented by UUID number and some are for read only and some for both read and write.. In our case, there are 2 characteristics and UUIDs. There are more.. Run GATTTOOL on the raspberry pi as follows, first connect to the BLE while the escooter is on:
To find out the MAC address of the Escooter
Type sudo hcitool lescan and hit enter.. It will list the Mac addresses of nearby BLE supported devices..
Before connecting, if you type the following from the linux command line, you can see all the characteristics of the BLE device to which you will connect and write the MAC address.
Type sudo gatttool -t random -b –device= ESCOOTER_MAC_ADRESI -I –characteristics and press enter
This time to connect to BLE..
Type sudo gatttool -t random -b ESCOOTER_MAC_ADRESI -I and press enter and the linux command line will change..
then type connect enter,
then type primary enter
and then enter char-desc
You can see them all here.. We only care about 6e400002-b5a3-f393-e0a9-e50e24dcca9e and 6e400003-b5a3-f393-e0a9-e50e24dcca9e and their handles ..
Here, the handle of 6e400002-b5a3-f393-e0a9-e50e24dcca9e is 0x000e and we send our data here privately and read the response of the scooter from 6e400003-b5a3-f393-e0a9-e50e24dcca9e, this is the event. In fact, I will specify 0100 notification handle below. If you print it, the result will come back to you as soon as you send data… If you code it more professionally with PYTHON software, except for GATTTOOL, then you will have to set the characteristic in notification with \0x01\0x00 as bytes .
If we type char-write-req 0xc 0100 and press enter, we will automatically receive a notification when we send data.
I’m making a note here, remember .. the notification event is this: We write code that will run in a continuous loop with python software or another software language at certain times. We make the notification ini true and we write the value above so that our handle notification code piece, which we also wrote in encoding, reads and informs us…So it is a kind of asynchronous process..
Now we will talk to the device with the protocol packet data that the device will understand to run with the device over BLE. For example, after connecting to the device in GATTTOOL
Send data with char-write-req 0x000e 55AA0320011A02BFFF
With char-read-uuid 6e400002-b5a3-f393-e0a9-e50e24dcca9e we also get
55AA0320011A02BFFF value is very important, let’s take a look at it:
The unchanging HEADER value, which is absolutely the same for the 55AA Xiaomi series, is at the beginning of each package.
03 The length of the data to be sent is + 2 in bytes.
A value of 20 means BLE to MOTOR
01 value means data will be read
The value of 1A 02 is what the main job is and it means give me the driver version..
The last BFFF is the checksum and it is obtained by XORing the other data except 55AA with a special byte value, you cannot write anything there by heart.. and the information can be as follows:
55aa0423011a340188ff So what does it mean.. Here the 3401 value is checked and it is 1.3.4 version..(interpret the bytes in reverse 01 before then 34..
Another example: If we send the value 55mm 04 2003 7d 0200 59ff, it will turn on the tail lamp on the tail of the scooter. Here, it means that I am sending (not receiving) to the engine controller of the 20 scooter, and 03 means SUMMER and the main command is 7d 02, so turn on the light. .. If it was 7d 00, it would turn off the light..
We do these little by little step by step and we also test whether each step works.
After this step, we do this by making a full program with the python programming language and BLUEPY library instead of GATTTOOL. Our aim is to gradually work on the Raspberry pi, which is the main part of the device’s IOT, and receive the data from the scooter via BLE and send the data via the MQTT client, which we will install on the Raspberry pi. We will transfer it to MQTT BROKER and from there to the central database or, if necessary, to read and use the data by other devices.
You can look on the internet for PYTHON software and examples..
Build each raspberry pi to MQTT client I’m thinking that mosquitto software is perfect and the server to be both client and also saw very well our job to establish brokers II .. My will build one from server side Linux or Windows operating systems other choice I have not decided what will be the weapon so so …. The MQTT client on the server side receives the data from my machine and prints it to the database, perhaps with an API, which would be the best. It is possible to write directly without the API, but it is more flexible and future-proof, even for use on mobile devices or for many other applications. ..
In other words, we do all the steps with the ANALYTICAL approach step by step until the end of the work. Then we assemble all the parts…
Flutter is my favorite of the Cross platform development environments for the mobile side, but we can also use Xamarin or React Native. However, Xamarin and React Native are not very secure software languages. I can do many things based on C#, including the API on the Windows side, easily.. It is even possible to easily do the API in LINUX using .NET Core..
As for the lock thing of Escooter.. Many companies use similar and same locks by buying them from China.. I ordered one from Germany, I will test it when I get close.. These can be opened via Bluetooth.. Mobile software can do this easily. .. (In my 3rd article, I brought this lock from Germany and explained how to install it in this project with HACK and CRACK)
The process goes like this on the mobile side.. Read QR code with mobile.. (the device has UNIQUE ID here and it is registered in the database, even it is set on each raspberry pi and each device knows its own ID..) communication with the API to the information center The transaction is started by installing it or sending it to MQTT Broker. The center processes the data into the database and sends information to the broker along with the device ID. After that, the process can be processed in two ways, or our mobile device can work as an MQTT client and the information from the broker with this ID can be used simultaneously with the device. This is the lock code and/or the order to unlock the scooter’s motor. The mobile device receives the lock password. The raspberry pi also receives the motor unlock command, and the lock is unlocked by clicking the automatic command from the mobile device to the lock.Then the mobile software is always on and the device’s BLE speaks and transmits data to the center with BLE, that is, Bluetooth. .
You can easily do all these tests without 2G GSM and wifi supported raspberry pi by keeping the escooter with you and without connecting it. It is even possible to use and test the raspberry pi outside by connecting your mobile device by hot spot sharing. If everything is ok, SIM808 or its You can buy card modules such as raspberry pi and connect them to raspberry pi easily.. it is enough for these types of cards to be 2G and support GPRS and / or GPS I … because it is possible to exchange data from the internet with 2G..
Those who want to buy IOT cards that can do all of these, should not forget some points, saying that I will be more effective by connecting directly to the controllers of the Escooter, not with the raspberry pi.
Escooter is important. Be sure to learn about this IOT issue and the package protocol details of the Escooter with the manufacturer you bought it from.
Can you make a direct connection with the IOT you will buy to these scooters, if necessary, do the tests with the manufacturer..
For this, you can buy the test escooter and test IOT card and test and develop yourself.
It is important that the Escooter’s battery is replaceable. If so, consider such a vehicle.
So where can we get the parts mentioned here? You can buy Raspberry pi and NEO 6M GPS module from SAMM market from the internet, a Turkish company.. You can buy Quectel IOT kits or modules from empastore as a Turkish company. So you don’t need to buy it from China.. Xiaomi m365 can be bought from anywhere.. Needeyse all this Companies that do the job have this brand in their fleets and it is a very ideal tool for doing this kind of R&D.
Another point I should add here is this: I laugh at the guys who say that this kind of IOT and their jobs are hidden from me and we don’t share our technology etc etc. I didn’t write that it would be okay.. Your box is on the device, that is, the one who opens the box and sees what is inside and then technology remains, so what are you hiding..
I also wrote this article so that anyone who wants to do it.. You don’t need to establish a company in a technopark, etc., to do the infrastructure or R&D of this business.. If you add up, I spent a maximum of 5000 TL with the escooter. It would be great, right?