-
Notifications
You must be signed in to change notification settings - Fork 0
/
patternmock.py
90 lines (82 loc) · 18.3 KB
/
patternmock.py
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
81
82
83
84
85
86
87
import paho.mqtt.client as mqtt
import time
import json
from collections import deque
import random
import sys
def on_connect(client, userdata, flags, rc):
print(f'{client._client_id} connected')
if __name__ == "__main__":
lons = [round(110.15 + (x*0.03), 2) for x in range(10)]
lats = [round(-7.75 - (x*0.015), 2) for x in range(10)]
clientid = [f'{sys.argv[1]}.{x}.{y}' for x in 'abcdefghij' for y in 'QRSTUVWXYZ']
latslons = [[m, n] for m in lats for n in lons]
paths = [[0, 0.017966305682390427],
[-0.00971331841609056, 0.015114218054838233],
[-0.016342726579457775, 0.007463473007443055],
[-0.017783434607622318, -0.002556871846504909],
[-0.013578028063032193, -0.011765428015330875],
[-0.0050616933896267145, -0.01723854404164073],
[0.00506169338962672, -0.017238544041640727],
[0.013578028063032196, -0.011765428015330873],
[0.017783434607622318, -0.0025568718465049053],
[0.01634272657945777, 0.007463473007443063],
[0.009713318416090563, 0.015114218054838233]]
#radius = 20,point = 100
paths2 = [[0,0.0001796630568239043],[-0.000011281136678234309,0.00017930853282138268],[-0.000022517751863859977,0.00017824635995808926],[-0.0000336654997702594,0.00017648073014505492],[-0.000044680385329367134,0.0001740186115165124],[-0.00005551893782010292,0.00017086972092985388],[-0.00006613838242744902,0.00016704648561763387],[-0.00007649680905510269,0.00016256399414295994],[-0.00008655333772547913,0.00015743993685182758],[-0.00009626827991430699,0.00015169453605740632],[-0.0001056032951831021,0.0001453504662318081],[-0.00011452154249136144,0.0001384327645203052],[-0.00012298782559131948,0.00013096873193115593],[-0.00013096873193145782,0.000122987825590998],[-0.0001384327645205818,0.00011452154249102711],[-0.00014535046623205503,0.00010560329518276221],[-0.00015169453605762048,0.00009626827991396955],[-0.0001574399368520073,0.0000865533377251523],[-0.00016256399414310492,0.00007649680905479458],[-0.00016704648561774517,0.00006613838242716785],[-0.0001708697209299341,0.00005551893781985596],[-0.00017401861151656534,0.00004468038532916098],[-0.00017648073014508542,0.00003366549977009963],[-0.000178246359958103,0.000022517751863750934],[-0.00017930853282138612,0.000011281136678178989],[-0.00017966305682390427,-3.300356811960943e-20],[-0.00017930853282138612,-0.000011281136678179057],[-0.000178246359958103,-0.000022517751863750998],[-0.00017648073014508542,-0.0000336654997700997],[-0.00017401861151656537,-0.000044680385329160885],[-0.00017086972092993408,-0.00005551893781985602],[-0.00016704648561774514,-0.00006613838242716792],[-0.00016256399414310492,-0.00007649680905479463],[-0.00015743993685200732,-0.0000865533377251522],[-0.00015169453605762054,-0.00009626827991396945],[-0.00014535046623205498,-0.00010560329518276226],[-0.00013843276452058174,-0.00011452154249102714],[-0.00013096873193145774,-0.0001229878255909981],[-0.0001229878255913194,-0.000130968731931156],[-0.00011452154249136144,-0.00013843276452030518],[-0.00010560329518310197,-0.00014535046623180822],[-0.00009626827991430687,-0.0001516945360574064],[-0.000086553337725479,-0.0001574399368518277],[-0.00007649680905510256,-0.00016256399414296002],[-0.00006613838242744904,-0.00016704648561763387],[-0.000055518937820102865,-0.0001708697209298539],[-0.000044680385329367,-0.00017401861151651244],[-0.00003366549977025942,-0.00017648073014505492],[-0.000022517751863859913,-0.00017824635995808926],[-0.000011281136678234324,-0.00017930853282138268],[2.2002378746514456e-20,-0.0001796630568239043],[0.000011281136678234366,-0.00017930853282138268],[0.000022517751863859954,-0.00017824635995808926],[0.00003366549977025938,-0.00017648073014505492],[0.00004468038532936711,-0.0001740186115165124],[0.0000555189378201029,-0.00017086972092985388],[0.00006613838242744908,-0.00016704648561763385],[0.00007649680905510266,-0.00016256399414295994],[0.00008655333772547895,-0.0001574399368518277],[0.00009626827991430698,-0.00015169453605740632],[0.00010560329518310208,-0.0001453504662318081],[0.00011452154249136145,-0.00013843276452030516],[0.00012298782559131948,-0.00013096873193115595],[0.00013096873193145771,-0.00012298782559099812],[0.0001384327645205817,-0.0001145215424910272],[0.000145350466232055,-0.00010560329518276222],[0.00015169453605762048,-0.00009626827991396956],[0.00015743993685200732,-0.00008655333772515224],[0.00016256399414310487,-0.00007649680905479472],[0.00016704648561774514,-0.0000661383824271679],[0.0001708697209299341,-0.00005551893781985593],[0.00017401861151656534,-0.000044680385329160966],[0.00017648073014508542,-0.00003366549977009969],[0.000178246359958103,-0.00002251775186375092],[0.00017930853282138612,-0.000011281136678179092],[0.00017966305682390427,1.1001189373203143e-20],[0.00017930853282138612,0.000011281136678179112],[0.000178246359958103,0.00002251775186375098],[0.00017648073014508536,0.00003366549977009971],[0.00017401861151656534,0.000044680385329160946],[0.00017086972092993408,0.00005551893781985599],[0.0001670464856177451,0.00006613838242716797],[0.0001625639941431049,0.00007649680905479472],[0.00015743993685200737,0.00008655333772515219],[0.0001516945360576205,0.00009626827991396949],[0.00014535046623205498,0.00010560329518276226],[0.0001384327645205817,0.0001145215424910272],[0.00013096873193145774,0.00012298782559099812],[0.00012298782559131942,0.000130968731931156],[0.00011452154249136144,0.00013843276452030518],[0.00010560329518310205,0.00014535046623180813],[0.00009626827991430691,0.00015169453605740638],[0.00008655333772547898,0.0001574399368518277],[0.00007649680905510264,0.00016256399414296002],[0.00006613838242744904,0.00016704648561763387],[0.00005551893782010287,0.00017086972092985388],[0.00004468038532936703,0.00017401861151651244],[0.00003366549977025939,0.00017648073014505492],[0.000022517751863859906,0.00017824635995808926],[0.000011281136678234327,0.00017930853282138268],[0,0.0001796630568239043]]
#radius = 100,point = 100
paths3 = [[0,0.0008983152841195215],[-0.00005640568339559102,0.0008965426641067744],[-0.0001125887593280172,0.0008912317997898959],[-0.00016832749886407306,0.0008824036507240564],[-0.00022340192666332197,0.0008700930575804459],[-0.00027759468912026545,0.0008543486046460609],[-0.0003306919121597327,0.0008352324280837177],[-0.00038248404530014595,0.0008128199707090045],[-0.0004327666886535371,0.0007871996842519526],[-0.00048134139959852727,0.000758472680278467],[-0.0005280164759426952,0.0007267523311491653],[-0.0005726077124835484,0.0006921638225904651],[-0.0006149391279823022,0.0006548436596437105],[-0.0006548436596814273,0.0006149391279421379],[-0.0006921638226250313,0.0005726077124417651],[-0.0007267523311800262,0.0005280164759002187],[-0.0007584726803052322,0.0004813413995563517],[-0.000787199684274408,0.00043276668861269086],[-0.000812819970727116,0.0003824840452616568],[-0.0008352324280976295,0.00033069191212459545],[-0.0008543486046560881,0.00027759468908940445],[-0.0008700930575870599,0.00022340192663756182],[-0.0008824036507278643,0.00016832749884411021],[-0.0008912317997916168,0.00011258875931439605],[-0.0008965426641072089,0.000056405683388685226],[-0.0008983152841195215,-1.6501784059155688e-19],[-0.0008965426641072089,-0.000056405683388685565],[-0.0008912317997916165,-0.00011258875931439638],[-0.0008824036507278643,-0.0001683274988441105],[-0.00087009305758706,-0.00022340192663756136],[-0.0008543486046560881,-0.0002775946890894047],[-0.0008352324280976293,-0.00033069191212459583],[-0.0008128199707271158,-0.00038248404526165704],[-0.0007871996842744081,-0.0004327666886126904],[-0.0007584726803052327,-0.00048134139955635126],[-0.0007267523311800261,-0.000528016475900219],[-0.000692163822625031,-0.0005726077124417653],[-0.0006548436596814269,-0.0006149391279421383],[-0.0006149391279823016,-0.0006548436596437111],[-0.0005726077124835484,-0.0006921638225904651],[-0.0005280164759426946,-0.0007267523311491657],[-0.0004813413995985266,-0.0007584726802784673],[-0.0004327666886535364,-0.0007871996842519529],[-0.0003824840453001453,-0.0008128199707090047],[-0.0003306919121597327,-0.0008352324280837177],[-0.0002775946891202652,-0.0008543486046460609],[-0.0002234019266633213,-0.000870093057580446],[-0.00016832749886407314,-0.0008824036507240564],[-0.00011258875932801686,-0.000891231799789896],[-0.000056405683395591086,-0.0008965426641067744],[1.10011893741226e-19,-0.0008983152841195215],[0.000056405683395591296,-0.0008965426641067744],[0.00011258875932801708,-0.0008912317997898959],[0.00016832749886407295,-0.0008824036507240564],[0.00022340192666332187,-0.0008700930575804459],[0.00027759468912026534,-0.0008543486046460609],[0.000330691912159733,-0.0008352324280837177],[0.00038248404530014584,-0.0008128199707090045],[0.0004327666886535362,-0.0007871996842519529],[0.0004813413995985271,-0.000758472680278467],[0.0005280164759426952,-0.0007267523311491653],[0.0005726077124835485,-0.000692163822590465],[0.0006149391279823021,-0.0006548436596437108],[0.0006548436596814268,-0.0006149391279421384],[0.000692163822625031,-0.0005726077124417655],[0.0007267523311800262,-0.0005280164759002188],[0.0007584726803052322,-0.00048134139955635175],[0.000787199684274408,-0.00043276668861269053],[0.0008128199707271156,-0.0003824840452616576],[0.0008352324280976293,-0.0003306919121245957],[0.0008543486046560881,-0.00027759468908940434],[0.0008700930575870599,-0.00022340192663756176],[0.0008824036507278643,-0.00016832749884411049],[0.0008912317997916168,-0.00011258875931439599],[0.0008965426641072089,-0.000056405683388685735],[0.0008983152841195215,5.500594686385229e-20],[0.0008965426641072089,0.00005640568338868585],[0.0008912317997916165,0.00011258875931439627],[0.0008824036507278643,0.00016832749884411062],[0.0008700930575870599,0.00022340192663756166],[0.0008543486046560881,0.0002775946890894046],[0.0008352324280976293,0.0003306919121245961],[0.0008128199707271157,0.00038248404526165753],[0.0007871996842744082,0.00043276668861269037],[0.0007584726803052323,0.0004813413995563515],[0.0007267523311800261,0.000528016475900219],[0.000692163822625031,0.0005726077124417655],[0.0006548436596814269,0.0006149391279421384],[0.0006149391279823018,0.0006548436596437109],[0.0005726077124835484,0.0006921638225904651],[0.000528016475942695,0.0007267523311491655],[0.00048134139959852683,0.0007584726802784673],[0.0004327666886535364,0.0007871996842519529],[0.0003824840453001457,0.0008128199707090046],[0.0003306919121597327,0.0008352324280837177],[0.0002775946891202653,0.0008543486046460609],[0.0002234019266633215,0.0008700930575804459],[0.00016832749886407298,0.0008824036507240564],[0.00011258875932801685,0.000891231799789896],[0.00005640568339559111,0.0008965426641067744],[0,0.0008983152841195215]]
#radius = 500,point = 100
paths4 = [[0,0.004491576420597607],[-0.00028202841753038795,0.004482713320516494],[-0.000562943797729746,0.00445615899888065],[-0.0008416374959173631,0.0044120182534679595],[-0.0011170096353773965,0.004350465287637668],[-0.0013879734480701851,0.004271743022829213],[-0.0016534595636096127,0.004176162139862121],[-0.0019124202295797796,0.004064099852820576],[-0.002163833446535356,0.003935998420361553],[-0.002406707001366657,0.0037923634003217232],[-0.002640082383111567,0.003633761654511397],[-0.002863038565760383,0.0034608191115696883],[-0.0030746956431245945,0.0032742182967099086],[-0.003274218301424424,0.003074695638104146],[-0.003460819115890429,0.002863038560537505],[-0.0036337616583689883,0.0026400823778020472],[-0.00379236340366738,0.0024067069960947473],[-0.0039359984231684565,0.002163833441429618],[-0.004064099855084471,0.001912420224768758],[-0.0041761621416010804,0.0016534595592175025],[-0.004271743024082621,0.0013879734442125927],[-0.0043504652884644186,0.0011170096321574154],[-0.004412018253943965,0.0008416374934220519],[-0.004456158999095738,0.0005629437960271501],[-0.0044827133205708,0.0002820284166672096],[-0.004491576420597607,-8.250892021464997e-19],[-0.0044827133205708,-0.0002820284166672113],[-0.0044561589990957376,-0.0005629437960271517],[-0.004412018253943965,-0.0008416374934220534],[-0.004350465288464419,-0.0011170096321574132],[-0.00427174302408262,-0.0013879734442125943],[-0.00417616214160108,-0.0016534595592175045],[-0.00406409985508447,-0.0019124202247687598],[-0.003935998423168457,-0.0021638334414296164],[-0.003792363403667381,-0.002406706996094745],[-0.0036337616583689875,-0.002640082377802049],[-0.003460819115890428,-0.0028630385605375058],[-0.003274218301424421,-0.0030746956381041486],[-0.003074695643124592,-0.0032742182967099116],[-0.002863038565760383,-0.003460819111569688],[-0.0026400823831115644,-0.0036337616545113987],[-0.002406707001366654,-0.0037923634003217254],[-0.0021638334465353525,-0.003935998420361555],[-0.0019124202295797762,-0.004064099852820578],[-0.001653459563609613,-0.004176162139862121],[-0.0013879734480701834,-0.004271743022829213],[-0.0011170096353773928,-0.004350465287637669],[-0.0008416374959173635,-0.0044120182534679595],[-0.0005629437977297445,-0.004456158998880651],[-0.0002820284175303882,-0.004482713320516494],[5.500594697878427e-19,-0.004491576420597607],[0.0002820284175303893,-0.004482713320516494],[0.0005629437977297455,-0.00445615899888065],[0.0008416374959173626,-0.0044120182534679595],[0.001117009635377396,-0.004350465287637668],[0.0013879734480701843,-0.004271743022829213],[0.0016534595636096138,-0.004176162139862121],[0.0019124202295797788,-0.004064099852820576],[0.002163833446535352,-0.003935998420361555],[0.002406707001366657,-0.0037923634003217237],[0.0026400823831115665,-0.003633761654511397],[0.0028630385657603835,-0.0034608191115696875],[0.003074695643124594,-0.00327421829670991],[0.0032742183014244208,-0.003074695638104149],[0.0034608191158904274,-0.002863038560537507],[0.0036337616583689875,-0.002640082377802048],[0.00379236340366738,-0.0024067069960947477],[0.003935998423168457,-0.0021638334414296172],[0.004064099855084468,-0.001912420224768762],[0.00417616214160108,-0.0016534595592175038],[0.004271743024082621,-0.0013879734442125923],[0.0043504652884644186,-0.0011170096321574151],[0.004412018253943965,-0.0008416374934220532],[0.004456158999095738,-0.0005629437960271497],[0.0044827133205708,-0.00028202841666721216],[0.004491576420597607,2.750297340488332e-19],[0.0044827133205708,0.0002820284166672127],[0.0044561589990957376,0.0005629437960271513],[0.004412018253943965,0.0008416374934220538],[0.0043504652884644186,0.0011170096321574147],[0.00427174302408262,0.001387973444212594],[0.00417616214160108,0.0016534595592175056],[0.004064099855084469,0.001912420224768762],[0.003935998423168458,0.0021638334414296155],[0.00379236340366738,0.0024067069960947464],[0.0036337616583689875,0.002640082377802049],[0.0034608191158904274,0.002863038560537507],[0.003274218301424421,0.003074695638104149],[0.003074695643124593,0.0032742182967099103],[0.002863038565760383,0.003460819111569688],[0.0026400823831115665,0.003633761654511397],[0.002406707001366655,0.003792363400321725],[0.0021638334465353525,0.003935998420361555],[0.0019124202295797781,0.004064099852820577],[0.001653459563609613,0.004176162139862121],[0.0013879734480701838,0.004271743022829213],[0.001117009635377394,0.004350465287637668],[0.0008416374959173628,0.0044120182534679595],[0.0005629437977297442,0.004456158998880651],[0.00028202841753038844,0.004482713320516494],[0,0.004491576420597607]]
#radius = 500,point = 20
paths5 = [[0,0.004491576420597607],[-0.0013879734480701851,0.004271743022829213],[-0.002640082383111567,0.003633761654511397],[-0.0036337616583689883,0.0026400823778020472],[-0.004271743024082621,0.0013879734442125927],[-0.004491576420597607,-8.250892021464997e-19],[-0.00427174302408262,-0.0013879734442125943],[-0.0036337616583689875,-0.002640082377802049],[-0.002640082383111566,-0.003633761654511397],[-0.001387973448070182,-0.004271743022829215],[5.500594697878427e-19,-0.004491576420597607],[0.0013879734480701843,-0.004271743022829213],[0.0026400823831115665,-0.003633761654511397],[0.0036337616583689875,-0.002640082377802048],[0.004271743024082621,-0.0013879734442125934],[0.004491576420597607,2.750297340488332e-19],[0.00427174302408262,0.001387973444212594],[0.0036337616583689875,0.0026400823778020485],[0.0026400823831115665,0.003633761654511397],[0.0013879734480701838,0.004271743022829213],[0,0.004491576420597607]]
state = [int(random.uniform(0,len(paths4))) for x in range(len(latslons))]
#dpath = deque(paths,maxlen=len(paths))
clients_connection = list()
for i in range(100):
mqttc = mqtt.Client(client_id = clientid[i],transport="websockets")
mqttc.max_inflight_messages_set(1)
mqttc.max_queued_messages_set(1)
mqttc.message_retry_set(5)
mqttc.ws_set_options(path="/tenant1", headers=None)
# mqttc.tls_set()
mqttc.username_pw_set(username="nuha", password="nuha")
mqttc.on_connect = on_connect
mqttc.connect_async("127.0.0.1", 9000, 60)
mqttc.loop_start()
clients_connection.append(mqttc)
# while True:
# for index,latlon in enumerate(latslons):
# time.sleep(random.uniform(0,2)/len(latslons))
# #time.sleep(2)
# mod = dpath[0]
# dpath.rotate(-1)
# msg = dict(lat = latlon[0] + mod[0],lon = latlon[1] + mod[1],time=int(time.time()))
# clients_connection[index].publish("gps",json.dumps(msg))
# while True:
# for mod in paths:
# time.sleep(1)
# msg = dict(lat = lats[0] + mod[0],lon = lons[0] + mod[1],time=int(time.time()))
# clients_connection[0].publish("gps",json.dumps(msg))
# while True:
# for index,latlon in enumerate(latslons[:10]):
# time.sleep(random.uniform(0,2)/len(latslons))
# #time.sleep(2)
# mod = dpath[0]
# dpath.rotate(-1)
# msg = dict(lat = latlon[0] + mod[0],lon = latlon[1] + mod[1],time=int(time.time()))
# clients_connection[index].publish("gps",json.dumps(msg))
while True:
time.sleep(1)
for index,latlon in enumerate(latslons):
#time.sleep(random.uniform(0,1)/len(latslons))
#time.sleep(1/len(latslons))
current_pos = state[index]
state[index] = 1 if current_pos == 100 else current_pos + 1
try:
mod = paths4[current_pos]
except:
print(current_pos)
msg = dict(lat = latlon[0] + mod[0],lon = latlon[1] + mod[1],time=int(time.time()))
clients_connection[index].publish("gps.fused.test",json.dumps(msg))
#print(json.dumps(msg))