Hi,
I'm new to the ESP32. I'm setting up a personal project to monitor voltage and current for a solar system via TCP/IP. I'm using LabVIEW to monitor the readings of 4 parameters . I've found some examples from the internet related to ESP32 wifiserver and made some modifications to the program. Previously, I used the ESP8266, but since ESP8266 only has 1 analog input, I tried using ESP32 which is more convenient. The ESP8266 program works fine together with the LabVIEW, however when using ESP32, the program doesn't read sensor readings. Can anyone help me identify where I might have gone wrong?
Thank you.
#include <WiFi.h>
#define SERVER_PORT 8000
const int V_Panel = 34;
const int V_batt = 35;
const int curr_panel = 36;
const int curr_load = 37;
const int led = 4;
const char* ssid = "zippo z78";
const char* password = "flash76";
WiFiServer server(SERVER_PORT);
float temp=0.0;
float current_IN = 0.00;
float current_LOAD =0.00;
float V_panel = 0.00;
float V_battery = 0.00;
float Vout1 = 0.00;
float Vout2 = 0.00;
float Vout5 = 0.00;
float Vout6 = 0.00;
float Vout7 = 0.00;
float Vout8 = 0.00;
float Vout9 = 0.00;
float R1 = 30900.0;
float R2 = 4700.0;
float R5 = 3300.0;
float R6 = 6800.0;
int i;
int Vpanel;
int Vbatt;
int ipanel;
int iload;
void setup()
{
Serial.begin(115200);
Serial.println("");
Serial.println("");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{ Serial.print("->");
delay(200);
}
Serial.println("");
Serial.println("WiFi Successfully Connected");
Serial.print("NodeMCU IP address: ");
Serial.println(WiFi.localIP());
server.begin();
Serial.println("NodeMCU as a Server Role Started");
for(i=0;i<25;i++)
{ digitalWrite(led,HIGH);
delay(10);
digitalWrite(led,LOW);
delay(10);
}
}
void loop()
{ WiFiClient client = server.available();
if (client)
{ Serial.println("Hi...New Client");
for(i=0;i<2;i++)
delay(20);
digitalWrite(led,LOW);
//delay(20);
}
while(1)
{ while(client.available())
{ digitalWrite(led,HIGH);
delay(10);
digitalWrite(led,LOW);
delay(10);
uint8_t data =client.read();
Serial.write(data);
switch (data)
{
case 'b': // take sample of solar panel voltage
Vpanel = analogRead(V_Panel);
Vout1 = Vpanel*3.3/1023;
Vout2 = Vout1*(R1+R2)/R2;
V_panel= Vout2;
Serial.println(V_panel);
client.println(V_panel);
delay(100);
break;
case 'c': //Take sample of battery voltage (V)
Vbatt = analogRead(V_batt);
Vout5 = Vbatt*3.3/1023;
V_battery = Vout5*(R1+R2)/R2;
Serial.println(V_battery);
client.println(V_battery);
delay(100);
break;
case 'd': // take sample of input current (A)
ipanel = analogRead(curr_panel);
Vout6 = ipanel*3.3/1023;
Vout7 = Vout6*((R5+R6)/R6);
current_IN = (Vout7-2.5)/0.185;
Serial.println(current_IN);
client.println(current_IN);
delay(100);
break;
case 'e': // take sample of load current (A)
iload = analogRead(curr_load);
Vout8 = iload*3.3/1023;
Vout9 = Vout8*((R5+R6)/R6);
current_LOAD = (Vout9-2.5)/0.185;
Serial.println(current_LOAD);
client.println(current_LOAD);
delay(100);
break;
}
}
if(server.hasClient())
{ return;
}
}
}