Beispiel #1
0
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)

# Define GPIO to use on Pi
GPIO_PIR = 17

print("PIR Module Test (CTRL-C to exit)")

# Set pin as input
GPIO.setup(GPIO_PIR,GPIO.IN)      # Echo

Current_State  = 0
Previous_State = 0

#Setup meshtastic TCPInterface
interface = meshtastic.TCPInterface("meshtastic.local")


#Setup MQTT
def printtime(): # Used for debug
	# Current time
	global hour, minute, wholetime
	now = datetime.datetime.now()
	hour = str(now.hour)
	minute = int(now.minute)
	minute = '%02d' % minute
	wholetime = hour + ":" + minute

#Definitions
def sendmqtt(mess):
    try:
Beispiel #2
0
# reported by @ScriptBlock

import meshtastic, sys
from pubsub import pub


def onConnection(
        interface,
        topic=pub.AUTO_TOPIC):  # called when we (re)connect to the radio
    print(interface.myInfo)
    interface.close()


pub.subscribe(onConnection, "meshtastic.connection.established")
interface = meshtastic.TCPInterface(sys.argv[1])
Beispiel #3
0
opt_device_info_interval_s_ = int(sys.argv[3])
opt_collect_mesh_nodes = sys.argv[4].lower() == 'true'
opt_mesh_info_interval_s_ = int(sys.argv[5])
abort_timeout = int(sys.argv[6])

print("Meshtastic Debug: Starting data collection for " + opt_device_ip)
print("Meshtastic Debug: Collect Device Info: " + str(opt_collect_device_info))
print("Meshtastic Debug: Device Info Interval: " +
      str(opt_device_info_interval_s_))
print("Meshtastic Debug: Collect Mesh Info: " + str(opt_collect_mesh_nodes))
print("Meshtastic Debug: Mesh Info Interval: " +
      str(opt_mesh_info_interval_s_))
print("Meshtastic Debug: Abort Timeout: " + str(abort_timeout))

pub.subscribe(onReceive, "meshtastic.receive")
interface = meshtastic.TCPInterface(opt_device_ip)

running = True

while running:
    loopTime = datetime.datetime.now()

    while not q.empty():
        data = q.get()
        f = open(
            sh + "/etc/apps/" + taName + "/bin/data/messages-" + sys.argv[1] +
            ".log", "a")
        f.write(data + "\r\n")
        f.close()

    if opt_collect_device_info:
Beispiel #4
0
        if self.rx_snr:
            data[0]["rx_snr"] = self.rx_snr

        return json.dumps(data)


def onReceive(packet, interface):  # called when a packet arrives
    print(f"Received: {packet}")
    if (len(packet["decoded"]["data"]["payload"])):
        update = PositionUpdate(packet)

        mqtt_client = mqtt.Client()
        mqtt_client.connect("127.0.0.1", 1883, 60)
        mqtt_client.publish("meshtastic/position",
                            update.get_influxdb_format())
        mqtt_client.disconnect()


def onConnection(
        interface,
        topic=pub.AUTO_TOPIC):  # called when we (re)connect to the radio
    # defaults to broadcast, specify a destination ID if you wish
    #interface.sendText("hello mesh")
    print(f"Connected to device")


interface = meshtastic.TCPInterface("127.0.0.1")

pub.subscribe(onReceive, "meshtastic.receive.position")
pub.subscribe(onConnection, "meshtastic.connection.established")