summaryrefslogtreecommitdiff
path: root/prilohy/web/mqttdummy.py
blob: 5dae09d557285d68b0f3af8ff4b87407864e1da3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#nrf/id/pid
#
#nrf/id/lati
#nff/id/long
#nrf/id/alti
#
#nrf/id/rssi
#nrf/id/snr
#nrf/id/rttt - last round trip transmit time
#
#nrf/id/temp - bme temperature
#nrf/id/humi - bme humidity
#nrf/id/pres - bme barometric pressure
#nrf/id/voc  - bme gas

#mosquitto_pub -h mikehanus.xyz -p 1883 -u agr -P ATenKureHubouTlackaVKomore -t 'agr/test' -m kkk

#['pid', 'lati', 'long', 'alti', 'rssi', 'snr', 'rttt', 'temp', 'humi', 'pres', 'voc ']

import time
import numpy as np
import paho.mqtt.client as mqtt

def on_connect(client, userdata, flags, reason_code):
    print(f"Connected with result code {reason_code}")
    client.subscribe("nrf/#")

def on_message(client, userdata, msg):
    print(msg.topic+" "+str(msg.payload))

mqttc = mqtt.Client()
mqttc.on_connect = on_connect
mqttc.on_message = on_message

mqttc.connect("localhost", 1883, 60)

mqttc.loop_start()

nrfid = "tst"
pid = 0
lati = 49.224426
long = 16.564100
#long = 16.550100
alti = 266

temp = 30
humi = 50.36
pres = 100.001
voc = 3

rssi = 0
snr = 0

def publish_pid(ppid, top, val):
    mqttc.publish(top,  f"{int(ppid)}@{val:0.9f}")


while True:

    x = (pid/20) * np.sin(pid/5)
    y = (pid/30) * np.cos(pid/5)

    #mqttc.publish(f"nrf/{nrfid}/pid",  pid)

    publish_pid(pid, f"nrf/{nrfid}/lati", lati + y/1000)
    publish_pid(pid, f"nrf/{nrfid}/long", long + x/1000)
    #publish_pid(pid, f"nrf/{nrfid}/alti", alti)

    publish_pid(pid, f"nrf/{nrfid}/temp", temp)
    #publish_pid(pid, f"nrf/{nrfid}/humi", humi)
    #publish_pid(pid, f"nrf/{nrfid}/pres", pres)
    #publish_pid(pid, f"nrf/{nrfid}/voc",  voc)

    publish_pid(pid, f"nrf/{nrfid}/rssi", rssi - ((x*x+y*y)**0.5) )
    publish_pid(pid, f"nrf/{nrfid}/snr",  snr)

    pid += 1
    time.sleep(1)

mqttc.loop_stop()