Good day!
I'm trying to create a python script for a Telit GM862-GPS that would retrieve GPS information every 1 second, split the gpsacp information and store the speed in km/h gps information to a variable.
then would call a method that would perform an If..Else statement that would check if the speed retrieved is over the speed limit i have set.
now here's the problem, it calls the method, perform If..else BUT produces a wrong answer.
For example, the speed i retrieved is 10.25 i would compare it to the speed limit that is set to 30
if currentspeed > speedlimit:
print ('over the limit')
else:
print ('not over the limit')
it always prints "over the limit", meaning the currentspeed is > speedlimit.
i did a simple test to the currentspeed variable.
i tried:
a = currentspeed * 10
when i print a, instead of displaying 102.5 (if the currentspeed is 10.25), it displays, : "10.2510.2510.2510.2510.2510.2510.2510.2510.2510.25"
i think theres the problem.
i tried explicitly casting it to either float or int by:
int(currentspeed) or float(currentspeed)
it compiles with no problem (.pyo)
but when i run it at the Telit GM862-GPS, whenever it reaches the point the it would cast the currentspeed to either a int or float, it hangs.
any solutions?
thanks

##### Constants #####
TRUE = 1
FALSE = 0
LOOP = 1
##### Modules #####
#Use serial
import SER
#Use build in module
import MOD
#Use AT command interface
import MDM
#Use GPS
import GPS
###### General Functions ######
#Debug message
def debugmsg(msgtext):
msgtext = msgtext.replace('\r', '\\r')
msgtext = msgtext.replace('\n', '\\n')
print msgtext
SER.send(msgtext + '\r\n')
#f = open('log.txt','ab')
#f.write(msgtext + '\n')
#f.close()
#GPS status
def gps_status(gpspos):
debugmsg('Retrieving GPS status')
gpspos_parts = gpspos.split(',')
if ( (gpspos_parts[5] == '2') or (gpspos_parts[5] == '3') ): #2D or 3D fix
#debugmsg('GPS fix "' + gpspos_parts[5] + '" ie valid');
status = TRUE
else:
#debugmsg('GPS fix "' + gpspos_parts[5] + '" ie not valid');
status = FALSE
return status
def check_if_over(currentspeed):
limit = 30
debugmsg('set limit to 10')
tempspeed = int(currentspeed)
if tempspeed > limit:
debugmsg('NOT OVER LIMIT')
else:
debugmsg('OVER THE LIMIT')
def testspeed(gpspos):
debugmsg('Test if speed is over limit')
if (gps_status(gpspos) == TRUE):
debugmsg('Has GPS Fix')
gpsdataparts = gpspos.split(',')
currentspeed = gpsdataparts[7]
debugmsg('Speed is ' + gpsdataparts[7])
check_if_over(currentspeed)
else:
debugmsg('Has NO GPS Fix to be tested for overspeeding')
##################################################################################
###### Init ######
SER.set_speed('115200','8N1')
SER.send('\r\n--------------------\r\n\r\n')
debugmsg('Running...');
#Set verbose error reporting
MDM.send('AT+CMEE=2\r', 0)
MDM.receive(50)#5 sec
MOD.sleep(1)#wait 0.1sec
#Main loop
while (LOOP==1):
debugmsg('Entering loop')
#Retrieve current position
gpspos = GPS.getActualPosition()
debugmsg('Position: %s' % gpspos)
#Retrieve GPS fix status
gps_statusnow = gps_status(gpspos)
#Save last valid position
#If position fix valid, or none recorded already, use last retrieved
if ( (gps_statusnow == TRUE) or (gps_statusnow == FALSE) ):
testspeed(gpspos)
MOD.powerSaving(1)