Raspberry Pi, API üzerinden en son tank seviyesini sorgularken sürekli 401 alıyor
Yapay zekâ tarafından English dilinden çevrildi ·
IoT tarafına yeni başlıyorum, backend geliştiriciyim ve bu iş bana verildi.Hermetry’de zaten bir tank seviye sensörü veri gönderiyor (cihaz “tank-01”, anahtar level_pct). Biri ofiste bir Pi olsun istiyor; seviye 90’ın üzerine çıktığında bir buzzer ötsün. Planım, Pi üzerinde küçük bir Python servisi çalıştırıp Hermetry’den en son değeri her 5 saniyede bir sorgulamaktı. tank-01 sayfasından erişim belirtecini kopyaladım ve şunu yaptım:
GET https://<host>/api/telemetry/latest?kind=iot_device&entityId=6f1c...&keys=level_pct
Authorization: Bearer <tank-01 token>
-> 401
“Bearer” ile ve onsuz denedim, sonuç aynı. Belirteç mi yanlış, yoksa yanlış uç nokta mı kullanıyorum?
New to the IoT side of things, I’m a backend dev and got handed this.
We have a tank level sensor already reporting to Hermetry (device “tank-01”, key level_pct). Someone wants a Pi in the office that sounds a buzzer when the level goes over 90. My plan was a tiny Python service on the Pi that polls Hermetry every 5 seconds for the latest value. I copied the access token from tank-01’s page and did:
GET https://<host>/api/telemetry/latest?kind=iot_device&entityId=6f1c...&keys=level_pct
Authorization: Bearer <tank-01 token>
-> 401
Tried with and without “Bearer”, same. Is the token wrong or is this the wrong endpoint?
Yapay zekâ tarafından English dilinden çevrildi ·
Bu bir cihaz kimlik bilgisi. Cihazın oturum açmasını sağlar, sizin için hiçbir veri okumaz. Yönetim API’si bir API anahtarı ister. Ayrıca 5 saniyede bir sorgulamak bir buzzer için fazlasıyla çok.
That’s a device credential. It logs a device in, it doesn’t read anything for you. The management API wants an API key. Also every 5 seconds is a lot for a buzzer.
Yapay zekâ tarafından English dilinden çevrildi ·
Brian haklı, ayrıca kuruluş ön ekini de eksik bırakmışsın. Geçen yıl bir soğutma odası için hemen hemen aynı şeyi kurdum.1. API Keys (Developer menu) > New API Key. Module permissions altında yalnızca telemetri için salt okunur yetki ver, başka bir şey verme. Bir IP izin listesini ofisin adresine ayarla ve son kullanma tarihini not al; varsayılan 90 gün, en fazla bir yıl. Takvimine bir hatırlatıcı koy, bizimki bir Cumartesi günü süresi doldu.2. Tüm yönetim yolları tenant altında bulunur:
GET https://<host>/tenant/<tenantId>/api/telemetry/latest?kind=iot_device&entityId=<deviceId>&keys=level_pct
Authorization: Bearer sk_live_...
Yanıt şuna benzer: {“latest”: {“level_pct”: {“ts”: …, “value”: 91.2}}}. Aynı okumada iki kez buzzer çalmamak için ts değerini bir önceki ile karşılaştır.3. 429 durumunu ele al ve Retry-After saniye kadar bekle. Yaklaşık 30 sn’de bir sorgula, tank 5 saniyede dolmaz.Anlık olmasını istersen diğer yol: Pi’yi kendisi bir cihaz yap, tanktaki bir kural level_pct 90’ın üzerine çıktığında ona komut göndersin ve Pi kendi cihaz token’ıyla GET /api/v1/rpc üzerinde beklesin. Daha fazla hareketli parça, polling yok. Bir buzzer için API key’i tercih ederim. Kurallar için REST API basics sayfasına bak.
Brian’s right, and you’re also missing the organisation prefix. I set up nearly the same thing for a chiller room last year.
1. API Keys (Developer menu) > New API Key. Under Module permissions give it read-only telemetry, nothing else. Set an IP allowlist to the office’s address, and note the expiry, default is 90 days, a year at most. Put a reminder in the calendar, ours expired on a Saturday.
2. Every management path sits under the tenant:
GET https://<host>/tenant/<tenantId>/api/telemetry/latest?kind=iot_device&entityId=<deviceId>&keys=level_pct
Authorization: Bearer sk_live_...
Answer looks like {“latest”: {“level_pct”: {“ts”: …, “value”: 91.2}}}. Compare the ts with the previous one so you don’t buzz twice on the same reading.
3. Handle 429 and wait the Retry-After seconds. Poll every 30 s or so, the tank doesn’t fill in 5.
The other route, if you want it instant: make the Pi a device itself, have a rule on the tank send it a command when level_pct rises above 90, and let the Pi wait on GET /api/v1/rpc with its own device token. More moving parts, no polling. For a buzzer I’d take the API key. Conventions are on REST API basics.
Yapay zekâ tarafından English dilinden çevrildi ·
Bu iki hataymış: token ve eksik /tenant/<tenantId> kısmı (anahtarı aldıktan sonra bir kez 404 aldım, sonra fark ettim). Şu an 30 s aralıkla çalışıyor ve IP adresimize kilitli, salt okunur bir anahtar kullanıyoruz. Bu sabah tank doldurulduğunda zil çaldı, yani çalışıyor.
That was two bugs, the token and the missing /tenant/<tenantId> bit (got a 404 once I had the key, then saw it). Running at 30 s now with a read-only key locked to our IP. Buzzer went off this morning when they filled it, so it works.
Yapay zekâ tarafından English dilinden çevrildi ·
Anahtarı, bir gün bir bilete yapıştıracağınız betikte değil, yalnızca root kullanıcısının erişebildiği bir dosyada saklayın.
Store the key in a root-only file, not in the script you’ll paste into a ticket some day.
- Bu konuyu yanıtlamak için giriş yapmış olmalısınız.
Sohbete katılın
Soru sormak ve yanıtlamak, yararlı gönderileri beğenmek ve sorununuzu çözen yanıtı işaretlemek için oturum açın. Her katkı puan ve seviye kazandırır.

