Advertisement
AntonioVillanueva

Meshtastic tests

Dec 9th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. """
  2. pip install meshtastic pypubsub
  3. """
  4. import meshtastic
  5. import meshtastic.serial_interface
  6. from pubsub import pub
  7. from datetime import datetime
  8. import time
  9. from time import gmtime, strftime
  10.  
  11. TOPIC_RX ="meshtastic.receive"
  12. TOPIC_CONNECT="meshtastic.connection.established"
  13.  
  14. def onConnect(interface, topic=pub.AUTO_TOPIC):
  15.     """ on connect"""
  16.     interface.sendText("Running " + getHeure())
  17.  
  18. def onReceive(packet, interface):
  19.     """  RX Meshtastic """
  20.     print(f"DEBUG RX : {packet}")
  21.  
  22. def onSend(interface,message, topic=pub.AUTO_TOPIC):
  23.     """ TX Meshtastic """
  24.     interface.sendText(message)
  25.  
  26.    
  27. def findInterface():
  28.     """Recherche tty Meshtastic .. ou par défaut ttyUSB"""
  29.     return meshtastic.serial_interface.SerialInterface()
  30.  
  31. def subscriptions():
  32.     """ subscribe Meshtastic topics"""
  33.     pub.subscribe(onReceive, TOPIC_RX)
  34.     pub.subscribe(onConnect, TOPIC_CONNECT)
  35.    
  36. def getHeure():
  37.     return strftime("%Y-%m-%d %H:%M:%S", gmtime())
  38.  
  39.  
  40.  
  41. interface = findInterface()#Get interface /dev/ttyUSB0
  42. subscriptions() #Subscribe TOPICs
  43.  
  44. # Main loop
  45.  
  46. while True:
  47.     onSend(interface,"Debug Live Mesh" +getHeure())
  48.     time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement