Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
forked fromCivlo85/gsmHat

Using the Waveshare GSM/GPRS/GNSS Hat for Raspberry Pi with Python

License

NotificationsYou must be signed in to change notification settings

kalutep/gsmHat

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

With gsmHat, you can easily use the functionality of the Waveshare GSM/GPRS/GNSS HAT for Raspberry Pi (Link to HAT). On this module a SIM868 Controller is doing the job to connect your Raspberry Pi with the world just by using a sim card.

Update on Wed Oct 21st, 2020

👉 Internet functionality added!

Overview

gsmHat was written for Python 3. It provides the following features

  • Non-blocking receiving and sending SMS in background
  • Non-blocking calling
  • Non-blocking refreshing of actual gps position
  • Non-blocking URL Call and receiving of response

Usage

In the following paragraphs, I am going to describe how you can get and use gsmHat for your own projects.

Getting it

To download gsmHat, either fork this github repo or simply use Pypi via pip.

$ python3 -m pip install -U gsmHat

Prepare

  • Install your sim card in your module, connect the GSM and the GPS antennas and mount the module on the pin headers of your Raspberry Pi. Make sure, that youdo not need to enter Pin Code to use your card. Pin Codes are not supported yet.

  • Enable the Uart Interface in your Raspberry Pi

    1. Start raspi-config:sudo raspi-config.
    2. Select option 5 - interfacing options.
    3. Select option P6 - serial.
    4. At the promptWould you like a login shell to be accessible over serial? answer 'No'
    5. At the promptWould you like the serial port hardware to be enabled? answer 'Yes'
    6. Exit raspi-config and reboot the Pi for changes to take effect.

Using it

  1. Import gsmHat to your project
fromgsmHatimportGSMHat,SMS,GPS
  1. Init gsmHat
gsm=GSMHat('/dev/ttyS0',115200)
  1. Check, if new SMS are available in your main loop
# Check, if new SMS is availableifgsm.SMS_available()>0:# Get new SMSnewSMS=gsm.SMS_read()# Do something with it
  1. Do something with your newly received SMS
# Get new SMSnewSMS=gsm.SMS_read()print('Got new SMS from number %s'%newSMS.Sender)print('It was received at %s'%newSMS.Date)print('The message is: %s'%newSMS.Message)
  1. You can also write SMS
Number='+491601234567'Message='Hello mobile world'# Send SMSgsm.SMS_write(Number,Message)
  1. Or you can call a number
Number='+491601234567'gsm.Call(Number)# This call hangs up automatically after 15 secondstime.sleep(10)# Wait 10 seconds ...gsm.HangUp()# Or you can HangUp by yourself earliergsm.Call(Number,60)# Or lets change the timeout to 60 seconds. This call hangs up automatically after 60 seconds
  1. Lets see, where your Raspberry Pi (in a car or on a motocycle or on a cat?) is positioned on earth
# Get actual GPS positionGPSObj=gsm.GetActualGPS()# Lets print some valuesprint('GNSS_status: %s'%str(GPSObj.GNSS_status))print('Fix_status: %s'%str(GPSObj.Fix_status))print('UTC: %s'%str(GPSObj.UTC))print('Latitude: %s'%str(GPSObj.Latitude))print('Longitude: %s'%str(GPSObj.Longitude))print('Altitude: %s'%str(GPSObj.Altitude))print('Speed: %s'%str(GPSObj.Speed))print('Course: %s'%str(GPSObj.Course))print('HDOP: %s'%str(GPSObj.HDOP))print('PDOP: %s'%str(GPSObj.PDOP))print('VDOP: %s'%str(GPSObj.VDOP))print('GPS_satellites: %s'%str(GPSObj.GPS_satellites))print('GNSS_satellites: %s'%str(GPSObj.GNSS_satellites))print('Signal: %s'%str(GPSObj.Signal))
  1. Calculate the distance between two Points on earth
GPSObj1=GPS()# You can also use gsm.GetActualGPS() to get an GPS objectGPSObj1.Latitude=52.266949# Location of Braunschweig, GermanyGPSObj1.Longitude=10.524822GPSObj2=GPS()GPSObj2.Latitude=36.720005# Location of Manavgat, TurkeyGPSObj2.Longitude=31.546094print('Distance from Braunschweig to Manavgat in metres:')print(GPS.CalculateDeltaP(GPSObj1,GPSObj2))# this will print 2384660.7 metres
  1. Call URL to send some data
# Init gsmHatgsm=GSMHat('/dev/ttyS0',115200)# Set the APN Connection data. You will get this from your provider# e.g. German Provider 'Congstar'gsm.SetGPRSconnection('internet.telekom','congstar','cs')# Get actual GPS positionGPSObj=gsm.GetActualGPS()# Build url string with dataurl='www.someserver.de/myscript.php'url+='?time='+str(int(GPSObj.UTC.timestamp()))url+='&lat='+str(GPSObj.Latitude)url+='&lon='+str(GPSObj.Longitude)url+='&alt='+str(GPSObj.Altitude)gsm.CallUrl(url)# Send actual position to a webserver
  1. Get the Response from a previous URL call
# Check, if new Response Data is availableifgsm.UrlResponse_available()>0:# Read the ResponsenewResponse=gsm.UrlResponse_read()# Do something with it

What will come in the future?

  • More options to configure the module (e.g. using sim cards with pin code)

On which platform was gsmHat developed and tested?

Hardware:

Software:

  • Raspbian (Codename: buster, Release: 10)
  • Kernel: Linux 5.4.51-v7l+
  • Python: 3.7.3

License

MIT License

Copyright (c) 2020 Tarek Tounsi

Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.

contact me:software@tounsi.de

About

Using the Waveshare GSM/GPRS/GNSS Hat for Raspberry Pi with Python

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python100.0%

[8]ページ先頭

©2009-2025 Movatter.jp