import random import time import busio import board import adafruit_tlc59116 from Crypto.Cipher import ARC4 # Starting byte (replace with a unique value)S START_BYTE = b'\x7F' # Example using hexadecimal value # Replace with your desired LiFi data data_to_send = b"kerala university of digital sciences innovation and technology!" # Adjust these values based on your LiFi hardware min_intensity = 0 # Minimum intensity (0-255) max_intensity = 255 # Maximum intensity (0-255) num_intensity_levels = 10 # Number of intensity levels to hop between pwm_frequency = 1000 # PWM frequency in Hz # I2C bus configuration (replace with your pin assignments if different) i2c = busio.I2C(board.SCL, board.SDA) # TLC59116 driver initialization (adjust channel count if needed) driver = adafruit_tlc59116.TLC59116(i2c) # Function to generate pseudo-random intensity levels def generate_intensity_levels(seed): random.seed(seed) intensity_levels = [] for _ in range(num_intensity_levels): intensity_levels.append(random.randint(min_intensity, max_intensity)) return intensity_levels # Function to transmit LiFi signal using PWM modulation with TLC59116 def transmit_lifi_signal(data, intensity): # Calculate the PWM duty cycle based on the intensity level duty_cycle = intensity / max_intensity # Loop through each bit in the data for bit in data: # Set the PWM duty cycle for the current bit driver.set_pwm_duty_cycle(duty_cycle if int(bit) else 0) time.sleep(1 / pwm_frequency) # Adjust based on your data rate # Function to perform RC4 encryption def rc4_encrypt(data, key): s = list(range(256)) j = 0 for i in range(256): j = (j + s[i] + key[i % len(key)]) % 256 s[i], s[j] = s[j], s[i] i = j = 0 encrypted_data = bytearray() for byte in data: i = (i + 1) % 256 j = (j + s[i]) % 256 s[i], s[j] = s[j], s[i] encrypted_data.append(byte ^ s[(s[i] + s[j]) % 256]) return encrypted_data # Main program # Use a fixed seed value for PRFH seed_value = 42 # Customize seed value # Generate a random key for RC4 encryption key = b"MyFixedKey123456" # Encrypt the data using RC4 encrypted_data = rc4_encrypt(START_BYTE + data_to_send, key) # Generate pseudo-random intensity levels using the fixed seed value intensity_levels = generate_intensity_levels(seed_value) print("Transmitting data with PRFH (seed:", seed_value, ")...") # Transmit the encrypted data using the pseudo-random intensity levels for intensity in intensity_levels: transmit_lifi_signal(encrypted_data, intensity) time.sleep(0.01) # Adjust hopping interval print("Data sent successfully!")
sender
![](/assets/playground/adafruit_playground_1200x900-699010177a4a3fd6bac6bc31deae0bfa3eb9ea777ba62aaa5cbc1225bb45bfcc.jpg)
Adafruit Playground is a wonderful place to share what you find interesting. Have a cool project you are working on? Have a bit of code that you think others will find useful? Want to show off your electronics workbench? You have come to the right place.
Adafruit Playground is a safe place to share with the wonderful Adafruit community of makers and doers.
Click here to learn more about Adafruit Playground and how to get started.
This page (sender) was last updated on May 17, 2024.
Text editor powered by tinymce.