eScooter IOT & Software Part 2 (GSM&GPRS connection)
Welcome to Phase 2 of eScooter IOT and software development..
I am sharing the picture that I shared in the first phase, showing the conceptual design of the system, so that you can understand it more clearly.
In the first phase, we saw that we were able to access all the controls of the Xiaomi m365 via Bluetooth BLE with the Raspberry pi Zero W and get all the information we wanted. As I mentioned in that article, the 1st and 2nd phases were actually made to produce a single solution. In the 2nd phase, instead of WIFI, MQTT broker I made the solution of connecting to (server) with GSM GPRS . I needed a GSM module for this and it would support GSM/GPRS/GNSS as 2G.
I chose SIM808 as GSM module in this phase … (IMEI registered)
The pins of Raspberry Pi I need are Ground, Power, TX and RX. Accordingly, I connected TX to SIM808’s RX and RX to SIM808’s TX and ground and power to the right place on Raspberry Pi, as in the picture. Since the sim card I have is nano and SIM808 wants a Standard SIM card, I went and bought dialers cut from a GSM dealer and easily converted my card to standard and inserted it into the slot on the back of the SIM808..
In the pictures above, the left one is SIM808 and the smaller one on the right is Raspberry pi Zero W.
There is a small button on the card to use, and you have to press it for 2 seconds and remove it so that it starts working. There are 3 LEDs between the GPS and Bluetooth antennas. These are NET, PPS and STA. Normally, NET and STA are lit for me. PPS never lights up. However, this led is completely because we did not power on the GPS/GNSS with AT commands. I will not do anything about GNSS. Depending on the process, the .NET light either flashed or flashed every 3 seconds. They explained it a little differently, but I look at the result..
You can connect the two with a special link and make it this way.
First of all, I wanted to do a test and send SMS, for this I wanted to use SIM808’s AT commands. For this, I installed the minicom software on the raspberry pi and with the appropriate parameters:
sudo minicom –D /dev/ttyS00 –b 9600 –o
I connected with and :
AT+CMGF=1
AT+CMGS=”+90533xxxxxxx”
test message selcuk
I sent my message as follows and I was successful without any problems.
Even if this card and chip do not natively support MQTT, you can still send and read the appropriate data with AT commands and by preparing it as HEX, which is really difficult. MQTT broker. Then, if you want to use it, then the best thing is to connect to serial0 instead of minicom with c++ or python, send AT commands and read the returned response values.
Now our main event is to go to the internet using this card and GPRS .. The most key point for this is.. In the meantime, we are either connected to our notebook via USB or directly connected to the home or office network via wifi.. I am talking about our raspberry pi.. There, we will connect to SIM808 via UART, that is, ttyS0, that is, serial0.. and from there we will go to the Internet as if. look.. then type route -n and look at the route a followed by the metrics…. In fact, type sudo traceroute www.turkiye.gov.tr and you’ll see where the route comes from. So I wonder if we’re going to define a route too ?
Yes, but even if we define it, it does not go over this serial connection with the IP number. What will we do?
We need to use PPP protocol and connect point-to-point over serial. One point is us and the other is SIM808..
We are installing PPP… Find out how to install it on raspberry.. Then you will see that we can turn it ON or Off whenever we want.. We did it but it will not be enough.. You will see that it will not follow this path while still going to the internet.. Then, after turning PPP ON and opening it, read the syslog with the cat command. It will have the endpoint IP of the place where it connects via PPP. Of course, there is also an IP that it gives to SIM808, starting with 10.. In my case, this gateway endpoint was 192.168.254.254..
sudo /sbin/route add -net 0.0.0.0 gw 192.168.254.254 ppp0
I added this with .. Veeee I removed the cable of my other Fiber internet from the device so I will see if it can access the internet .. Yes.!
And then on my MOSQUITTO MQTT server or Broker that I set up on one of my own servers abroad:
mosquitto_sub -h 213.XXX.XXX.XX -t test
I signed up to the topic named test by entering, so I say listen there..
Then I opened another session from raspberry with putty and logged in as the second user and this time
I typed mosquitto_pub -h 213.XXX.XXX.XX -t test -m “Hello” and it instantly captured the message from the other open screen and showed it..
In the same way, the eScooter IOT device becomes a member of a topic on the MQTT broker or server and sees all the messages coming to this topic. that scooter will also send or if it is called lock, it will execute the order immediately. Other scooters will also see this message, but they will not take any action because they have not received it.
We software engineers can easily set such rules and data protocol rules and conventions.
So far, we have seen that we can do everything that the eScooter IOT can do by using the Raspberry Pi Zero W + GPS antenna + SIM808 card. Those who wish can make these cards durable in IP65 or 67 standards by having a special box made and attach them to the device. We have one missing lock, which is Germany. I’ve been close to it, but since I haven’t received it, I haven’t done the testing and integration tests yet..
The thing to do here is to focus entirely on the software.. To reach the whole solution by combining these parts..
MQTT Broker / Server must be installed..
To write a complete software that reads MQTT and sends data to Raspberry Pi with software that reads escooter brain via bluetooth BLE with python or C or C++.
Establishing a SQL Server that can be MYSQL in the main center and making tables etc. that will enable it to process the data coming from MQTT appropriately
By installing the main management software, connecting to MQTT, sending and receiving data, processing to the database and writing the codes for all other management.
To make an API for mobile software that will communicate with the database and/or talk directly to MQTT and the software that will talk to the escooter via direct bluetooth BLE.
Maybe, after this article, I can share with you a full integration of the system with all its components, with pictures and details.
Stay well…
Selcuk Celik