Introduction
Send Moving Vehicle’s GNSS Position
via LTE using Raspberry Pi 4.
Hardware
·
Raspberry
Pi 4
·
‘SIM7600E-H
4G HAT’ module for Raspberry Pi - a 4G/3G/2G communication and GNSS
positioning module
‘SIM7600E-H
4G HAT’ module onboard a main LTE antenna connector, an auxiliary LTE
antenna connector and a GNSS antenna connector.
Contemplates
‘SIM7600E-H 4G HAT’ module features LTE
communication and GNSS reception, controlled using AT commands.
When acquiring GNSS position, current UTC time is
attached along with the GNSS coordinate.
Send vehicle GNSS positions every 1 minutes or 10
seconds period to web server, executed using ‘timer_sendTCP’
and separate thread ‘thread_timer_TCP’; Read
vehicle’s current GNSS position every 2 seconds period, executed using ‘timer_GPSPositioning’ and separate thread ‘thread_timer_GPS’. Use the acquired UTC time as the
timestamp for all the outgoing messages.
If current LTE environment, TCP setup, current
GPS environment or GPS setup not okay, close the TCP/GPS, wait awhile and
retry again. Send the error messages to web server and save to log file
using current UTC time as the timestamp.
To make sure at any moments only a single AT
command is sending to ‘SIM7600E-H 4G HAT’ module, use Mutex Lock
‘mutex_SIM7600’ to control the access of threads. Each AT commands have
different execution-times and maximum timeouts, therefore we will not know
when or what the next AT commands will be executing.
To temporarily store the vehicle GNSS positions
before bulk-send to web server, use shared linked-list ‘share_list_records_GPS_DateTime’.
Use mutex lock, ‘mutex_share_list_records’ to
make sure only a single thread is accessing the shared linked-list at a
time.

Source Code
1.
sudo
make clean
2.
sudo
make
3.
sudo
./AT
Raspbian c++: AT.cpp Makefile
References
SIM7600E-H 4G HAT
·
Official support website: https://www.waveshare.com/wiki/SIM7600E-H_4G_HAT
·
Raspberry SIM7600X source code folder: https://github.com/Edragon/RPI/tree/master/network/SIM7600X
·
SIM7600E-H 4G HAT User Manual: https://www.waveshare.com/wiki/File:SIM7600E-H-4G-HAT-Manual-EN.pdf
·
Raspberry Pi to Arduino Shields Connection Bridge
Installation Guide: https://www.cooking-hacks.com/documentation/tutorials/raspberry-pi-to-arduino-shields-connection-bridge
Topic: Increment One Second to a Given Date-Time
Our ‘SIM7600E-H 4G HAT’ module can
only able to receive GNSS UTC time every 2 seconds due to its limitation.
And the GNSS UTC time might not always be available, subject to outdoor
GNSS reception. Therefore, I wrote a function to increase current date-time
by 1 second when 1 second period software timer time-up. The 1 second
software timer (using Thread.Sleep() command)
will be declared in separate thread to avoid runtime delays from other
processes.
It is not a straight-forward matter to increase
current date-time by 1 second. Because there are different number of days
in each month.
·
January,
March, May, July, August, October and December months have 31 days.
·
April,
June, September and November months have 30 days.
·
February
month: 28 days in common years and 29 days in leap years. Leap years occur in each
year evenly divisible by 4, except for years evenly divisible by 100, which
are not leap years unless evenly divisible by 400.
Visual C++ code
increase_1s_to_DateTime.cpp
Topic: Given Two Date-Times, Find the Time Differences in Hours
We would like to
know the vehicle’s current speed, by using current & previous GPS
coordinates and UTC time.
Speed is traveling
distance divided by traveling time, unit in km/h. Having 2 GPS coordinates,
we can know the traveling distance using Haversine
formula. The traveling time will be the current UTC time minus the
previous UTC time, unit in hours.
Again, it is not so
straight-forward to find the time differences for the given two date-times.
Visual C++ code
Find_Time_Diff_2DateTimes.cpp
Optional Topic: Add Numerous Seconds to a Given Date-Time
Rather than add 1
seconds to a given Date-Time, add numerous seconds to a given Date-Time.
Visual C++ code
·
Using
jumper ‘goto’: AddSeconds.cpp
·
Using
‘while’ loop: AddSeconds_WhileLoop.cpp
|