Hey everyone.. I am working on a project that has two temperature sensors each connected to individual NodeMCUs. One acts as a slave and other a master. The slave has to send the sensor data to the master through serial communication and master combines the slave's data and its own data. I have used Software Serial for communication. What I need is the master has to wait for the slave to send the data and then print it in the serial monitor. I tried using
while (!serial.available());
, but it doesnt work as I needed.
This is the snippet of Master's Code:
void temp_monitor_master()
float C_tot;
float C_avg, temp;
int input=1, sample=20;
String string_Cavg;
{
for(int i=1; i<=20 ; i++){
C_tot=C_tot+mlx.readObjectTempC();
delay(100);
}
C_avg=C_tot/20;
C_avg = 60;
if((sample>5 && sample <100) && (C_avg>20 && C_avg<100) ){
string_Cavg=String(C_avg,1);
Serial.println(string_Cavg);
Serial.println("Controller 1 (Master)");
Serial.print("<0"); Serial.print(sample);
Serial.print(" 0"); Serial.print(C_avg);
Serial.print(">");
while (serial1.available()<1);
{
Serial.println(serial1.readStringUntil('n'));
}
C_avg=0;
C_tot=0;
}
}
The code Slave:
int C_tot;
int C_avg, temp;
int input, sample=20;
String str;
void temp_monitor_slave(){
for(int i=1; i<=20 ; i++){
C_tot=C_tot+mlx.readObjectTempC();
delay(100);
}
C_avg=C_tot/20;
Serial.print("nAv/erage Celsius = ");
Serial.print(C_avg);
Serial.println("*C");
if((sample>5 && sample <100) && (C_avg>20 && C_avg<100) ){
str = String("(0") + String (sample) + String(" 0") + String(C_avg) + String(")");
Serial.println(str);
serial1.print(str);
C_avg=0;
C_tot=0;
}
}
Thanks in advance...