Hi,
Just looking for any help whatsoever.
I have three different values that I am trying to extract from a buffer. Initially the buffer is compiled from data collected by a sensor that sends at 1200 baud/s. The sensor sends the data, the buffer gets compiled, the buffer then gets sorted and the results are currently being published to the cloud. I was having a very hard time with characters sorting into other buffers (even though I didn’t think it would be that difficult). At this point I just have the same data being stored in 4 separate buffers and then being published to the cloud. When the information is published the initial buffer uploads fine, but the others do not. Sometimes they are sending nothing to the cloud and sometimes the characters are unreadable.
Here are the main parts of the code:
//Constants
const size_t READ_BUF_SIZE = 320;
const unsigned long CHAR_TIMEOUT =10000;
//Global Variables
char readBuf[READ_BUF_SIZE];
size_t readBufOffset =0;
unsigned long lastCharTime = 0;
int i;
struct DataStruct
{
char VWC[READ_BUF_SIZE];
char EC[READ_BUF_SIZE];
char TempCelsius[READ_BUF_SIZE];
};
void setup()
{
pinMode(B0,OUTPUT);
Serial.begin(9600);
Serial1.begin(1200,SERIAL_8N1);
delay(2000);
}
void loop()
{
static uint32_t ms;
DataStruct sensorData;
digitalWrite(B0,HIGH);
readBufOffset =0;
i=1;
//Reading Data from the Serial
while(Serial1.available()){
if (readBufOffset < READ_BUF_SIZE) {
char c = Serial1.read();
if (c != '\n') {
//add character to buffer
readBuf[readBufOffset++] = c;
//because I was experiencing some hardships with the sorting and publishing the right information I am just simply trying to see if there are any characters being stored in these buffers
sensorData.VWC[readBufOffset]=c;
sensorData.EC[readBufOffset]=c;
sensorData.TempCelsius[readBufOffset]=c;
lastCharTime = millis();
}
else {
//end of line character found
Serial.printlnf ("got: %s", readBuf);
Particle.publish("thebuffer",readBuf);
Serial.print("i= ");
Serial.println(i);
readBuf[readBufOffset]=0;
i=1;
}
}
Particle.publish("VWC", String(sensorData.VWC));
Particle.publish("EC", String(sensorData.EC));
Particle.publish("TempCelsius", String(sensorData.TempCelsius));
Particle.publish("thebuffer",String(readBuf));
delay(1000);
digitalWrite(B0,LOW);
delay(100000);
}
…
here is the published data.
Any help or insight would be greatly appreciated. I do not have a computer science background, but I am trying to learn as I go along. Thank you.