Python Daemon Script for Raspberry Pi 4 (Offline Ollama Loop):
# pi_brain_daemon.py - Runs 100% Offline on Raspberry Pi 4
import serial, json, requests, ephem
ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1)
def compute_astrology(m, d, y, h, mi, lat, lng):
obs = ephem.Observer()
obs.lat = str(lat)
obs.lon = str(lng)
obs.date = f"{y}/{m}/{d} {h}:{mi}:00"
# Returns (actor, stage, atmosphere)
return "A stranger marked by exile", "An iron-gated tower", "Salt wind and cold ash"
def generate_local_story(actor, stage, atmosphere):
prompt = f"Weave a 3-sentence gothic scene with: Actor={actor}, Stage={stage}, Atmosphere={atmosphere}"
res = requests.post('http://localhost:11434/api/generate', json={
"model": "llama3.2:1b",
"prompt": prompt,
"stream": False
})
return res.json()['response']
while True:
raw = ser.readline().decode('utf-8').strip()
if raw.startswith('{'):
packet = json.loads(raw)
if packet.get('status') == 'LOCKED':
a, s, at = compute_astrology(packet['month'], packet['day'], packet['year'], packet['hour'], packet['minute'], packet['lat'], packet['lng'])
story = generate_local_story(a, s, at)
print("\n" + "="*50 + "\n" + story + "\n" + "="*50)