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(',')) dst = arr[0] ptype = arr[1] src = arr[2] seq = arr[3] datalen = arr[4] SNR = arr[5] RSSI = arr[6] arr = map(int, rdata.split(',')) bw = arr[0] cr = arr[1] sf = arr[2] if (str(src) in key_SMS.source_list) or (len(key_SMS.source_list) == 0): #this part depends on the syntax used by the end-device #we use: thingspeak_channel#thingspeak_field#TC/22.4/HU/85... #ex: ##TC/22.4/HU/85... or TC/22.4/HU/85... or thingspeak_channel##TC/22.4/HU/85... #or #thingspeak_field#TC/22.4/HU/85... to use some default value # get number of '#' separator nsharp = ldata.count('#') nslash = 0 #will field delimited by '#' in the MongoDB data = ['', ''] #no separator if nsharp == 0: # get number of '/' separator on ldata nslash = ldata.count('/') #contains ['', '', "s1", s1value, "s2", s2value, ...] data_array = data + re.split("/", ldata) else: data_array = re.split("#", ldata) # only 1 separator if nsharp == 1: # get number of '/' separator on data_array[1] nslash = data_array[1].count('/') # then reconstruct data_array data_array = data + re.split("/", data_array[1]) # we have 2 separators if nsharp == 2: # get number of '/' separator on data_array[2] nslash = data_array[2].count('/') # then reconstruct data_array data_array = data + re.split("/", data_array[2]) #just in case we have an ending CR or 0 data_array[len(data_array) - 1] = data_array[len(data_array) - 1].replace('\n', '') data_array[len(data_array) - 1] = data_array[len(data_array) - 1].replace('\0', '') #sms data to be sent #sms_data = "SensorData Sensor"+str(src) #sms_data = "SRC#"+str(src)+"#RSSI#"+str(RSSI)+"#BW#"+str(bw)+"#CR#"+str(cr)+"#SF#"+str(sf)+"#GWID#"+gwid+"/"+data sms_data = "SensorData Sensor" + str(src) + " RSSI " + str( RSSI) + " BW " + str(bw) + " CR " + str(cr) + " SF " + str( sf) + " GWID " + gwid nomenclatures = [] # data to send data = [] data.append(data_array[0]) data.append(data_array[1]) if nslash == 0: # old syntax without nomenclature key, so insert only one key # we use DEF nomenclatures.append("DEF") data.append(data_array[2]) else: # completing nomenclatures and data i = 2 while i < len(data_array) - 1: nomenclatures.append(data_array[i]) data.append(data_array[i + 1]) i += 2 #add the nomemclatures and sensed values i = 0 while i < len(data) - 2: sms_data += " " + nomenclatures[i] + " " + data[i + 2] i += 1 # Send data to expected contacts success = False if not always_enabled: if (libSMS.internet_ON()): print('Internet is available, no need to use the SMS Service') sys.exit() else: print("rcv msg to send via the SMS Service: " + sms_data) success = libSMS.send_sms(sm, sms_data, key_SMS.contacts) else: print("rcv msg to send via the SMS Service: " + sms_data) success = libSMS.send_sms(sm, sms_data, key_SMS.contacts) if (success): print "Sending SMS done" else: print "Source is not is source list, not sending with CloudSMS.py"
for cloud in clouds: if "CloudSMS.py" in cloud["script"]: try: always_enabled = cloud["always_enabled"] except KeyError: print "always_enabled undefined" always_enabled = False try: gammurc_file = cloud["gammurc_file"] except KeyError: print "gammurc_file undefined" if not always_enabled: if (libSMS.internet_ON()): print('Internet is available, no need to use the SMS Service') sys.exit() #check Gammu configuration if (not libSMS.gammuCheck()): sys.exit() else: if (not libSMS.gammurcCheck(gammurc_file)): sys.exit() if (libSMS.phoneConnection(gammurc_file, key_SMS.PIN) == None): sys.exit() else: sm = libSMS.phoneConnection(gammurc_file, key_SMS.PIN)
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(',')) dst = arr[0] ptype = arr[1] src = arr[2] seq = arr[3] datalen = arr[4] SNR = arr[5] RSSI = arr[6] arr = map(int, rdata.split(',')) bw = arr[0] cr = arr[1] sf = arr[2] if (str(src) in key_Orion.source_list) or (len(key_Orion.source_list) == 0): #this part depends on the syntax used by the end-device #we use: thingspeak_channel#thingspeak_field#TC/22.4/HU/85... #ex: ##TC/22.4/HU/85... or TC/22.4/HU/85... or thingspeak_channel##TC/22.4/HU/85... #or #thingspeak_field#TC/22.4/HU/85... to use some default value # get number of '#' separator nsharp = ldata.count('#') nslash = 0 # no separator if nsharp == 0: # will use default Fiware-Service and Fiware-ServicePath data = ['', ''] # get number of '/' separator on ldata nslash = ldata.count('/') # contains ['', '', "s1", s1value, "s2", s2value, ...] data_array = data + re.split("/", ldata) else: data_array = re.split("#", ldata) # only 1 separator if nsharp == 1: # insert '' to indicate default Fiware-Service # as we assume that the only parameter indicate the Fiware-ServicePath data_array.insert(0, '') # if the length is greater than 2 if len(data_array[1]) < 3: data_array[1] = '' # we have 2 separators if nsharp == 2: # if the length of BOTH fields is greater than 2 then we take them into account if len(data_array[0]) < 3 or len(data_array[1]) < 3: data_array[0] = '' data_array[1] = '' # get number of '/' separator on data_array[2] # because ldata may contain '/' as Fiware-ServicePath name nslash = data_array[2].count('/') # then reconstruct data_array data_array = [data_array[0], data_array[1]] + re.split( "/", data_array[2]) # at the end data_array contains # ["Fiware-Service", "Fiware-ServicePath", "s1", s1value, "s2", s2value, ...] # just in case we have an ending CR or 0 data_array[len(data_array) - 1] = data_array[len(data_array) - 1].replace('\n', '') data_array[len(data_array) - 1] = data_array[len(data_array) - 1].replace('\0', '') #sms data to be sent sms_data = "SensorData " + key_Orion.sensor_name + str(src) #sms_data = "SRC#"+str(src)+"#RSSI#"+str(RSSI)+"#BW#"+str(bw)+"#CR#"+str(cr)+"#SF#"+str(sf)+"#GWID#"+gwid+"/"+data #sms_data = "SensorData Sensor"+str(src)+" RSSI "+str(RSSI)+" BW "+str(bw)+" CR "+str(cr)+" SF "+str(sf)+" GWID "+gwid+" " #start from the first nomenclature i = 2 while i < len(data_array) - 1: sms_data += " " + data_array[i] + " " + data_array[i + 1] i += 2 if data_array[0] == '': data_array[0] = key_Orion.project_name if data_array[1] == '': data_array[1] = key_Orion.service_path sms_data += " " + data_array[0] + " " + data_array[1] # Send data to expected contacts success = False if (not always_enabled): if (libSMS.internet_ON()): print('Internet is available, no need to use the SMS Service') sys.exit() else: print("rcv msg to send via the Orion WAZIUP SMS Service: " + sms_data) success = libSMS.send_sms(sm, sms_data, key_OrionWAZIUP_SMS.contacts) else: print("rcv msg to send via the Orion WAZIUP SMS Service: " + sms_data) success = libSMS.send_sms(sm, sms_data, key_OrionWAZIUP_SMS.contacts) if (success): print "Sending SMS done" else: print "Source is not is source list, not sending with CloudOrionWAZIUP_SMS.py"