@@ -27,48 +27,27 void setup() { | |||
|
27 | 27 | Serial.print("Voltaje pkpk:"); Serial.print(" "); Serial.println(Vpk); |
|
28 | 28 | } |
|
29 | 29 | void loop() { |
|
30 | total=0; | |
|
31 | //analogValue = analogRead(pinADC); | |
|
32 | /* | |
|
33 | for (int i = 0; i < numSamples; i++) { | |
|
34 | total += analogRead(pinADC); | |
|
35 | }*/ | |
|
36 | //int averageValue = total / numSamples; | |
|
37 | 30 | int averageValue=analogRead(pinADC); |
|
38 | 31 | Vout = 0.8291*averageValue+90.27;//Ajuste realizado para el ADC |
|
39 | //Serial.println(Vout); | |
|
40 | 32 | Plcal=5*pow((Vout+101),2)/(2*175.19*175.19);//Calculamos la potencia en la línea |
|
41 | 33 | //dif=abs(Plinea-Plcal)*100/Plinea;//Hallamos la diferencia porcentual |
|
42 |
if (Plcal> |
|
|
34 | if (Plcal>4){//valores por debajo de este umbral serán leidos como tierra | |
|
43 | 35 | Parray[contador]=Plcal; |
|
44 | 36 | contador =contador+1; |
|
45 | 37 | } |
|
46 | 38 | //cuando llenamos los valores hacemos la |
|
47 |
if (contador |
|
|
39 | if (contador>(SIZE-1)){ | |
|
48 | 40 | p=&Parray[0]; |
|
49 | 41 | Pmax=find_maximun(p); |
|
50 | 42 | contador=0; |
|
51 | 43 | dif=abs(Plinea-Pmax)*100/Plinea; |
|
52 | 44 | difPlow=abs(Plinea-Pmax); |
|
53 | if(dif>10 && difPlow>7) Serial.println(Pmax); | |
|
54 | } | |
|
55 | ||
|
56 | ||
|
57 | /* | |
|
58 | if(dif>10 && Vout>120 ){ | |
|
59 | Parray[contador]=Plcal; | |
|
60 | contador =contador+1; | |
|
61 | if(contador==SIZE){ | |
|
62 | p=&Parray[0]; | |
|
63 | Pmax=find_maximun(p); | |
|
64 | contador=0; | |
|
65 | difPlow=abs(Plinea-Pmax); | |
|
66 | if (difPlow>8) { | |
|
67 | Serial.print("Potencia anomala en el transmisor: "); | |
|
68 | Serial.println(Pmax); | |
|
69 | } | |
|
45 | Serial.print("Valor normal: "); Serial.println(Pmax); | |
|
46 | if(dif>10 && difPlow>9) { | |
|
47 | Serial.print("Nivel anómalo: "); | |
|
48 | Serial.println(Pmax); | |
|
70 | 49 | } |
|
71 |
|
|
|
50 | } | |
|
72 | 51 | } |
|
73 | 52 | float ecuacionLineal(float Vpk){ |
|
74 | 53 | float m=175.19,b=-101; |
@@ -1,17 +1,18 | |||
|
1 | 1 | #include <WiFi.h> |
|
2 | 2 | #include <PubSubClient.h> |
|
3 | 3 | |
|
4 |
const char *ssid = " |
|
|
4 | const char *ssid = "HUAWEI P smart"; | |
|
5 | 5 | const char *password = "12345678"; |
|
6 |
const char *mqtt_server = "192.168. |
|
|
6 | const char *mqtt_server = "192.168.43.149"; | |
|
7 | 7 | const int mqtt_port = 1883; |
|
8 | 8 | const char *mqtt_client_id = "ESP32_Client"; |
|
9 | 9 | const char *subscribe_topic = "tesis/potenciaNominal"; |
|
10 | 10 | const char *publish_topic = "tesis/potencia"; |
|
11 | const char *publish_topic_voltage = "tesis/ReferenceVoltage"; | |
|
11 | 12 | |
|
12 | 13 | WiFiClient espClient; |
|
13 | 14 | PubSubClient client(espClient); |
|
14 | ||
|
15 | float Vpk=0,Vout=0; | |
|
15 | 16 | void setup_wifi() { |
|
16 | 17 | delay(10); |
|
17 | 18 | Serial.println(); |
@@ -38,11 +39,13 void callback(char *topic, byte *payload, unsigned int length) { | |||
|
38 | 39 | // Convierte la cadena a un número (en este caso, asume que es un float) |
|
39 | 40 | float potenciaNominal = atof(receivedValue); |
|
40 | 41 | // Realiza cálculos basados en la potencia nominal recibida (sustituye con tu lógica) |
|
41 | float voltajeCalculado = potenciaNominal * 1.2; | |
|
42 | Vpk= sqrt(10*potenciaNominal)/5; | |
|
43 | Vout=175.19*Vpk-101; | |
|
44 | ||
|
42 | 45 | // Publica el resultado en el tópico de voltaje |
|
43 | 46 | char result[10]; |
|
44 |
snprintf(result, sizeof(result), "%.2f", |
|
|
45 | client.publish(publish_topic, result); | |
|
47 | snprintf(result, sizeof(result), "%.2f", Vout); | |
|
48 | client.publish(publish_topic_voltage, result); | |
|
46 | 49 | } |
|
47 | 50 | |
|
48 | 51 | void reconnect() { |
General Comments 0
You need to be logged in to leave comments.
Login now