Skip to content

Commit

Permalink
Refactor API URL to use dynamically obtained outbound IP address
Browse files Browse the repository at this point in the history
Instead of using a hardcoded IP address in the  variable, this commit modifies the code to dynamically obtain the outbound IP address using the  function. The  variable is updated to construct the URL with the dynamically obtained IP address. This change allows for greater flexibility and adaptability when the machine's IP address changes.
  • Loading branch information
ozfive committed Jul 12, 2023
1 parent 28fd3b6 commit 48381bd
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Read.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@

import json
import requests
import socket
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522

# Initialize the RFID reader
reader = SimpleMFRC522()

# API endpoint URL
api_url_base = 'http://192.168.1.111:3001/'
def get_outbound_ip():
connection = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
connection.connect(("8.8.8.8", 80))

local_ip = connection.getsockname()[0]
connection.close()

return local_ip


# Get the outbound IP dynamically
outbound_ip = get_outbound_ip()
port = '3001'
# Construct the API base URL with the dynamic IP
api_url_base = f"http://{outbound_ip}:{port}/"

# Function to start the playlist based on RFID tag information
def start_playlist(tag, unique):
Expand Down

0 comments on commit 48381bd

Please sign in to comment.