def LoRaRec(data,socket,source_address): bandera = 0 mensaje = b"" tabla = BaseDatos(mode_print) my_lora_address = binascii.hexlify(network.LoRa().mac()) if (mode_print == 1): #print ("DEBUG Server: Content in reception LoRa", data) # KN: Enable this print to see the content in reception LoRa in debug mode print ("DEBUG Server: Source Address in LoRaRec ", source_address) if (source_address == ANY_ADDR): content2 = str(data) # Capturing the data, and changing the format IPlora,user_raw = content2.split(",") if (IPlora == "b'FFFFFFFraspbsend'") or (IPlora == b'FFFFFFFraspberry'): if (mode_print == 1): print ("DEBUG Server: It's the raspberry IP") if (mode_print == 1): print ("DEBUG Server: IP Lora: ", str(IPlora)) lenght = len(user_raw) userf = user_raw[:lenght - 1] if (userf == "broadcast"): # Message to all users message_broadcast = str(IPlora[2:]) tabla = BaseDatos(mode_print) if (mode_print == 1): print ("DEBUG Server: Message Broadcast received", message_broadcast) posthandler.broadcast(message_broadcast, mode_print) # Function to save the broadcast message IPloraf = IPlora[4:] if (mode_print == 1): print ("DEBUG Server: User ", userf) bandera = posthandler.consultat(userf, mode_print) # Checking if the user is in the database if (mode_print == 1): print ("DEBUG Server: Flag ", bandera) if bandera == 1: # The user is in the database, I'm going to respond if (mode_print == 1): print ("DEBUG Server: Lora Address ", IPloraf) sent, retrans, sent, notsend = swlp.tsend(my_lora_address, socket, my_lora_address, IPloraf, mode_print) # Function to send a LoRa Message using the protocol elif (source_address == my_lora_address[8:]): # The message is for me, I'm going to save it message_raw = data #if (mode_print == 1): print ("DEBUG Server: Message in server", message_raw) # KN: Enable this print to see the message in server in debug mode if (mode_print == 2): print ("Receiving message") if (message_raw == b"Failed"): print ("Reception Failed, Discarding") elif (message_raw != b"") and (message_raw != b"Failed"): mensajet = str(message_raw) print("XXXYYYraw", message_raw) # handling sensors data... there must be a better way to send and receive json if (mensajet[-10:-1] == "mqttproxy"): aaa = mensajet.find("{") zzz = mensajet.find("}") user_final = "mqttproxy" messagef = str(mensajet[aaa:zzz+1]) idEmisor = str(mensajet[2:aaa-1]) if (mode_print == 1): print ("Sender: " + idEmisor) print ("Message: " + messagef) # KN: Enable this print to see the message in debug mode print ("User: "******",") if (mode_print == 1): print ("Sender: " + str(idEmisor[1:])) #print ("Message: " + str(messagef)) # KN: Enable this print to see the message in debug mode print ("User: " + str(user_final)) lenght = len(user_final) userf = user_final[:lenght - 1] tabla.ingreso(idEmisor[2:],userf,messagef) # Function to save the message in the database
def LoRaRec(data,socket,source_address): bandera=0 mensaje = b"" tabla=BaseDatos() my_lora_address = binascii.hexlify(network.LoRa().mac()) print("DEBUG: Content in reception LoRa",data) if DEBUG_MODE: print("DEBUG: Source Address in LoRaRec ", source_address) if (source_address == ANY_ADDR): content2 = str(data) #Capturing the data, and changing the format IPlora,user_raw = content2.split(",") if(IPlora=="b'FFFFFFFraspbsend'") or (IPlora==b'FFFFFFFraspberry'): if DEBUG_MODE: print("DEBUG: It's the raspberry IP") if DEBUG_MODE: print("DEBUG: IP Lora: ",str(IPlora)) lenght = len(user_raw) userf = user_raw[:lenght-1] if(userf=="broadcast"): #Message to all users message_broadcast = str(IPlora[2:]) tabla=BaseDatos() if DEBUG_MODE: print("DEBUG: Message Broadcast received",message_broadcast) posthandler.broadcast(message_broadcast) #Function to save the broadcast message IPloraf = IPlora[4:] if DEBUG_MODE: print("DEBUG: User ", userf) bandera=posthandler.consultat(userf) #Checking if the user is in the database #bandera=tabla.consultaControl(userf) if DEBUG_MODE: print("DEBUG: Flag ", bandera) if bandera == 1: #The user is in the database, I'm going to respond if DEBUG_MODE: print("DEBUG: Lora Address ", IPloraf) sent, retrans,sent = swlp.tsend(my_lora_address, socket, my_lora_address, IPloraf)#Function to send a LoRa Message using the protocol elif(source_address== my_lora_address[8:]): #The message is for me, I'm going to save it message_raw = data if DEBUG_MODE: print("DEBUG: message in server", message_raw) if(message_raw !=b""): mensajet = str(message_raw) idEmisor, messagef,user_final = mensajet.split(",") print("Sender: "+str(idEmisor[1:])) print("Message: "+str(messagef)) print("User: "+str(user_final)) lenght = len(user_final) userf = user_final[:lenght-1] tabla.ingreso(idEmisor[2:],userf,messagef)#Function to save the message in the database