receive different strings of data in processing.
in
Core Library Questions
•
2 years ago
Hi, Im having probelms getting processing to recognise the different set of data during serialEvent()
I have data coming in every 4 seconds for live graphing, when a button is pressed on my interface it sends a string to my arduino requesting different types of data,once the data is through the arduino continues sending the 4second data, I have tested it on the arduino serial monitor and its working as expected but processing is not grabbing the data and parsing it. Im having little success with this serialEvent() I have set both data packets with start and end packet markers of [] and {}.
- void serialEvent(Serial myPort){
println("Called");
int mapped_tempc = 0;
int mapped_rh = 0;
int mapped_ldr =0;
if(myport.read() == '[')
{
print("Data");
String inString = myport.readStringUntil(']');
inString = inString.substring(0, inString.length() - 1);
if(inString != null )
{
inString = trim(inString);
int inputs[] = int(split(inString, ','));
Temp_C = inputs[0];
Temp_F = inputs[1];
RH = inputs[2];
Lightlev = inputs[3];
mapped_tempc = inputs[4];
mapped_rh = inputs[5];
mapped_ldr = inputs[6];
date_day = inputs[7];
date_month = inputs[8];
date_year = inputs[9];
time_hours = inputs[10];
time_minutes = inputs[11];
Max_TempC = inputs[12] + "C";
Min_TempC = inputs[13] + "C";
Max_TempF = inputs[14] + "F";
Min_TempF = inputs[15] + "F";
Max_RH = inputs[16] + "%";
Min_RH = inputs[17] + "%";
MaxTempDate = inputs[18] + "/" + inputs[19] + "/" + inputs[20];
MaxTempTime = inputs[21] + ":";
if(inputs[22] < 10) { MaxTempTime += "0";}
MaxTempTime += inputs[22];
MinTempDate = inputs[23] + "/" + inputs[24] + "/" + inputs[25];
MinTempTime = inputs[26] + ":";
if(inputs[27] < 10) { MinTempTime += "0";}
MinTempTime += inputs[27];
MaxRHDate = inputs[28] + "/" + inputs[29] + "/" + inputs[30];
MaxRHTime = inputs[31] + ":";
if(inputs[32] < 10) { MaxRHTime += "0";}
MaxRHTime += inputs[32];
MinRHDate = inputs[33] + "/" + inputs[34] + "/" + inputs[35];
MinRHTime = inputs[36] + ":";
if(inputs[37] < 10) { MinRHTime += "0";}
MinRHTime += inputs[37];
All_TempC = Temp_C + "C";
All_TempF = Temp_F + "F";
All_RH = RH + "%";
for(int i = 0; i < 38; i ++)
{
DataStream += inputs[i] + ":";
}
if(Lightlev > 5)
{
lightlevel = true;
}
else
{
lightlevel = false;
}
Array_Data.addval(mapped_tempc, mapped_rh,checkStatus(0,Temp_C), checkStatus(1,RH));
if(time_minutes < 10)
{
All_Time = time_hours + ":" + "0" + time_minutes;
}
else
{
All_Time = time_hours + ":" + time_minutes;
}
All_Date = date_day + "/" + date_month + "/" + date_year;
ExcelGraphData.print(Temp_C + " ," + RH + " ," + Lightlev + " ," + All_Date + " ," + All_Time + "\n");
ExcelGraphData.flush();
}
}
if(myport.read() == '{')
{
println("Max/Min");
Display_SevenDay = true;
String inhistString = myport.readStringUntil('}');
inhistString = inhistString.substring(0, inhistString.length() - 1);
if(inhistString != null )
{
inhistString = trim(inhistString);
int history_ints[] = int(split(inhistString, ','));
for(int i = 0;i < 50;)
{
println(history_ints[i]);
int t = 0;
int h = 0;
t = history_ints[i];
i++;
h = history_ints[i];
Array_Data.addsevenval(t, h,checkStatus(0,t), checkStatus(1,h));
}
}
}
myport.clear();
}
1