Circular Buffer For Handling Rapid Particle Events


#42

There is two Serial events happening concurrently in my code the main one being used for Serial Monitor and the other (ptSerial) used to send to the photon.


#43

which code is that? did you try my latest version?


#44

So the code I pasted just now above is the code on my Arduino with the RFID Shield on it.

I just used the latest version you provided a second ago and boy a remarkable difference in output!

TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 just crossed the line...TestTrackTag02 is known to meTestTrackTag02 was in the queue.TestTrackTag02 added to the queue.TestTrackTag02 sent to publishManager with a time of: 1526351218.


#45

that’s what I’d expect to see…

and the Console?


#46

I provided this so that might be able to make sense of my lack of programming capabilities and see what the Arduino is sending the Particle device.


#47

So the Photon’s serial is what I’d expect. Did you get what you wanted in the Particle Console?


#48


#49

As you can see from the screen shot. I am getting some success here (Thanks to you). So I have a question about timing. Is it expected to pub as soon as it see’s a tag and then employ hysteresis to ignore that tag for 3 seconds? Or is it the other way around? Meaning we need to see this tag for 3 seconds then pub?


#50

OK, good… just play around with this:

constexpr uint16_t CROSSING_HYSTERESIS_SECONDS = 3; 

by changing the value of 3 to some other number that meets your requirements. It is the time that a publish is held in the vector, ignoring the other messages.

and add to these:

Serial.printf("%s was in the queue.", crossingRunner);

this:

Serial.printf("%s was in the queue.\n", crossingRunner);

a new line so that you don’t get the muddled mess I handed to you (sorry).


#51

08%20PM


#52

I can’t say thank you enough! This is brilliant work! I am heavily looking into C++ publications and NewLib to get a better understanding of programming on this subject. I can program web based languages all day (JS, HTM, PHP, CSS, etc) but this topic has always been on the bucket list.


#53

:upside_down_face:

So the logic here is that the runner has passed the reader… the last read time is what gets published.

If you want to record (publish) the time that the runner approached the reader (the first read time), then we would have to modify a bit. I thought this would get you pretty close.

EDIT:

it seems you merely need to swap the timestamp here:

for (size_t i = 0; i < runners.size(); i++) {
                if (strcmp(runners[i].runnerTag, newRunner.runnerTag) == 0) {
                    newRunner.ts =  runners[i].ts; // <<<<<<<<< here
                    runners.erase(runners.begin() + i);
                    Serial.printf("%s was in the queue.", crossingRunner);
                    break; // <<<<<<<<<< adding this will speed this up a bit too!
                }
            }

to record the approaching timestamp. (not tested)


#54

#55

@BulldogLowell

I think there is a issue with the hysteresis here. I can read the same tag and it won’t ignore it. So I can get like 4 of the same read a couple seconds apart and I have it set for 8.


#56


#57

those look like they are 4 seconds apart…

What’s happening on the Serial Monitor?


#58

@BulldogLowell

I got it working just now. Might I ask why the data that I am supposedly passing in JSON doesn’t look so JSON like in the console? I get a bunch of unwanted \ and “ in the data.


#59

Hmmmm… can you show what you are getting?