def init_LoRa(self): self.sending_to_lora = False self.lora = rf95.RF95(self.cfg.LoRa_spiDev,0, int_pin=None,reset_pin=5) if not self.lora.init(): # returns True if found log("RF95 not found") self.lora = None return self.lora.set_frequency(self.cfg.LoRa_frequency) self.lora.set_tx_power(self.cfg.LoRa_power) self.lora.set_modem_config_simple(getLoRaBWCode(self.cfg.LoRa_BW), getLoRaCRCode(self.cfg.LoRa_CR), getLoRaSFCode(self.cfg.LoRa_SF)) self.lora.sleep() log("LoRa 0K (" +str(self.cfg.LoRa_frequency)+ "," + self.cfg.LoRa_BW+","+self.cfg.LoRa_CR+","+self.cfg.LoRa_SF+ "," +self.cfg.LoRa_mode +")" )
def __init__(self, cfg): self.cfg = cfg threading.Thread.__init__(self) sensor.Sensor.__init__(self, cfg) self.lora = rf95.RF95(self.cfg.LoRa_spiDev, 0, None, None) if self.lora.init(): self.lora.set_frequency(self.cfg.LoRa_frequency) self.lora.set_tx_power(self.cfg.LoRa_power) self.lora.set_modem_config_simple(getLoRaBWCode(cfg.LoRa_BW), getLoRaCRCode(self.cfg.LoRa_CR), getLoRaSFCode(self.cfg.LoRa_SF)) log("LoRa 0K (" + str(cfg.LoRa_frequency) + "," + cfg.LoRa_BW + "," + self.cfg.LoRa_CR + "," + self.cfg.LoRa_SF + "," + cfg.LoRa_mode + ")") else: log("ERROR RF95 not found") self.lora = None
#!/usr/bin/python3 from __future__ import print_function import time import rf95 import RPi.GPIO as GPIO GPIO.setwarnings(True) file = open("/home/pi/logfile.txt", "a") file.write("\n") file.write("A") file.close() # Create rf95 object with CS0 and external interrupt on pin 25 #lora = rf95.RF95(CS, INT(G0/IRQ), RST) #lora = rf95.RF95(0, 25, 17) #GPIO original lora = rf95.RF95(0, 25) #GPIO original #lora = rf95.RF95(0, 24, 4) #GPIO #lora = rf95.RF95(0, 17, 22) #GPIO test Bw125Cr45Sf128 = (0x72, 0x74, 0x00) file = open("/home/pi/logfile.txt", "a") file.write("\n") file.write("B") file.close() if not lora.init(): # returns True if found print("RF95 not found") lora.cleanup() quit(1) else:
#!/usr/bin/env python3 import rf95 # Create rf95 object with CS0 and external interrupt on pin 25 lora = rf95.RF95(24, 23, 22) if not lora.init(): # returns True if found print("RF95 not found") quit(1) else: print("RF95 LoRa mode ok") # set frequency, power and mode lora.set_frequency(915.5) lora.set_tx_power(5) lora.set_modem_config(Bw31_25Cr48Sf512) # Send some data lora.send([0x00, 0x01, 0x02, 0x03]) lora.wait_packet_sent() # Send a string lora.send(lora.str_to_data("$TELEMETRY TEST")) lora.wait_packet_sent() # Wait until data is available while not lora.available(): pass # Receive #data = lora.recv() #print (data) #for i in data:
try: ssdv_file = open(ssdv_filename, "rb") except IOError as e: print("Could not open the file") print("I/O error({0}): {1}".format(e.errno, e.strerror)) exit(1) if os.path.getsize(ssdv_filename) / 256 != 0: print("File does not look like a SSDV image") exit(1) # ok, get number of packets to send ssdv_packets = os.path.getsize(ssdv_filename) // 256 # Create rf95 object with CS0 and external interrupt on pin 25 lora = rf95.RF95(0, 25) if not lora.init(): # returns True if found print("RF95 not found") quit(1) else: print("RF95 LoRa mode ok") # set frequency, power and mode lora.set_frequency(868.5) lora.set_tx_power(5) # Send ssdv packets # We are ignoring the first sync byte of each packet # as the rf95 packet payload size is just 255 bytes. # We need to take this into account on the receive side.
def setServoAngle(servoNum1, position): # print ("Servo {} {} micro pulses".format(s, pw)) pw = position * 500 / 90 + 1500 pi.set_servo_pulsewidth(servoNum1, pw) pi = pigpio.pi() #+---------------------------------------------AllPins--------------------------------------------------+ #BCMMODE GPIOMODE thrusterPin = 18 #GPIO18 servoPin = 23 #GPIO23 #LoRa lora = rf95.RF95(0, 25, 17) #GPIO Bw125Cr45Sf128 = (0x72, 0x74, 0x00) lora.set_frequency(433) lora.set_tx_power(23) header = [0xff, 0xff, 0, 0] #Thruster setServo(thrusterPin, 1500) #pin 12 on board (GPIO18 PCM_CLK) #14Board for Ground #Servo setServoAngle(servoPin, -15) #0degrees #Antenna #2, 6, 8(TX), and 10(RX)(All Board)
podLocs = [LocationGlobal(0, 0, 0) ] #List of locations that the drone will drop pods off at podsDropped = 0 # Determines which location the drone will drop the next pod off at totalPods = 1 # how many pods are there? podsRecovered = 1 - totalPods # Determines which location the drone will return to before hunting for the nearest pod, a negative number signifies a return to home funnelSize = 0.25 #Radius of the funnel in meters grabDist = 0.25 #Distance from the pod from where we can grab, in meters recvData = [ None, None, time.time() ] #the recieving thread adds to this in the format ((x, y), z, timestamp), where any value is None if not known recvRadioBuffer = [] loraPodLoc = None vision = socket.socket() vision.bind(("127.0.0.1", 4444)) radio = rf95.RF95(0, 25) if not radio.init(): print "Radio not found, aborting" quit(1) else: print "Radio found" radio.set_tx_power(23) radio.set_modem_config(rf95.Bw125Cr45Sf128) radio.set_frequency(915.0) ###################################################################### ## ## ## METHOD DEFINITIONS ## ## ## ######################################################################
# GPIO.setup(25, GPIO.IN) # GPIO.add_event_detect(25, GPIO.RISING, callback=handle_interrupt) def log(message): print datetime.datetime.now().strftime("[%d/%m/%Y-%H:%M:%S]"), message with open("rx.log", "a") as myfile: myfile.write(datetime.datetime.now().strftime("[%d/%m/%Y-%H:%M:%S]") + ' ' + message + '\n') os.system("sudo /opt/vc/bin/tvservice -o > /dev/null") os.system("echo 1 | sudo tee /sys/class/leds/led0/brightness > /dev/null") # Create rf95 object with CS0 and external interrupt on pin 25 lora = rf95.RF95(1, 0, None, None) if not lora.init(): # returns True if found log("RF95 not found") quit(1) else: log("RF95 LoRa mode ok") # set frequency, power and mode lora.set_frequency(869.2) lora.set_tx_power(20) #lora.set_modem_config_simple(rf95.BW_31K25HZ,rf95.CODING_RATE_4_8,rf95.SPREADING_FACTOR_512CPS) #lora.set_modem_config(rfm95.Bw125Cr45Sf128 ) # Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium range. #lora.set_modem_config(rf95.Bw500Cr45Sf128 ) # Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short range. #lora.set_modem_config(rf95.Bw31_25Cr48Sf512) # Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long range.