Translated from Türkçe by AI ·
If it is already connected to Hermetry, send the IP there as a client attribute. I always do it this way on the test devices at the pharmaceutical plant.Right after connecting, and again if the IP changes, publish to v1/attributes:
import socket, json
def lan_ip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("10.255.255.255", 1))
ip = s.getsockname()[0]; s.close(); return ip
def on_connect(c, u, f, rc):
c.publish("v1/attributes", json.dumps({"lan.ip": lan_ip(), "host": socket.gethostname()}), qos=1)
On the device page, in the Attributes tab, when you select the Client scope, lan.ip appears there with its last update time. The example in the documentation also uses the lan.ip key anyway.Don’t rely on the IP address field in Overview: it holds the address the latest connection came from, so if there is NAT on the way out it will be the school’s external IP, which is useless for SSH.Öznitelikler
Zaten Hermetry’e bağlıysa IP’yi oraya client attribute olarak yolla. Ben ilaç tesisindeki test cihazlarında hep böyle yapıyorum.
Bağlandıktan hemen sonra, bir de IP değişirse, v1/attributes’a yayınla:
import socket, json
def lan_ip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("10.255.255.255", 1))
ip = s.getsockname()[0]; s.close(); return ip
def on_connect(c, u, f, rc):
c.publish("v1/attributes", json.dumps({"lan.ip": lan_ip(), "host": socket.gethostname()}), qos=1)
Cihaz sayfasında Attributes sekmesinde Client kapsamını seçince lan.ip orada, son güncellenme zamanıyla görünüyor. Dokümandaki örnekte de lan.ip anahtarı kullanılıyor zaten.
Overview’daki IP address alanına güvenme, o en son bağlantının geldiği adres, yani çıkışta NAT varsa okulun dış IP’si olur, SSH için işe yaramaz.

