示例#1
0
 def initSMS(self):
     smsStatus = "SMS Status Default"
     while True:
         ser.write(b'AT+CMGF=1\r')  # Set SMS mode to TEXT
         smsStatus = ser.readline()
         if b'OK' in smsStatus:
             print(b'SMS status is ' + smsStatus)
             return True
         if b'ERROR' in smsStatus:
             trackerUtils.writeToFile(piLog,
                                      (("SMS status is " + smsStatus)))
             ser.write(b'AT+CMGF=1\r')
         time.sleep(1)
示例#2
0
 def checkFONA(self):
     # SETUP SERIAL MODEM FOR PI/FONA
     while True:
         ser.write(b'AT\r')
         fonaStatus = ser.readline()
         if b'OK' in fonaStatus:
             print(b'The FONA is ' + fonaStatus)
             return True
         if b'ERROR' in fonaStatus:
             trackerUtils.writeToFile(piLog,
                                      ("FONA status is " + fonaStatus))
             print(b'The FONA is ' + fonaStatus)
     return True
示例#3
0
 def getGPS(self):
     print("Getting GPS Data\r")
     while True:
         ser.write(b'AT+CGNSINF \r')
         global gpsCoord
         gpsCoord = ser.readline()
         if b'+CGNSINF: ' in gpsCoord:  # 1 = gps fix, 0 = no fisx
             print(gpsCoord)
             return gpsCoord
             return True
         if b'ERROR' in gpsCoord:
             trackerUtils.writeToFile(piLog,
                                      ("Error in GPS Coord: " + gpsCoord))
             ser.write(b'AT+CGNSINF=0\r')
 def initSMS(self):
     #ser.open()
     smsStatus = "SMS Status Default"
     print("init SMS")
     while True:
         ser.write(b'AT+CMGF=1\r')  # Set SMS mode to TEXT
         smsStatus = ser.readline()
         if b'OK' in smsStatus:
             print('SMS status is ' + smsStatus.decode() +
                   ". Modem set to text mode")
             trackerUtils.writeToFile(
                 piLog, 'SMS status is ' + smsStatus.decode() +
                 " Modem set to text mode")
             return True
         if b'ERROR' in smsStatus:
             trackerUtils.writeToFile(
                 piLog, (("SMS status is " + smsStatus.decode())))
             ser.write(b'AT+CMGF=1\r')
         time.sleep(1)
示例#5
0
 def openGPS(self):
     print("Turning on the GPS\r")
     ser.write(b'AT+CGNSPWR=1\r')  # Turn on the GPS
     time.sleep(1)
     # Check GPS power status is ON!
     while True:
         ser.write(b'AT+CGNSPWR?\r')
         gpsPower = ser.readline()
         if b'1' in gpsPower:
             print("GPS is powered on")
             return True
         else:
             print("GPS has no power")
             print("GPS is off. Turning on...")
             trackerUtils.writeToFile(piLog, ("GPS status is " + gpsPower))
             ser.write(b'AT+CGNSPWR=1')  # Power on GPS module
     time.sleep(0.5)
     ser.write(b'AT+CGNSRST=1\r')  # GPS reset set to hot start mode
     return True
示例#6
0
    def convertGPS(self, gpsV1):
        global deg
        deg = chr(37)
        array = gpsV1.split(b',')
        #### Format from DDMM.MMMMMM to DD MM.MMMMMM
        # Latitude
        global latDeg
        global latMin
        lat = array[1]  # text array pull latitude from input
        latDeg = int(float(lat) / 100)  # Retrieves DD
        latMin = float(lat) - latDeg * 100
        latMin = latMin / 60
        latitude = latDeg + latMin
        latitude = str(latitude)
        print(latitude + " is decimal degree latitude")

        # Longitude
        global lonDeg
        global lonMin
        lon = array[2]  # text array pulling longitude
        lonDeg = int(float(lon) / 100)
        lonMin = float(lon) - lonDeg * 100
        lonMin = lonMin / 60
        longitude = lonDeg + lonMin
        longitude = str(longitude)
        print(longitude + " is decimal degree longitude")

        # Altitude
        global alt
        alt = array[3]
        print('GPS Altitude is ' + alt.decode())

        # Time UTCGetting
        global utc
        utc = array[4]
        print('UTC time is ' + utc.decode())

        # Speed in knots
        global speed
        speed = array[7]
        print('speed in knots is ' + speed.decode())

        # Heading in Degrees
        global heading
        heading = array[8]
        print('Heading is ' + heading.decode() + ' degrees')

        # Write parsed GPS to Log file
        gpsMsg1 = (latitude + "," + longitude +
                   " Fix Coords in Decimal Degree")
        trackerUtils.writeToFile(piLog, gpsMsg1)
        gpsMsg2 = (b'Altitude: ' + alt + b' meters, Speed: ' + speed +
                   b' knots, Heading: ' + heading + b' Time: ' + utc + b' UTC')
        trackerUtils.writeToFile(piLog, str(gpsMsg2))

        # Google Maps link
        global gMapsLink
        gMapsLink = ("https://www.google.com/maps/@" + latitude + "," +
                     longitude)
        print(gMapsLink)
        return [
            alt.decode(),
            utc.decode(),
            speed.decode(),
            heading.decode(), latitude, longitude
        ]
class fonaSMS(object):
    global ctrlZ
    ctrlZ = chr(26)

    global ser
    global piLog
    print("setup SMS Serial")
    ser = trackerUtils.openSerialPort()
    print("Connected to " + ser.name + "\r")
    piLog = "piTracker-" + str(time.time()) + ".log"
    trackerUtils.initFile(piLog)
    print("SMS serial complete")
    trackerUtils.writeToFile(piLog, "Connected to " + ser.name)

    ##    #serial setupGPS
    ##    ser = serial.Serial(
    ##    "/dev/serial0",
    ##    baudrate=115200,
    ##    parity=serial.PARITY_NONE,
    ##    stopbits=serial.STOPBITS_ONE,
    ##    bytesize=serial.EIGHTBITS,
    ##    timeout = 1,)

    # CHECK FONA
    def checkFONA(self):
        # SETUP SERIAL MODEM FOR PI/FONA
        #ser.open()
        while True:
            ser.write(b'AT\r')
            fonaStatus = ser.readline()
            if b'OK' in fonaStatus:
                print(b'The FONA is ' + fonaStatus)
                return True
            if b'ERROR' in fonaStatus:
                trackerUtils.writeToFile(piLog,
                                         ("FONA status is " + fonaStatus))
                print(b'The FONA is ' + fonaStatus)
        #ser.close()
        return True

    def initSMS(self):
        #ser.open()
        smsStatus = "SMS Status Default"
        print("init SMS")
        while True:
            ser.write(b'AT+CMGF=1\r')  # Set SMS mode to TEXT
            smsStatus = ser.readline()
            if b'OK' in smsStatus:
                print('SMS status is ' + smsStatus.decode() +
                      ". Modem set to text mode")
                trackerUtils.writeToFile(
                    piLog, 'SMS status is ' + smsStatus.decode() +
                    " Modem set to text mode")
                return True
            if b'ERROR' in smsStatus:
                trackerUtils.writeToFile(
                    piLog, (("SMS status is " + smsStatus.decode())))
                ser.write(b'AT+CMGF=1\r')
            time.sleep(1)
        #ser.close()

    # Send SMS
    def sendSMS(self, recipient, message):
        #ser.open()
        try:

            def get_num(x):
                return str("".join(ele for ele in x if ele.isdigit()))

            print("called Send SMS")
            print("sending SMS")
            ser.write(('AT+CMGS="%s"\r' % recipient).encode())
            time.sleep(1)
            print("The message being sent is " + message)  # Wait for prompt
            ser.write(message.encode())
            ser.write(chr(26).encode())  # Exit message write and send
            time.sleep(1)
            sendStatus = ser.readlines()
            print("Send status is ")
            for line in sendStatus:
                print(line)
            if b'+CMGS' in sendStatus:
                print("Success: SMS sent!")
            else:
                print("Error: SMS not sent!")

    # except:
    #     print("Error: Something else failed!")
    #     trackerUtils.writeToFile(piLog, "Error: Something else failed!")
        finally:
            ser.__del__()
示例#8
0
    def convertGPS(self, gpsV1):
        global deg
        deg = chr(37)
        array = gpsV1.split(b',')
        #### Format from DDMM.MMMMMM to DD MM.MMMMMM
        # Latitude
        global latDeg
        global latMin
        lat = array[1]  # text array pull latitude from input
        floatLat = float(lat)  # text to float
        floatLat = floatLat / 100  # float math
        strLat = str(floatLat)  # DD to string
        arrayLat = strLat.split(".")  # split string along .
        latDeg = arrayLat[0]  # DD array member
        latDeg = float(latDeg)
        latMin = arrayLat[1]  # MMMMMM array member
        latMin = float(latMin)  # str to float
        latMin = latMin / 60
        latMin = latMin / 10000
        latitude = latDeg + latMin
        latitude = str(latitude)
        print(latitude + " is decimal degree latitude")

        # Longitude
        global lonDeg
        global lonMin
        lon = array[2]  # text array pulling longitude from ,,,
        floatLon = float(lon)  # text to float
        floatLon = floatLon / 100  # float math
        strLon = str(floatLon)
        arrayLon = strLon.split(".")  # split DDMM.MMMM to DD.MMMMMMM along .
        lonDeg = arrayLon[0]  # lonDeg = DD
        lonDeg = float(lonDeg)
        lonMin = arrayLon[1]  # lonMin = MMMMMM
        lonMin = float(lonMin)  # str to float
        lonMin = lonMin / 60
        lonMin = lonMin / 10000
        longitude = lonDeg + lonMin
        longitude = str(longitude)
        print(longitude + " is decimal degree longitude")

        # Altitude
        global alt
        alt = array[3]
        print(b'GPS Altitude is ' + alt)

        # Time UTC
        global utc
        utc = array[4]
        print(b'UTC time is ' + utc)

        # Speed in knots
        global speed
        speed = array[7]
        print(b'speed in knots is ' + speed)

        # Heading in Degrees
        global heading
        heading = array[8]
        print(b'Heading is ' + heading + b' degrees')

        # Write parsed GPS to Log file
        gpsMsg1 = (latitude + "," + longitude +
                   " Fix Coords in Decimal Degree")
        trackerUtils.writeToFile(piLog, gpsMsg1)
        gpsMsg2 = (b'Altitude: ' + alt + b' meters, Speed: ' + speed +
                   b' knots, Heading: ' + heading + b' Time: ' + utc + b' UTC')
        trackerUtils.writeToFile(piLog, str(gpsMsg2))

        # Google Maps link
        global gMapsLink
        gMapsLink = ("https://www.google.com/maps/@" + latitude + "," +
                     longitude)
        print(gMapsLink)
        return gMapsLink

        # Close GPS
        def closeGPS():
            ser.write(b'AT+CGNSPWR=0')  # Probably won't need, but hey...
            ser.close()