@@ -34,13 +34,13 @@ def _fmt_ts(ts: Optional[int]) -> str:
3434 return str (ts )
3535
3636
37- def _latest_location (ldb : LocationDB , node_id : int ) -> Optional [Dict [str , Any ]]:
37+ def _latest_location (ldb : LocationDB , node_num : int ) -> Optional [Dict [str , Any ]]:
3838 with ldb .connect () as con :
3939 cur = con .cursor ()
4040 cur .execute (
4141 f"SELECT timestamp, latitude, longitude, altitude, location_source FROM { ldb .table } "
42- "WHERE node_id = ? ORDER BY timestamp DESC LIMIT 1" ,
43- (node_id ,),
42+ "WHERE node_num = ? ORDER BY timestamp DESC LIMIT 1" ,
43+ (node_num ,),
4444 )
4545 row = cur .fetchone ()
4646 if not row :
@@ -54,13 +54,13 @@ def _latest_location(ldb: LocationDB, node_id: int) -> Optional[Dict[str, Any]]:
5454 }
5555
5656
57- def _latest_device_telemetry (tdb : TelemetryDB , node_id : int ) -> Optional [Dict [str , Any ]]:
57+ def _latest_device_telemetry (tdb : TelemetryDB , node_num : int ) -> Optional [Dict [str , Any ]]:
5858 with tdb .connect () as con :
5959 cur = con .cursor ()
6060 cur .execute (
6161 f"SELECT timestamp, battery_level, voltage, channel_utilization, air_util_tx, uptime_seconds "
62- f"FROM { tdb .table_device } WHERE node_id = ? ORDER BY timestamp DESC LIMIT 1" ,
63- (node_id ,),
62+ f"FROM { tdb .table_device } WHERE node_num = ? ORDER BY timestamp DESC LIMIT 1" ,
63+ (node_num ,),
6464 )
6565 row = cur .fetchone ()
6666 if not row :
@@ -75,13 +75,13 @@ def _latest_device_telemetry(tdb: TelemetryDB, node_id: int) -> Optional[Dict[st
7575 }
7676
7777
78- def _latest_power_telemetry (tdb : TelemetryDB , node_id : int ) -> Optional [Dict [str , Any ]]:
78+ def _latest_power_telemetry (tdb : TelemetryDB , node_num : int ) -> Optional [Dict [str , Any ]]:
7979 with tdb .connect () as con :
8080 cur = con .cursor ()
8181 cur .execute (
8282 f"SELECT timestamp, ch1_voltage, ch1_current, ch2_voltage, ch2_current, ch3_voltage, ch3_current "
83- f"FROM { tdb .table_power } WHERE node_id = ? ORDER BY timestamp DESC LIMIT 1" ,
84- (node_id ,),
83+ f"FROM { tdb .table_power } WHERE node_num = ? ORDER BY timestamp DESC LIMIT 1" ,
84+ (node_num ,),
8585 )
8686 row = cur .fetchone ()
8787 if not row :
@@ -122,7 +122,7 @@ def _infer_owner_candidates(db_hint: str | None) -> list[int]:
122122 return sorted (out )
123123
124124
125- def main () -> None :
125+ def start () -> None :
126126 db_base = os .environ .get ("MESHTASTIC_DB" )
127127 set_default_db_path (db_base )
128128
@@ -157,7 +157,7 @@ def main() -> None:
157157 with ndb .connect () as con :
158158 cur = con .cursor ()
159159 cur .execute (
160- f"SELECT node_id , long_name, short_name, last_heard, hops_away, snr FROM { ndb .table } "
160+ f"SELECT node_num , long_name, short_name, last_heard, hops_away, snr FROM { ndb .table } "
161161 "ORDER BY (last_heard IS NULL), last_heard DESC"
162162 )
163163 rows = cur .fetchall ()
@@ -167,15 +167,15 @@ def main() -> None:
167167 return
168168
169169 node_list = []
170- for node_id , long_name , short_name , last_heard , hops_away , snr in rows :
171- uid = int (node_id ) if isinstance (node_id , (int , str )) else node_id
170+ for node_num , long_name , short_name , last_heard , hops_away , snr in rows :
171+ uid = int (node_num ) if isinstance (node_num , (int , str )) else node_num
172172 name_long = long_name or ndb .get_name (uid , "long" )
173173 name_short = short_name or ndb .get_name (uid , "short" )
174174 loc = _latest_location (ldb , uid )
175175 dev = _latest_device_telemetry (tdb , uid )
176176 pwr = _latest_power_telemetry (tdb , uid )
177177 node_data = {
178- "node_id " : uid ,
178+ "node_num " : uid ,
179179 "long_name" : name_long ,
180180 "short_name" : name_short ,
181181 "last_heard" : last_heard ,
@@ -193,7 +193,7 @@ def main() -> None:
193193 cur = con .cursor ()
194194 # Environment telemetry
195195 cur .execute (
196- f"SELECT * FROM { tdb .table_environment } WHERE node_id = ? ORDER BY timestamp DESC LIMIT 1" , (uid ,)
196+ f"SELECT * FROM { tdb .table_environment } WHERE node_num = ? ORDER BY timestamp DESC LIMIT 1" , (uid ,)
197197 )
198198 env_row = cur .fetchone ()
199199 if env_row :
@@ -202,22 +202,22 @@ def main() -> None:
202202
203203 # Air quality telemetry
204204 cur .execute (
205- f"SELECT * FROM { tdb .table_air_quality } WHERE node_id = ? ORDER BY timestamp DESC LIMIT 1" , (uid ,)
205+ f"SELECT * FROM { tdb .table_air_quality } WHERE node_num = ? ORDER BY timestamp DESC LIMIT 1" , (uid ,)
206206 )
207207 aq_row = cur .fetchone ()
208208 if aq_row :
209209 columns = [d [0 ] for d in cur .description ]
210210 node_data ["telemetry_air_quality" ] = dict (zip (columns , aq_row ))
211211
212212 # Health telemetry
213- cur .execute (f"SELECT * FROM { tdb .table_health } WHERE node_id = ? ORDER BY timestamp DESC LIMIT 1" , (uid ,))
213+ cur .execute (f"SELECT * FROM { tdb .table_health } WHERE node_num = ? ORDER BY timestamp DESC LIMIT 1" , (uid ,))
214214 health_row = cur .fetchone ()
215215 if health_row :
216216 columns = [d [0 ] for d in cur .description ]
217217 node_data ["telemetry_health" ] = dict (zip (columns , health_row ))
218218
219219 # Host telemetry
220- cur .execute (f"SELECT * FROM { tdb .table_host } WHERE node_id = ? ORDER BY timestamp DESC LIMIT 1" , (uid ,))
220+ cur .execute (f"SELECT * FROM { tdb .table_host } WHERE node_num = ? ORDER BY timestamp DESC LIMIT 1" , (uid ,))
221221 host_row = cur .fetchone ()
222222 if host_row :
223223 columns = [d [0 ] for d in cur .description ]
@@ -228,4 +228,4 @@ def main() -> None:
228228
229229
230230if __name__ == "__main__" :
231- main ()
231+ start ()
0 commit comments