if _use_sms_alert: PIN = json_array["alert_conf"]["pin"] contact_sms = json_array["alert_conf"]["contact_sms"] gammurc_file = json_array["alert_conf"]["gammurc_file"] if (libSMS.gammurcCheck(gammurc_file)): print "Alert by SMS is ON. Contact SMS is ", print contact_sms print "Initializing gammu for SMS" else: print "overriding use_sms to false" _use_sms_alert = False if _use_sms_alert: if (libSMS.phoneConnection(gammurc_file, PIN) == None): print "overriding use_sms to false" print "Sending SMS failed" _use_sms_alert = False else: sm = libSMS.phoneConnection(gammurc_file, PIN) if _use_sms_alert : print "post_processing_gw.py sends SMS indicating that gateway has started post-processing stage..." success = libSMS.send_sms(sm, "Gateway "+_gwid+" has started post-processing stage", contact_sms) if (success): print "Sending SMS done" sys.stdout.flush() #------------------------------------------------------------ #for handling images #------------------------------------------------------------
try: gammurc_file = key_WAZIUP_SMS.gammurc_file except AttributeError: gammurc_file = "/home/pi/.gammurc" #check Gammu configuration if (not libSMS.gammuCheck()): print 'CloudWAZIUP_SMS: Gammu is not available' sys.exit() else: if (not libSMS.gammurcCheck(gammurc_file)): print 'CloudWAZIUP_SMS: gammurc file is not available' sys.exit() if (libSMS.phoneConnection(gammurc_file, key_WAZIUP_SMS.PIN) == None): print 'CloudWAZIUP_SMS: Can not connect to cellular network' sys.exit() else: sm = libSMS.phoneConnection(gammurc_file, key_WAZIUP_SMS.PIN) # main # ------------------- # mainly a replication of the CloudWAZIUP.py code def main(ldata, pdata, rdata, tdata, gwid): #this is common code to process packet information provided by the main gateway script (i.e. post_processing_gw.py) #these information are provided in case you need them arr = map(int, pdata.split(','))
def store_gps_coordinate(src, SNR, RSSI, seq, bc, lat, lgt, fxt, tdata, gwid): #------------------------------------------------------------ #open gateway_conf.json file #------------------------------------------------------------ gwconf_filename = "gateway_conf.json" f = open(os.path.expanduser(gwconf_filename),"r") lines = f.readlines() f.close() array = "" #get all the lines in a string for line in lines : array += line #change it into a python array gw_json_array = json.loads(array) try: _gw_lat = gw_json_array["gateway_conf"]["ref_latitude"] except KeyError: _gw_lat = "undef" try: _gw_long = gw_json_array["gateway_conf"]["ref_longitude"] except KeyError: _gw_long = "undef" try: gw_lat = float(_gw_lat) except ValueError: _gw_lat = "undef" try: gw_long = float(_gw_long) except ValueError: _gw_long = "undef" if (_gw_lat=="undef") or (_gw_long=="undef"): print 'GPS file: gw has no valid GPS coordinate' distance=-1 else: # gw pA = (gw_lat, gw_long) pB = (float(lat), float(lgt)) distance = haversine(pA, pB) #create the .csv file. First line is for the gateway's position #use for instance https://www.gpsvisualizer.com/ if not os.path.isfile(os.path.expanduser(_gps_csv)): f = open(os.path.expanduser(_gps_csv),"a") data = 'name,time,desc,symbol,latitude,longitude' f.write(data+'\n') data = 'GW,,gateway,wedge,'+_gw_lat+','+_gw_long f.write(data+'\n') f.close() #add the new position in the csv file f = open(os.path.expanduser(_gps_csv),"a") data = 'gps'+src+','+tdata+',"'+str(bc)+'('+str("%.3f" % distance)+'km)",googlemini,'+lat+','+lgt f.write(data+'\n') f.close() #open gps file to store the GPS coordinate and the calculated distance f = open(os.path.expanduser(_gps_file),"a") data = 'src '+src+' seq '+str(seq)+' bc '+str(bc)+' snr '+str(SNR)+' rssi '+str(RSSI)+' time '+tdata+' gw '+gwid+' fxt '+fxt+' lat '+lat+' lgt '+lgt+' distance '+str("%.4f" % distance) f.write(data+'\n') f.close() print 'GPS file: lat='+lat print 'GPS file: lgt='+lgt print 'GPS file: d='+"%.4f" % distance #update the list of remote GPS device #information from device older than key_GpsFile.active_interval_minutes will be marked not active update_gps_device(src, SNR, RSSI, seq, bc, lat, lgt, fxt, str("%.4f" % distance), tdata, gwid) if (key_GpsFile.SMS==True): try: gammurc_file=key_GpsFile.gammurc_file except AttributeError: gammurc_file="/home/pi/.gammurc" print 'GPS file: SMS is requested' #check Gammu configuration if (not libSMS.gammuCheck()): print 'GPS file: Gammu is not available' sys.exit() else: if (not libSMS.gammurcCheck(gammurc_file)): print 'GPS file: gammurc file is not available' sys.exit() if (libSMS.phoneConnection(gammurc_file, key_GpsFile.PIN) == None): print 'GPS file: Can not connect to cellular network' sys.exit() else: sm = libSMS.phoneConnection(gammurc_file, key_GpsFile.PIN) print "GPS file: Sending SMS" success = libSMS.send_sms(sm, data, key_GpsFile.contacts) if (success): print "GPS file: Sending SMS done"
def store_gps_coordinate(src, SNR, RSSI, seq, bc, lat, lgt, fxt, tdata, gwid): try: _gw_lat = gw_json_array["gateway_conf"]["ref_latitude"] except KeyError: _gw_lat = "undef" try: _gw_long = gw_json_array["gateway_conf"]["ref_longitude"] except KeyError: _gw_long = "undef" try: gw_lat = float(_gw_lat) except ValueError: _gw_lat = "undef" try: gw_long = float(_gw_long) except ValueError: _gw_long = "undef" if (_gw_lat == "undef") or (_gw_long == "undef"): print 'GPS file: gw has no valid GPS coordinate' distance = -1 else: # gw pA = (gw_lat, gw_long) pB = (float(lat), float(lgt)) distance = haversine(pA, pB) #open gps file to store the GPS coordinate and the calculated distance f = open(os.path.expanduser(_gps_file), "a") data = 'src ' + src + ' seq ' + str(seq) + ' bc ' + str( bc ) + ' snr ' + str(SNR) + ' rssi ' + str( RSSI ) + ' time ' + tdata + ' gw ' + gwid + ' fxt ' + fxt + ' lat ' + lat + ' lgt ' + lgt + ' distance ' + str( "%.4f" % distance) f.write(data + '\n') f.close() print 'GPS file: lat=' + lat print 'GPS file: lgt=' + lgt print 'GPS file: d=' + "%.4f" % distance #update the list of remote GPS device #information from device older than key_GpsFile.active_interval_minutes will be marked not active update_gps_device(src, SNR, RSSI, seq, bc, lat, lgt, fxt, str("%.4f" % distance), tdata, gwid) if (key_GpsFile.SMS == True): try: gammurc_file = key_GpsFile.gammurc_file except AttributeError: gammurc_file = "/home/pi/.gammurc" print 'GPS file: SMS is requested' #check Gammu configuration if (not libSMS.gammuCheck()): print 'GPS file: Gammu is not available' sys.exit() else: if (not libSMS.gammurcCheck(gammurc_file)): print 'GPS file: gammurc file is not available' sys.exit() if (libSMS.phoneConnection(gammurc_file, key_GpsFile.PIN) == None): print 'GPS file: Can not connect to cellular network' sys.exit() else: sm = libSMS.phoneConnection(gammurc_file, key_GpsFile.PIN) print "GPS file: Sending SMS" success = libSMS.send_sms(sm, data, key_GpsFile.contacts) if (success): print "GPS file: Sending SMS done"