Compare commits
3 Commits
| Author | SHA256 | Date | |
|---|---|---|---|
| 9c9ff32f63 | |||
| 8ce167fa4c | |||
| 310a057795 |
+278192
File diff suppressed because it is too large
Load Diff
BIN
Binary file not shown.
|
After Width: | Height: | Size: 238 KiB |
+12
-24
@@ -5,17 +5,12 @@
|
||||
#define MAX_PACKAGES 100
|
||||
#define TICKS 1000
|
||||
|
||||
const char* SSID="Tenda_32C850";
|
||||
const char* PASSWD="rhLcrMEcY^Xjvq66";
|
||||
// COnfigurar direcciones fijas
|
||||
IPAddress local_ip(192,168,0,150);
|
||||
IPAddress gateway(192,168,0,1);
|
||||
IPAddress subnet(255,255,255,0);
|
||||
IPAddress dns1(192,168,0,100);
|
||||
IPAddress dns2(1,1,1,1);
|
||||
const char* SSID="ESP32-AP";
|
||||
const char* PASSWD="Tc8eX4v9TnXYQwsA";
|
||||
|
||||
NetworkServer server(8080);
|
||||
NetworkClient client = server.accept();
|
||||
IPAddress IP_C(192,168,4,2);
|
||||
#define PORT_C 8080
|
||||
NetworkUDP udp;
|
||||
|
||||
uint8_t i=0;
|
||||
|
||||
@@ -33,20 +28,17 @@ void setup() {
|
||||
Serial.begin(230400);
|
||||
|
||||
Network.begin();
|
||||
WiFi.STA.begin();
|
||||
WiFi.STA.config(local_ip,gateway,subnet,dns1,dns2);
|
||||
WiFi.STA.connect(SSID, PASSWD);
|
||||
while (WiFi.STA.status() != WL_CONNECTED) {
|
||||
WiFi.AP.begin();
|
||||
while (!WiFi.AP.create(SSID, PASSWD)) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
udp.begin(8080);
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
server.begin();
|
||||
Serial.println(WiFi.AP.localIP());
|
||||
|
||||
// Iniciar y desbloquear la bandera
|
||||
timerSemaphore = xSemaphoreCreateBinary();
|
||||
@@ -60,14 +52,10 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (!client || !client.connected()) {
|
||||
client = server.accept();
|
||||
}
|
||||
|
||||
if (xSemaphoreTake(timerSemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
if (client && client.connected()) {
|
||||
uint8_t imagen = i;
|
||||
client.printf("%03u",imagen);
|
||||
}
|
||||
udp.beginPacket(IP_C,PORT_C);
|
||||
udp.write(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