##// END OF EJS Templates
Recuperación parcial
Renato Huallpa -
r383:10ef20bfab46
parent child
Show More
@@ -0,0 +1,39
1 import os
2 import paho.mqtt.client as mqtt
3 from radarsys import settings
4 from radarsys.socketconfig import sio as sio
5
6 lista_ack=[
7 chr( 33 ), chr( 34 ), chr( 35 ), chr( 36 ), chr( 37 ), chr( 38 ), chr( 39 ), chr( 40 ), chr( 41 ), chr( 42 ), chr( 43 ), chr( 44 ), chr( 45 ), chr( 46 ), chr( 47 ), chr( 48 ), chr( 49 ), chr( 50 ), chr( 51 ), chr( 52 ), chr( 53 ), chr( 54 ), chr( 55 ), chr( 56 ), chr( 57 ), chr( 58 ), chr( 59 ), chr( 60 ), chr( 61 ), chr( 62 ), chr( 63 ), chr( 64 ), chr( 65 ), chr( 66 ), chr( 67 ), chr( 68 ), chr( 69 ), chr( 70 ), chr( 71 ), chr( 72 ), chr( 73 ), chr( 74 ), chr( 75 ), chr( 76 ), chr( 77 ), chr( 78 ), chr( 79 ), chr( 80 ), chr( 81 ), chr( 82 ), chr( 83 ), chr( 84 ), chr( 85 ), chr( 86 ), chr( 87 ), chr( 88 ), chr( 89 ), chr( 90 ), chr( 91 ), chr( 92 ), chr( 93 ), chr( 94 ), chr( 95 ), chr( 96 )
8 ]
9
10 lista_ack_dismatching=[
11 chr( 97 ), chr( 98 ), chr( 99 ), chr( 100 ), chr( 101 ), chr( 102 ), chr( 103 ), chr( 104 ), chr( 105 ), chr( 106 ), chr( 107 ), chr( 108 ), chr( 109 ), chr( 110 ), chr( 111 ), chr( 112 ), chr( 113 ), chr( 114 ), chr( 115 ), chr( 116 ), chr( 117 ), chr( 118 ), chr( 119 ), chr( 120 ), chr( 121 ), chr( 122 ), chr( 123 ), chr( 124 ), chr( 125 ), chr( 126 ), chr( 127 ), chr( 128 ), chr( 129 ), chr( 130 ), chr( 131 ), chr( 132 ), chr( 133 ), chr( 134 ), chr( 135 ), chr( 136 ), chr( 137 ), chr( 138 ), chr( 139 ), chr( 140 ), chr( 141 ), chr( 142 ), chr( 143 ), chr( 144 ), chr( 145 ), chr( 146 ), chr( 147 ), chr( 148 ), chr( 149 ), chr( 150 ), chr( 151 ), chr( 152 ), chr( 153 ), chr( 154 ), chr( 155 ), chr( 156 ), chr( 157 ), chr( 158 ), chr( 159 ), chr(160)
12 ]
13
14 def on_connect(mqtt_client, userdata, flags, rc):
15 if rc == 0:
16 print('Connected successfully')
17 mqtt_client.subscribe(os.environ.get('TOPIC_ABS_ACK','abs/beams_ack'))
18 else:
19 print('Bad connection. Code:', rc)
20
21 def on_message(mqtt_client, userdata, msg):
22 # print(f'Received message on topic: {msg.topic} with payload: {msg.payload}', flush=True)
23 # message= str(msg.payload)
24 # sio.emit('abs_ws',data={'msg':message})
25 #message=str(msg.payload)
26 #lista_ack.pop(message)
27 print("Mientras" ,flush=True)
28
29
30
31 client = mqtt.Client()
32 client.on_connect = on_connect
33 client.on_message = on_message
34 client.username_pw_set(os.environ.get('MQTT_USER', 'abs'), os.environ.get('MQTT_PASSWORD', 'abs'))
35 client.connect(
36 host=os.environ.get('MQTT_SERVER', '10.10.10.200'),
37 port=int(settings.os.environ.get('MQTT_PORT', 1883)),
38 keepalive=int(os.environ.get('MQTT_KEEPALIVE', 36000))
39 ) No newline at end of file
@@ -16,4 +16,17 PGDATA=/var/lib/postgresql/data
16 16 LC_ALL=C.UTF-8
17 17 TZ=America/Lima
18 18 DOCKER_DATA=/data/dockers/radarsys/
19 LOCAL_IP=192.168.1.128 No newline at end of file
19 LOCAL_IP=192.168.1.128
20
21 MQTT_SERVER=10.10.10.102
22 #MQTT_SERVER = 0.0.0.0
23 MQTT_PORT = 1883
24 MQTT_KEEPALIVE = 3660
25
26 MQTT_USER_ATRAD=atrad
27 MQTT_PASSWORD_ATRAD = atrad
28 MQTT_USER = abs
29 MQTT_PASSWORD = abs
30 MQTT_CLIENT_ID= abs_id
31 TOPIC_ABS=abs/beams
32 TOPIC_ABS_ACK=abs/beams_ack
@@ -10,6 +10,10 import requests
10 10 import struct
11 11 import os, sys, time
12 12
13 from .mqtt import client as mqtt_client
14 from radarsys.socketconfig import sio as sio
15 import json
16
13 17 antenna_default = json.dumps({
14 18 "antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
15 19 [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
@@ -488,7 +492,28 class ABSConfiguration(Configuration):
488 492 conf_active.conf = self
489 493 conf_active.save()
490 494 return True
495
496 def write_device_mqtt(self):
497 apuntes_up_down=''
498 beams = ABSBeam.objects.filter(abs_conf=self)
491 499
500 inicializacion="{\"beams\":["
501 finalizacion="]}"
502
503 for beam in beams:
504 beam.antenna=beam.antenna[1:]
505 info="{\"id\":"+str(beam.id)+","+beam.antenna + ","
506 apuntes_up_down=apuntes_up_down+info
507
508 apuntes_up_down=apuntes_up_down[:len(apuntes_up_down)-1]
509
510 apuntes_up_down=inicializacion+ apuntes_up_down+finalizacion
511
512 #print(apuntes_up_down,flush=True)
513
514 mqtt_client.publish(os.environ.get('TOPIC_ABS', 'abs/beams'),apuntes_up_down)
515
516 return True
492 517
493 518 def read_module(self, module):
494 519
@@ -39,13 +39,22
39 39
40 40 </style>
41 41 {% endblock %}
42
43
42 44 {% block extra-menu-actions %}
43 45 <li>
44 46 <a href="{{ dev_conf.get_absolute_url_plot }}" target="_blank">
45 47 <span class="far fa-image" aria-hidden="true"></span> View Patterns </a>
46 48 </li>
47 49 {% endblock %}
50
51
48 52 {% block extra-content %}
53 <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
54 <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js">
55 </script>
56
57
49 58 {% if beams %}
50 59 <h4>Beams:</h4>
51 60 <div class="container">
@@ -280,6 +289,10
280 289 </tr>
281 290 </table>
282 291
292 <!-- <meta id="configuraciones_down" data-playlist="{{ beam.get_downvalues }}">
293 <meta id="configuraciones_up" data-playlist="{{ beam.get_upvalues }}">
294 <meta id="sda" data-toggle="" -->
295
283 296 {% if beam.id == active_beam %}
284 297 <table class="legend">
285 298 <tr>
@@ -301,8 +314,12
301 314 {% else %}
302 315 <div style="vertical-align: top; display:inline-block;">
303 316 <button id="send_beam{{forloop.counter}}" type="button" class="btn btn-default">
304 <span class="fas fa-external-link-square-alt" aria-hidden="true"></span>
305 Change Beam</button>
317 <span class="fas fa-external-link-square-alt" aria-hidden="true"></span>
318 Change Beam</button>
319 <br><br><br>
320 <button id="change_beam_mqtt{{forloop.counter}}" type="button" class="btn btn-default">
321 <span class="fas fa-external-link-square-alt" aria-hidden="true"></span>
322 Change Beam MQTT</button>
306 323 </div>
307 324 {% endif %}
308 325 </div>
@@ -317,23 +334,51
317 334 </p>
318 335 {% endif %}
319 336 {% endblock extra-content %}
337
320 338 {% block extra-js%}
321 339 <script>
322 340 $(document).ready(function () {
341
342 var socket = io.connect('http://' + document.domain + ':' + location.port);
323 343
324 {% for beam in beams %}
344 socket.on('connect', function(data) {
345 console.log('Connecting... OK');
346 })
325 347
326 {% if dev_conf.operation_mode == 1 %}
327 $("#send_beam{{forloop.counter}}").prop('disabled', true)
328 {% else %}
329 $("#send_beam{{forloop.counter}}").click(function () {
330 document.location = "{% url 'url_send_beam' dev_conf.id beam.id %}";
331 });
332 {% endif %}
348 socket.on('abs_ws', function(data) {
349 console.log('ingresamos');
350 console.log(data.msg);
351 var text = data['msg'];
352 // $('#chatLog').val(text);
333 353
334 {% endfor %}
354 if(data.msg=="b\'Hola\'"){console.log('Hola_amigo')};
355 })
356
357
358 {% for beam in beams %}
359
360 {% if dev_conf.operation_mode == 1 %}
361 $("#send_beam{{forloop.counter}}").prop('disabled', true)
362 $("#change_beam_mqtt{{forloop.counter}}").prop('disabled', true)
363 {% else %}
364 $("#send_beam{{forloop.counter}}").click(function () {
365 document.location = "{% url 'url_send_beam' dev_conf.id beam.id %}";
366 });
367
368 a=$("#change_beam_mqtt{{forloop.counter}}")
369 a.click(function () {
370 info="change_beam_mqtt{{forloop.counter}}"
371 socket.emit('change_beam',{data:info})
372 });
335 373
374 {% endif %}
375
376 {% endfor %}
377
378
379 });
336 380
337 });
338 381 </script>
382
383
339 384 {% endblock %}
@@ -24,6 +24,8 from .utils.overJroShow import overJroShow
24 24 #Create your views here.
25 25 import json, ast
26 26
27 from .mqtt import client as mqtt_client
28 from radarsys.socketconfig import sio as sio
27 29
28 30 def get_values_from_form(form_data):
29 31
@@ -246,6 +248,41 def import_file(request, id_conf):
246 248 return render(request, 'abs_import.html', kwargs)
247 249
248 250
251 # def send_mqtt(request,id_conf):
252
253 # # conf = get_object_or_404(ABSConfiguration, pk=id_conf)
254
255 # # abs_mqtt = Configuration.objects.filter(pk=conf.device.conf_active).first()
256 # # if abs_mqtt!=conf:
257 # # url_mqtt = '#' if abs is None else abs.get_absolute_url()
258 # # label_mqtt = 'None' if abs is None else abs.label
259 # # messages.warning(
260 # # request,
261 # # mark_safe('The current configuration has not been written in the modules, the active configuration is <a href="{}">{}</a>'.format(
262 # # url_mqtt,
263 # # label_mqtt
264 # # ))
265 # # )
266 # # return redirect(conf.get_absolute_url())
267
268 # # beam = get_object_or_404(ABSBeam, pk=id_beam)
269
270 # conf = get_object_or_404(ABSConfiguration, pk=id_conf)
271
272 # mqtt_client.publish('abs/beams_up', 'Hola up')
273 # mqtt_client.publish('abs/beams_down', 'Hola down')
274
275 # kwargs = {
276 # 'title': 'ABS',
277 # 'suptitle': conf.label,
278 # 'message': 'Are you sure you want to write ABS Beam?',
279 # 'delete': False
280 # }
281 # kwargs['menu_configurations'] = 'active'
282
283 # return render(request, 'confirm.html', kwargs)
284
285
249 286 def send_beam(request, id_conf, id_beam):
250 287
251 288 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
@@ -443,3 +480,33 def plot_pattern(request, id_conf, id_beam, antenna):
443 480 response = HttpResponse(buf.getvalue(), content_type='image/png')
444 481 return response
445 482
483 import os
484 from django.http import HttpResponse
485
486 @sio.on('connection-bind')
487 def abs_connection_bind(sid, data):
488 print("sid:",sid,"data",data)
489
490 @sio.on('disconnect')
491 def abs_test_disconnect(sid):
492 print("Disconnected")
493
494 @sio.event
495 def abs_send_beam_up(sid, message):
496 mqtt_client.publish('abs/beams_up', message['data'])
497
498 @sio.event
499 def abs_send_beam_down(sid, message):
500 mqtt_client.publish('abs/beams_down', message['data'])
501
502 @sio.event
503 def change_beam(sid,message):
504 data=str(message['data'])
505 data=data[16]
506 mqtt_client.publish('abs/change_beam',data)
507
508
509
510
511
512
@@ -1,3 +1,4
1 import os
1 2 import paho.mqtt.client as mqtt
2 3 from radarsys import settings
3 4 from radarsys.socketconfig import sio as sio
@@ -16,11 +17,11 def maxima_temp(trs):
16 17 return max(temps)
17 18
18 19 def on_message(mqtt_client, userdata, msg):
19 print(f'Received message on topic: {msg.topic} with payload: {msg.payload}', flush=True)
20 # print(f'Received message on topic: {msg.topic} with payload: {msg.payload}', flush=True)
20 21 trsi = [[],[],[],[]]
21 22 mensaje = str(msg.payload)
22 23 datos = [i for i in mensaje[21:-1].split("*")]
23 status=''.join([datos[i][3] for i in [0,1,2,3]])
24 status=''.join([datos[i][3] for i in range(3)])
24 25 for trs,i in zip(datos,[0,1,2,3]) :
25 26 trsi[i]= [int(i) for i in trs[1:-1].split(",")]
26 27 potencias = [trsi[0][34],trsi[0][36],trsi[2][32],trsi[2][34]]
@@ -30,9 +31,9 def on_message(mqtt_client, userdata, msg):
30 31 client = mqtt.Client()
31 32 client.on_connect = on_connect
32 33 client.on_message = on_message
33 client.username_pw_set(settings.MQTT_USER, settings.MQTT_PASSWORD)
34 client.username_pw_set(os.environ.get('MQTT_USER_ATRAD', 'atrad'), os.environ.get('MQTT_PASSWORD_ATRAD', 'atrad'))
34 35 client.connect(
35 host=settings.MQTT_SERVER,
36 port=settings.MQTT_PORT,
37 keepalive=settings.MQTT_KEEPALIVE
36 host=os.environ.get('MQTT_SERVER', '0.0.0.0'),
37 port=int(settings.os.environ.get('MQTT_PORT', 1883)),
38 keepalive=int(os.environ.get('MQTT_KEEPALIVE', 36000))
38 39 ) No newline at end of file
@@ -170,7 +170,7 django.utils.encoding.force_text = force_str
170 170 # choose of auto-created primary keys
171 171 DEFAULT_AUTO_FIELD='django.db.models.AutoField'
172 172
173 MQTT_SERVER = '10.10.10.99'
173 MQTT_SERVER = '10.10.10.200'
174 174 MQTT_PORT = 1883
175 175 MQTT_KEEPALIVE = 60
176 176 MQTT_USER = ''
General Comments 0
You need to be logged in to leave comments. Login now