File size: 3,041 Bytes
a04833b
938949f
 
 
 
a04833b
938949f
 
a04833b
 
938949f
 
 
 
 
 
063a7cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
938949f
063a7cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
938949f
 
063a7cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
title: SolarWine API
emoji: 🌿
colorFrom: green
colorTo: yellow
sdk: docker
app_port: 7860
private: true
---

# SolarWine API

FastAPI backend for the SolarWine agrivoltaic vineyard control system.

## Endpoints

### Health & Monitoring
- `GET|HEAD /api/health` β€” system health (uptime, Redis, TB, IMS, Gemini status)
- `GET /api/health/data` β€” data freshness per source (age, ok/degraded)
- `GET /api/health/data-sources` β€” per-source green/yellow/red status with thresholds

### Weather (IMS Station 43)
- `GET /api/weather/current` β€” latest weather readings + data age
- `GET /api/weather/history?start_date&end_date&format` β€” historical weather (hourly)
- `GET /api/weather/forecast` β€” weather forecast

### Vine Sensors (ThingsBoard)
- `GET /api/sensors/snapshot` β€” latest readings (treatment vs reference)
- `GET /api/sensors/history?type&area&hours` β€” sensor time-series
- `GET /api/sensors/soil-moisture?hours` β€” soil moisture history
- `GET /api/sensors/rain?hours` β€” rainfall history

### Energy
- `GET /api/energy/current` β€” current power output (kW)
- `GET /api/energy/daily/{date}` β€” daily production + hourly profile
- `GET /api/energy/history` β€” energy generation time-series
- `GET /api/energy/predict/{date}` β€” predicted daily generation

### Photosynthesis
- `GET /api/photosynthesis/current?model` β€” current A rate (FvCB or ML)
- `GET /api/photosynthesis/forecast` β€” 24h predicted A profile

### Control System
- `GET /api/control/status` β€” last control loop tick
- `GET /api/control/plan` β€” current day-ahead plan
- `GET /api/control/budget` β€” energy budget status
- `GET /api/control/trackers` β€” tracker angles and modes

### Chatbot (Gemini AI)
- `POST /api/chatbot/message` β€” send message to vineyard advisor
- `POST /api/chatbot/feedback` β€” submit feedback on response
- `GET /api/chatbot/briefing` β€” current system status briefing

### Biology
- `GET /api/biology/phenology` β€” current growth stage
- `GET /api/biology/rules` β€” all biology rules
- `GET /api/biology/rules/{name}` β€” single rule detail
- `GET /api/biology/chill-units?season_start` β€” accumulated chill units

### Auth
- `POST /api/auth/login` β€” JWT token (guest mode when JWT_SECRET unset)

### Events
- `GET /api/events/stream` β€” SSE stream for live frontend updates

Interactive docs at `/docs`.

## Environment Variables

| Variable | Required | Description |
|----------|----------|-------------|
| `IMS_API_TOKEN` | Yes | IMS weather API token |
| `THINGSBOARD_HOST` | Yes | ThingsBoard server URL |
| `THINGSBOARD_USERNAME` | Yes | ThingsBoard login |
| `THINGSBOARD_PASSWORD` | Yes | ThingsBoard password |
| `GOOGLE_API_KEY` | No | Gemini AI for chatbot/advisor |
| `JWT_SECRET` | No | JWT signing key (guest mode if unset) |
| `ADMIN_PASSWORD` | No | Login password |
| `REDIS_URL` | No | Upstash Redis for shared cache |
| `SENTRY_DSN` | No | Sentry error tracking |
| `SMTP_HOST` | No | Email alerts (with ALERT_EMAIL_TO) |
| `ALERT_EMAIL_TO` | No | Alert recipient email(s) |