Ubuntu masaüstümden terminal ile ofis ışıkları rölesini değiştirme
Yapay zekâ tarafından English dilinden çevrildi ·
tamam, bu yarı kolaylık meselesi, yarı da API’yi öğrenmek istemem.Analitik ofisimiz ve yanındaki rıhtım ışıkları, MQTT üzerinden Hermetry’ye bilgi veren bir ESP32 röle kartıyla açılıp kapatılıyor. Üzerinde anahtar kartı olan bir pano var ve tarayıcıdan sorunsuz çalışıyor. Ancak günün çoğunu Ubuntu’da terminalde geçiriyorum ve panoyu açmadan ofis ışıklarını değiştiren bir klavye kısayolu istiyorum.Denediğim şey: cihazın erişim belirtecini Credentials çekmecesinden alıp cihazın HTTP uç noktasına gönderdim:
curl -X POST "https://<device host>/api/v1/telemetry"
-H "Authorization: Bearer <ACCESS_TOKEN>"
-H "Content-Type: application/json"
-d '{"light": false}'
200 yanıtı dönüyor ve bir an için anahtar kartı Off gösteriyor, ama ışıklar açık kalıyor ve birkaç saniye sonra ESP32 tekrar bilgi verince kart yeniden On oluyor. Demek ki yanlış şeyle konuşuyorum. Cihazın gerçekten bir işlem yapması için hangi uç nokta doğru?
ok so this is half a convenience thing and half me wanting to learn the API.
Our analytics office and the dock lights next to it are switched by an ESP32 relay board that reports to Hermetry over MQTT. There’s a board with a switch card on it and that works fine from the browser. I spend the whole day in a terminal on Ubuntu though and I want a keyboard shortcut that toggles the office lights without opening the board.
What I tried: I took the device’s access token from the Credentials drawer and posted to the device HTTP endpoint:
curl -X POST "https://<device host>/api/v1/telemetry"
-H "Authorization: Bearer <ACCESS_TOKEN>"
-H "Content-Type: application/json"
-d '{"light": false}'
It answers 200, and for a moment the switch card shows Off, but the lights stay on and a few seconds later the card flips back to On when the ESP32 reports again. So I’m clearly talking to the wrong thing. Which endpoint is the right one to make the device actually do something?
Yapay zekâ tarafından English dilinden çevrildi ·
Cihaz token’ı ile telemetri göndermek, cihazmış gibi davranmak anlamına gelir. Hermetry yalnızca “cihazın” söylediğini kaydeder. Sizin ihtiyacınız olan, ters yönde giden bir komuttur.
Posting telemetry with the device token is you pretending to be the device. Hermetry just stores what “the device” says. You want a command going the other way.
Yapay zekâ tarafından English dilinden çevrildi ·
Doğru, bu kartın geri dönmesini açıklıyor. Yani /api/v1/rpc mi? Cihazın HTTP sayfasında bu listeleniyor
right, that explains the card flipping back. so is it /api/v1/rpc? the device HTTP page lists that one
Yapay zekâ tarafından English dilinden çevrildi ·
Bu, cihaz tarafı için; komutları bekliyor. Bence cihaz token’ı yerine bir API anahtarı kullanman gerekiyor. Bir süre önce python requests ile buna benzer bir şey yapmıştım ama yolu hatırlamıyorum.
That one is for the device side, it waits for commands. I think you need an API key instead of the device token, I did something like this with python requests a while ago but I don’t remember the path.
Yapay zekâ tarafından English dilinden çevrildi ·
Fabrikamızdaki hat aydınlatmaları için tam olarak bunu, süpervizör bilgisayarındaki küçük bir betikle yapıyoruz. Bir API anahtarıyla Commands API kullanılıyor.Anahtar kartınız zaten bir komut gönderiyor ve kartlar yalnızca cihaz profilinin Temel seviyedeki Commands kataloğunda bulunan komutları gönderebilir. Yani yöntem mevcut. Tam adını ve parametrelerini görmek için, oluşturacağınız anahtarla API’ye sorun: GET /tenant/<tenantId>/api/iot/devices/<deviceId>/rpc-commands o cihaza bir kontrolün gönderebileceği komutları listeler.API Keys altında anahtarı oluşturun: temel komutları gönderme ve komutları okuma iznini verin, masaüstünüzün adresini IP izin listesine ekleyin ve bir son kullanma tarihi seçin. Ardından:
#!/bin/sh
# ~/bin/office-lights (chmod 700)
KEY=$(cat ~/.config/hermetry/key)
curl -s -X POST "https://<your host>/tenant/<tenantId>/api/iot/devices/<deviceId>/rpc"
-H "Authorization: Bearer $KEY"
-H "Content-Type: application/json"
-d "{"method":"light.set","params":{"on":$1},"timeoutMs":10000}"
Zaman aşımı 30 saniye veya daha az olan çift yönlü bir komut bekler ve durumla birlikte 200 yanıtı verir; böylece terminalde SUCCESSFUL veya hatayı görürsünüz. office-lights true ve office-lights false komutlarını iki kısayola bağlayın, işiniz bitti. Bir API anahtarı yalnızca katalogdaki yöntemleri gönderebilir; bu da zaten burada istediğiniz şey.Dokümantasyon: Commands API.
We do exactly this for the line lights at our plant, from a little script on the supervisor’s PC. It’s the Commands API with an API key.
Your switch card already sends a command, and boards can only send commands that are in the device profile’s Commands catalogue at the Basic tier. So the method exists. To see its exact name and params, ask the API with the same key you’re about to create: GET /tenant/<tenantId>/api/iot/devices/<deviceId>/rpc-commands lists what a control may send to that device.
Create the key under API Keys: give it the permission to send basic commands and to read commands, put your desktop’s address in the IP allowlist, and pick an expiry. Then:
#!/bin/sh
# ~/bin/office-lights (chmod 700)
KEY=$(cat ~/.config/hermetry/key)
curl -s -X POST "https://<your host>/tenant/<tenantId>/api/iot/devices/<deviceId>/rpc"
-H "Authorization: Bearer $KEY"
-H "Content-Type: application/json"
-d "{"method":"light.set","params":{"on":$1},"timeoutMs":10000}"
A two-way command with a timeout of 30 seconds or less waits and answers 200 with the status, so you see SUCCESSFUL or the error in the terminal. Bind office-lights true and office-lights false to two shortcuts and you’re done. An API key can only send methods that are in the catalogue, which is what you want here anyway.
Docs: Commands API.
Yapay zekâ tarafından English dilinden çevrildi ·
Anahtarlar varsayılan olarak 90 gün sonra sona erer (en fazla bir yıl), bu yüzden bir yere hatırlatıcı koyun, yoksa kısayolunuz üç ay sonra sessizce çalışmaz hale gelir. Ayrıca anahtar dosyasını chmod 600 olarak tutun ve dotfiles deponuza koymayın.
Keys expire after 90 days by default (a year at most), so put a reminder somewhere or your shortcut dies quietly in three months. And keep the key file chmod 600, not in your dotfiles repo.
Yapay zekâ tarafından English dilinden çevrildi ·
Çalışıyor. Tek sorunum: katalogda light.set yok; entegratörümüz buna relay.set dedi ve state (0 veya 1) adında bir parametre kullanıyor. rpc-commands çağrısı bunu hemen gösterdi. İlk atadığım kısayol Super+L idi, bu da tabii ekranı kilitliyor; şimdi Super+F9 üzerinde.
Works. My only snag: the catalogue doesn’t have light.set, our integrator called it relay.set with a param called state (0 or 1). The rpc-commands call showed it straight away. First binding was Super+L which of course locks the screen, it’s on Super+F9 now.
Yapay zekâ tarafından English dilinden çevrildi ·
+1, bunu evdeki garaj kapısı için kaydediyorum
+1, saving this for the garage door at home
Yapay zekâ tarafından English dilinden çevrildi ·
Güzel. Rıhtım ışıkları için, bir sürücü hâlâ geri manevra yaparken birisi ışıkları kapattıktan sonra bizimkine “emin misiniz?” onayı ekledik.
Nice. We added an “are you sure” prompt to ours for the dock lights after someone switched them off with a driver still reversing in.
- 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.

