Exemplo n.º 1
0
def receive_data():
	try:
		# Attempt to set up the RFM69 Module
		rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, 915.0)
		display.text('RFM69 Detected', 0, 1, 1)
	except RuntimeError:
		# Thrown on version mismatch
		display.text('RFM69 Error', 0, 1, 1)
  
	packet = rfm69.receive()
	
	if packet is None:
		# Check for packet rx
		display.show()
	else:
		# Display the packet text
		prev_packet = packet
		packet_text = str(prev_packet, "utf-8")
		display.text(packet_text, 0, 2, 1)
		
		# Scan the packet text for the sender ID and the data by slicing the packet text
		sender_id = 
		data = 
		
		# Return the timestamp, sender ID, and data
		current_time = datetime.datetime.now()
		return (time, sender_id, data)
Exemplo n.º 2
0
def init():
    global display
    global rfm69
    global btnA
    global btnB

    # I2C
    i2c = busio.I2C(board.SCL, board.SDA)

    # OLED Display
    reset_pin = DigitalInOut(board.D4)
    display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, reset=reset_pin)

    #Vaciar display
    display.fill(0)
    display.show()
    width = display.width
    height = display.height

    #Modulo radio
    CS = DigitalInOut(board.CE1)
    RESET = DigitalInOut(board.D25)
    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
    rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, 433.0)
    rfm69.encryption_key = b'\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08'

    # Button A
    btnA = DigitalInOut(board.D5)
    btnA.direction = Direction.INPUT
    btnA.pull = Pull.UP

    # Button B
    btnB = DigitalInOut(board.D6)
    btnB.direction = Direction.INPUT
    btnB.pull = Pull.UP
 def __init__(self, node_id, pin):
     # initialize the RFM69 radio on the Feather
     spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
     cs = digitalio.DigitalInOut(board.RFM69_CS)
     reset = digitalio.DigitalInOut(board.RFM69_RST)
     self.rfm69 = adafruit_rfm69.RFM69(spi, cs, reset, 915.0)
     self.packet = None
     self.node_id = node_id
     # Initialize the pin used to turn valve on/off.
     self.valve = digitalio.DigitalInOut(pin)
     self.valve.direction = digitalio.Direction.OUTPUT
     self.valve.value = False
     self.stop_watering_time = 0
     self.watering = False
     self.led = digitalio.DigitalInOut(board.D13)
     self.led.direction = digitalio.Direction.OUTPUT
     self.led.value = False
Exemplo n.º 4
0
    def __init__(self):
        self._rfm69 = None

        # RFM69 setup
        chip_select = DigitalInOut(board.CE1)
        reset = DigitalInOut(board.D25)
        spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

        # Setup interrupt directly via RPi.GPIO as Blinka doesn't support interrupts
        self._DIO0 = 22
        GPIO.setup(self._DIO0, GPIO.IN)

        try:
            # Preamble is 40 bits, detect at 20 => 3 bytes for now???
            self._rfm69 = adafruit_rfm69.RFM69(
                spi, chip_select, reset, 868.5, sync_word=b"\x2d\xd4", preamble_length=3
            )
            logging.info("RFM69 Initialised OK!")
        except RuntimeError as error:
            # Thrown on version mismatch
            logging.fatal(f"RFM69 Error: {error}")
            sys.exit(1)

        self._rfm69.modulation_type = 0b00  # FSK
        # self._rfm69.modulation_shaping = 0b01  # Gaussian BT 1.0
        self._rfm69.modulation_shaping = 0b10  # Gaussian BT 0.5
        # ListenEnd?

        self._rfm69.bitrate = 57600
        self._rfm69.frequency_deviation = 28750
        self._rfm69.packet_format = 1  # Packet mode
        self._rfm69.dc_free = 0b00  # No Manchester/Whitening
        self._rfm69.crc_on = 0

        # Start receiving on callback
        self._packet_queue = Queue(maxsize=64)
        GPIO.add_event_detect(self._DIO0, GPIO.RISING)
        GPIO.add_event_callback(self._DIO0, self.payload_ready_callback)
        self._rfm69.listen()
Exemplo n.º 5
0
            print('RSSI: {0}'.format(rfm69.last_rssi))


# Define radio parameters.
RADIO_FREQ_MHZ = 915.0  # Frequency of the radio in Mhz. Must match your
# module! Can be a value like 915.0, 433.0, etc.

# Define pins connected to the chip, use these if wiring up the breakout according to the guide:
CS = digitalio.DigitalInOut(board.CE1)
RESET = digitalio.DigitalInOut(board.D25)

# Initialize SPI bus.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Initialze RFM radio
rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ)

# Optionally set an encryption key (16 byte AES key). MUST match both
# on the transmitter and receiver (or be set to None to disable/the default).
rfm69.encryption_key = b'\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08'

# Print out some chip state:
print('Temperature: {0}C'.format(rfm69.temperature))
print('Frequency: {0}mhz'.format(rfm69.frequency_mhz))
print('Bit rate: {0}kbit/s'.format(rfm69.bitrate / 1000))
print('Frequency deviation: {0}hz'.format(rfm69.frequency_deviation))

# configure the interrupt pin and event handling.
RFM69_G0 = 22
io.setmode(io.BCM)
io.setup(RFM69_G0, io.IN, pull_up_down=io.PUD_DOWN)  # activate input
Exemplo n.º 6
0
    config = config_handler.config(name="usb/FLIGHT_DATA/config.txt",
                                   usb_methods=usb_methods_copied)
    os.system("sudo umount /dev/sda1")
    time.sleep(3)
else:
    config = config_handler.config()
    lcd.prompt("SETUP", "DEFAULT CONFIG")
    time.sleep(2)
    lcd.prompt("SETUP", "DEFAULT METHODS")
    time.sleep(2)

##SETUP
CS = digitalio.DigitalInOut(board.D7)
RESET = digitalio.DigitalInOut(board.D5)
spibus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rf = adafruit_rfm69.RFM69(spibus, CS, RESET, 433.0)
rf.encryption_key = b'\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08'

#DATA SETUP
os.system("mkdir -p DATA")

i = 0
while os.path.exists("DATA/" + str(i) + "/"):
    i += 1
data_number = i

data_path = "DATA/" + str(data_number) + "/"
graphs_pdf_path = data_path + "GRAPHS/"
graphs_png_path = graphs_pdf_path + "pictures/"
os.system("mkdir -p " + data_path + " " + graphs_pdf_path + " " +
          graphs_png_path)
Exemplo n.º 7
0
    uint8_t ps_2;
    uint8_t ps_3;
    uint8_t ps_4;
};
'''

cmd_format = 'BBBBB'

# RFM69 Configuration
CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Initialize the radio
try:
    rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, 915.0)
    print('RFM69: Online')
except RuntimeError as error:
    # Thrown on version mismatch
    print('RFM69 Error: ', error)

# Global Vars
rfm69.encryption_key = b'\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08'

# Node value for ground/pi side radio
rfm69.node = 1
# Node value for the avionics side radio
rfm69.destination = 2
unpacked = None
receive_counter = 0
send_flag = 0
Exemplo n.º 8
0
i2c = busio.I2C(board.SCL, board.SDA)
 
# 128x32 OLED Display
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x3c)
# Clear the display.
display.fill(0)
display.show()
width = display.width
height = display.height

# RFM69 Configuration
packet = None
CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, 433.0)
rfm69.encryption_key = None 

numPkts = 0

while True:
    # initialization
    packetRX = None
    packetTX = None

    packetTX = bytes("Hello World!", "utf-8")
    rfm69.send(packetTX)

    displayPacket = str(packetTX, "utf-8")
    display.fill(0) 
    display.text('Pkt = ', 0, 0, 1)
Exemplo n.º 9
0
def main():
    #############################################################################
    # Initialize RFM69 Board
    #############################################################################
    # Button A
    btnA = DigitalInOut(board.D5)
    btnA.direction = Direction.INPUT
    btnA.pull = Pull.UP

    # Button B
    btnB = DigitalInOut(board.D6)
    btnB.direction = Direction.INPUT
    btnB.pull = Pull.UP

    # Button C
    btnC = DigitalInOut(board.D12)
    btnC.direction = Direction.INPUT
    btnC.pull = Pull.UP

    # Create the I2C interface.
    i2c = busio.I2C(board.SCL, board.SDA)

    # 128x32 OLED Display
    reset_pin = DigitalInOut(board.D4)
    display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, reset=reset_pin)
    # Clear the display.
    display.fill(0)
    display.show()

    # Set up some variables to help with writing to the display
    display_width = display.width
    display_height = display.height
    display_line1 = 0
    display_line2 = 12
    display_line3 = 24

    # Define radio parameters.
    # Frequency of the raio in Mhz.  Must match
    RADIO_FREQ_MHZ = 915.0

    # set GPIO pins as nessessary for the radio
    CS = DigitalInOut(board.CE1)
    RESET = DigitalInOut(board.D25)

    # Initialize SPI bus
    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
    rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ)

    # Optionally set an encryption key (16 byte AES key). MUST match both
    # on the transmitter and receiver (or be set to None to disable/the default).
    rfm69.encryption_key = b'\x00\x06\x01\x08\x01\x09\x07\x00\x00\x01\x02\x03\x01\x09\x07\x01'

    # set delay before transmitting ACK (seconds)
    rfm69.ack_delay = 0.1
    # set node addresses
    rfm69.node = 7
    rfm69.destination = 5
    # initialize counter
    counter = 0
    ack_failed_counter = 0
    display_temps = False

    execution_loop = True
    while execution_loop:
        packet = None
        # check for packet rx
        packet = rfm69.receive(with_ack=True, with_header=True)

        if packet is not None:
            # Display the packet text and rssi
            # Print out the raw bytes of the packet:
            # print("Received (raw header):", [hex(x) for x in packet[0:4]])
            # print("Received (ray payload):  {0}".format(packet[4:]))
            # print("RSSI: {0}".format(rfm69.last_rssi))

            packet_text = str(packet[4:], "utf-8")

            # Extract the sensor data from the string
            x = packet_text.split(",")
            fDegC = float(x[0])
            fBackDegC = float(x[1])
            fPressure = float(x[2])

            # Convert C to F
            fDegF = (fDegC * 9 / 5) + 32
            fBackDegF = (fBackDegC * 9 / 5) + 32

            # Create a dictionary object
            sensor_dict = {
                "front_temp": round(fDegF, 1),
                "back_temp": round(fBackDegF, 1),
                "pressure": round(fPressure, 1),
                "sensor": packet[1],
                "RSSI": rfm69.last_rssi,
                "sequence": hex(packet[2]),
                "status": hex(packet[3])
            }

            # Create a JSON string from the disctionary object
            sensor_json = json.dumps(sensor_dict)
            #print(sensor_json)

            # Publish MQTT message
            mqtt.Client.connected_flag = False
            broker = "192.168.12.27"

            client = mqtt.Client(
                "sensor_rfm69_mqtt")  # Create a MQTT client object
            client.username_pw_set(username="******",
                                   password="******")
            client.on_connect = on_connect  # bind call back function
            client.loop_start()  # Start loop
            # print("Connecting to broker ", broker)

            client.connect(broker, port=1883, keepalive=60, bind_address="")
            while not client.connected_flag:
                time.sleep(1)

            client.publish("shop", sensor_json)

            client.loop_stop()  # Stop loop
            client.disconnect()

            # Check the board buttons
            #   - If Button A has been pressed - display the temps
            #   - If Button B or C has been pressed - clear the display
            if not btnA.value:
                # Button A Pressed
                display_temps = True
            elif not btnB.value:
                # Button B Pressed
                display_temps = False
                display.text("B - Going Dark!", 10, display_line2, 1)
                display.show()
            elif not btnC.value:
                # Button C Pressed
                display_temps = False
                display.text("C - Going Dark!", 10, display_line2, 1)
                display.show()

            if display_temps:
                display.text("Front Room:  " + str(round(fDegF, 1)), 5,
                             display_line1, 1)
                display.text(" Back Room:  " + str(round(fBackDegF, 1)), 5,
                             display_line2, 1)
                display.text("      RSSI: " + str(rfm69.last_rssi), 5,
                             display_line3, 1)
                display.show()

            time.sleep(10)

            # Clear the display and lets do it again
            display.fill(0)
            display.show()
packetSentLED = DigitalInOut(PIN_PACKET_SENT_LED)
packetSentLED.direction = Direction.OUTPUT

#   Initialize the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)

#   Initialize the SPI bus
spi = busio.SPI(SPI_SCK, MOSI=SPI_MOSI, MISO=SPI_MISO)

print()
print("This is node #{0}".format(RFM69_NETWORK_NODE))
print()

#   Initialze RFM69 radio
print("Initializing the RFM69 radio")
rfm69 = adafruit_rfm69.RFM69(spi, RFM69_CS, RFM69_RST, RFM69_RADIO_FREQ_MHZ)

# Optionally set an encryption key (16 byte AES key). MUST match both
# on the transmitter and receiver (or be set to None to disable/the default).
rfm69.encryption_key = b'\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08'

rfm69Celsius = rfm69.temperature
rfm69Fahrenheit = round(rfm69Celsius * 1.8 + 32, 1)

#   Print out some RFM69 chip state:
print("RFM69 Radio Data")
print('    Temperature:         {0}°F ({1}°C)'.format(rfm69Fahrenheit,
                                                      rfm69Celsius))
print('    Frequency:           {0} MHz'.format(round(rfm69.frequency_mhz, 0)))
print('    Bit rate:            {0} kbit/s'.format(rfm69.bitrate / 1000))
print('    Frequency deviation: {0} kHz'.format(rfm69.frequency_deviation /
Exemplo n.º 11
0
cs = digitalio.DigitalInOut(board.D9)
reset = digitalio.DigitalInOut(board.D11)

display1 = adafruit_ht16k33.segments.Seg14x4(i2c, address=0x70)
display2 = adafruit_ht16k33.segments.Seg14x4(i2c, address=0x71)
display3 = adafruit_ht16k33.segments.Seg14x4(i2c, address=0x72)
display = [display1, display2, display3]
for i in range(0, 3):
    display[i].print(i)
display[0].print('T199')
display[1].print('TomH')
display[2].print('2019')

RADIO_FREQ_MHZ = 434.0
# Initialze RFM radio
rfm69 = adafruit_rfm69.RFM69(spi, cs, reset, RADIO_FREQ_MHZ)
# ino: uint8_t key[] ="VillaAstrid_2003"
e_key = b'\x56\x69\x6c\x6c\x61\x41\x73\x74\x72\x69\x64\x5f\x32\x30\x30\x33'
rfm69.encryption_key = e_key
rec_msg = {'Zone': '', 'Sensor': '', 'Value': '', 'Remark': ''}
sensor_4char = {
    'T_bmp180': 'TMP2',
    'P_bmp180': 'ILMP',
    'H_dht22': 'HUM ',
    'T_dht22': 'TMP1',
    'T_Water': 'LAKE',
    'Light1': 'LDR1',
    'Light2': 'LDR2',
    'Temp2': 'TMP2'
}
Exemplo n.º 12
0
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x3c)

# Clear the display.
display.fill(0)
display.show()
width = display.width
height = display.height

# Configure Packet Radio
CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
FREQ = 915.0
ID = 0

spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, FREQ)

def get_ip():
	ifname = 'eth0'
	s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))[20:24])

def display_ip():
	eth_ip = get_ip()
	display.text('IP: ' + eth_ip, 0, 0, 1)
	display.show()

def receive_data():
	try:
		# Attempt to set up the RFM69 Module
		rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, 915.0)
Exemplo n.º 13
0
# Or uncomment and instead use these if using a Feather M0 RFM69 board
# and the appropriate CircuitPython build:
# CS = digitalio.DigitalInOut(board.RFM69_CS)
# RESET = digitalio.DigitalInOut(board.RFM69_RST)

# Define the onboard LED
LED = digitalio.DigitalInOut(board.D26)
LED.direction = digitalio.Direction.OUTPUT

# Initialize SPI bus.
spi = busio.SPI(board.D11, MOSI=board.D10, MISO=board.D9)

# Initialze RFM radio
rfm69 = adafruit_rfm69.RFM69(spi,
                             CS,
                             RESET,
                             RADIO_FREQ_MHZ,
                             sync_word=b"\x48\x65")

# Optionally set an encryption key (16 byte AES key). MUST match both
# on the transmitter and receiver (or be set to None to disable/the default).
rfm69.encryption_key = (
    b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08")

# Print out some chip state:
print("Temperature: {0}C".format(rfm69.temperature))
print("Frequency: {0}mhz".format(rfm69.frequency_mhz))
print("Bit rate: {0}kbit/s".format(rfm69.bitrate / 1000))
print("Frequency deviation: {0}hz".format(rfm69.frequency_deviation))

# Send a packet.  Note you can only send a packet up to 60 bytes in length.
import adafruit_rfm69

# ------------------------ #
# --- INITIALIZE RADIO --- #
# ------------------------ #

# Radio frequency
RadioFreq = 915.0

# Radio module pins
RAD_CS = digitalio.DigitalInOut(board.RFM69_CS)
RAD_RST = digitalio.DigitalInOut(board.RFM69_RST)
RAD_SPI = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm69 = adafruit_rfm69.RFM69(RAD_SPI,
                             RAD_CS,
                             RAD_RST,
                             RadioFreq,
                             baudrate=9600)

# ------------------------------- #
# --- INITIALIZE MOTOR DRIVER --- #
# ------------------------------- #

# Connect pins
MOT_PWM = pulseio.PWMOut(board.D5)
MOT_DIR_1 = digitalio.DigitalInOut(board.D9)
MOT_DIR_2 = digitalio.DigitalInOut(board.D6)
MOT_STDBY = digitalio.DigitalInOut(board.D10)

# Set pins as outputs
MOT_DIR_1.direction = digitalio.Direction.OUTPUT