Compare commits
2 Commits
main
...
PC_STA-udp
| Author | SHA256 | Date | |
|---|---|---|---|
| 8ce167fa4c | |||
| 310a057795 |
+13
-18
@@ -5,17 +5,18 @@
|
|||||||
#define MAX_PACKAGES 100
|
#define MAX_PACKAGES 100
|
||||||
#define TICKS 1000
|
#define TICKS 1000
|
||||||
|
|
||||||
const char* SSID="Tenda_32C850";
|
const char* SSID="fedora";
|
||||||
const char* PASSWD="rhLcrMEcY^Xjvq66";
|
const char* PASSWD="kESOdSke";
|
||||||
// COnfigurar direcciones fijas
|
// COnfigurar direcciones fijas
|
||||||
IPAddress local_ip(192,168,0,150);
|
IPAddress local_ip(10,42,0,150);
|
||||||
IPAddress gateway(192,168,0,1);
|
IPAddress gateway(10,42,0,1);
|
||||||
IPAddress subnet(255,255,255,0);
|
IPAddress subnet(255,255,255,0);
|
||||||
IPAddress dns1(192,168,0,100);
|
IPAddress dns1(10,42,0,1);
|
||||||
IPAddress dns2(1,1,1,1);
|
IPAddress dns2(1,1,1,1);
|
||||||
|
|
||||||
NetworkServer server(8080);
|
IPAddress IP_C(10,42,0,1);
|
||||||
NetworkClient client = server.accept();
|
#define PORT_C 8080
|
||||||
|
NetworkUDP udp;
|
||||||
|
|
||||||
uint8_t i=0;
|
uint8_t i=0;
|
||||||
|
|
||||||
@@ -40,14 +41,13 @@ void setup() {
|
|||||||
delay(500);
|
delay(500);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
}
|
}
|
||||||
|
udp.begin(8080);
|
||||||
|
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
Serial.println("WiFi connected");
|
Serial.println("WiFi connected");
|
||||||
Serial.println("IP address: ");
|
Serial.println("IP address: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
server.begin();
|
|
||||||
|
|
||||||
// Iniciar y desbloquear la bandera
|
// Iniciar y desbloquear la bandera
|
||||||
timerSemaphore = xSemaphoreCreateBinary();
|
timerSemaphore = xSemaphoreCreateBinary();
|
||||||
xSemaphoreGive(timerSemaphore);
|
xSemaphoreGive(timerSemaphore);
|
||||||
@@ -60,14 +60,9 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (!client || !client.connected()) {
|
|
||||||
client = server.accept();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xSemaphoreTake(timerSemaphore, portMAX_DELAY) == pdTRUE) {
|
if (xSemaphoreTake(timerSemaphore, portMAX_DELAY) == pdTRUE) {
|
||||||
if (client && client.connected()) {
|
udp.beginPacket(IP_C,PORT_C);
|
||||||
uint8_t imagen=i;
|
udp.write(i);
|
||||||
client.printf("%03u",imagen);
|
udp.endPacket();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
import csv
|
||||||
|
import time
|
||||||
|
import threading
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import socket
|
||||||
|
import time
|
||||||
|
from websocket import create_connection
|
||||||
|
|
||||||
|
HOST="0.0.0.0"
|
||||||
|
PORT=8080
|
||||||
|
CSV_NOMBRE = "Router_STA_UDP.csv"
|
||||||
|
PNG_NOMBRE = "ROUTER_STA_UDP.png"
|
||||||
|
|
||||||
|
row_data=[]
|
||||||
|
|
||||||
|
inicio=time.perf_counter()
|
||||||
|
duracion=300
|
||||||
|
|
||||||
|
lock = threading.Lock()
|
||||||
|
running = True
|
||||||
|
|
||||||
|
|
||||||
|
def graficar():
|
||||||
|
plt.ion()
|
||||||
|
fig, ax1 = plt.subplots()
|
||||||
|
ax2 = ax1.twinx()
|
||||||
|
|
||||||
|
line_data, = ax2.plot([], [])
|
||||||
|
|
||||||
|
ax1.set_ylim(0, 100)
|
||||||
|
ax2.set_ylim(0, 100)
|
||||||
|
|
||||||
|
while running:
|
||||||
|
with lock:
|
||||||
|
|
||||||
|
data_copy = row_data.copy()
|
||||||
|
|
||||||
|
if len(data_copy) > 1:
|
||||||
|
|
||||||
|
t = [i / 1000 for i in range(len(data_copy))] # aprox 1kHz
|
||||||
|
|
||||||
|
datos = [x[0] for x in data_copy]
|
||||||
|
lag = [x[1] for x in data_copy]
|
||||||
|
|
||||||
|
|
||||||
|
t = t[-1000:]
|
||||||
|
datos = datos[-1000:]
|
||||||
|
lag = lag[-1000:]
|
||||||
|
|
||||||
|
line_data.set_data(t, datos)
|
||||||
|
|
||||||
|
ax1.set_xlim(t[0], t[-1])
|
||||||
|
|
||||||
|
plt.pause(0.01)
|
||||||
|
|
||||||
|
plt.savefig(PNG_NOMBRE, dpi=500)
|
||||||
|
|
||||||
|
|
||||||
|
# lanzar hilo de gráfica
|
||||||
|
thread_plot = threading.Thread(target=graficar)
|
||||||
|
thread_plot.start()
|
||||||
|
t_prev = time.perf_counter()
|
||||||
|
|
||||||
|
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
client.bind((HOST,PORT))
|
||||||
|
|
||||||
|
while time.perf_counter() - inicio < duracion:
|
||||||
|
row,address=client.recvfrom(1)
|
||||||
|
data=row[0]
|
||||||
|
t_now = time.perf_counter()
|
||||||
|
delta = (t_now - t_prev) * 1000 # ms
|
||||||
|
t_prev = t_now
|
||||||
|
|
||||||
|
with lock:
|
||||||
|
row_data.append([data, delta])
|
||||||
|
|
||||||
|
running = False
|
||||||
|
thread_plot.join()
|
||||||
|
|
||||||
|
data_final = [[d, round(l, 3)] for d, l in row_data]
|
||||||
|
with open(CSV_NOMBRE, 'w', newline='', encoding='utf-8') as archivo:
|
||||||
|
write = csv.writer(archivo, quoting=csv.QUOTE_NONE, escapechar='\\')
|
||||||
|
write.writerows(data_final)
|
||||||
|
|
||||||
|
print(f"Datos recibidos:{len(row_data)}")
|
||||||
Reference in New Issue
Block a user