Skip to content

Commit

Permalink
Use journald to log in python code
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinmartian committed Nov 3, 2023
1 parent 0959d45 commit 8aef669
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions reader/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
from requests.exceptions import ConnectionError
import systemd.journal

reader = SimpleMFRC522()

while True:
try:
print("Place an RFID tag near the reader...")
systemd.journal.send("Place an RFID tag near the reader...")
id, text = reader.read()
print(f"Tag ID: {id}")
systemd.journal.send(f"Tag ID: {id}")

# Define the URL to which you want to send the data
url = 'http://yoda:3001/play' # Update the URL as needed
Expand All @@ -24,18 +25,15 @@
response = requests.post(url, json=data, timeout=5, headers={'Content-Type': 'application/json'})

if response.status_code == 200:
print("Data sent successfully.")
systemd.journal.send("Data sent successfully.")
break
# time.sleep(2)
# GPIO.cleanup()
# exit() # Exit the script on success
else:
print("Failed to send data. Status code:", response.status_code)
print("Response body:", response.text)
systemd.journal.send(f"Failed to send data. Status code: {response.status_code}")
systemd.journal.send(f"Response body: {response.text}")
break

except ConnectionError as e:
print("Connection error:", e)
systemd.journal.send(f"Connection error: {e}")
time.sleep(5) # Wait for a moment before retrying

time.sleep(2)
Expand Down

0 comments on commit 8aef669

Please sign in to comment.