@ScruffR
I tried the code one more time, and it gave me the same behavior. It worked for three frames and stopped after that. I don’t know what is the issue for that.
The frame that you are seeing before that is for the original code that I’m using, which gives me delay 2-3 seconds between each frame.
What is odd is that the timestamps on the dashboard are all referencing the same second, which would explain why only three (plus the online msg) turn up.
Either one publish causes multiple events or my logic is wrong - I have to meditate over that after I’ve stopped crying
@ScruffR
I think that the publish might cause multiple events since two of these three frames are different. Thanks for helping me in that. I’ll try tomorrow to check the output on the USB serial, and let you know what is happening there. I just have a stupid question about the USB serial. Do I need to put the Spark on the listening mode to read the data?
Thanks in advance.
No, as soon you do Serial.begin() the serial port on the Particle device gets opened and data gets sent, no matter if there is anybody receiving or not.
I don’t know the expected output/protocol, so I can’t tell right from wrong.
But if you got the baud rate right and the other settings of the sensor match (8bit, 1stop, no parity) this is pretty sure what the Particle “hears” from your sensor.
Could there be problems with the wiring?
One other thing to try is to add a buffer flush - I’ll whip something up.
On second thought it might even be more likely to be a buffer issue.
I guess your sensor is already filling up the buffer before you got chance to read anything out the buffer.
So try Serial1.flush() as last line in setup() and in the if() block.
If this does not work try this function instead.
Actually the correct data should be something like this:
and the wrong data is:
I did make sure that the sensors send correct data through the serial port on the PC by using the Putty. Also, the board that gives me the sensor's data sets on the same setting that you mentioned. In addition, I'm sure that the wiring is correct, since the original code that I posted gave me correct data but with long delay(between 2-3 seconds). Do yo think that I should make a serial1.flush(); or something like szReceive=" "; after each publishing?
@ScruffR
It didn’t work, but I’d like to test the flush function instead. Where I should put this function? Because I put it after the third if, but it gave me this error:
test3.cpp: In function 'void loop()':
test3.cpp:44:2: error: a function-definition is not allowed here before '{' token
//ms = millis();
make: *** [test3.o] Error 1
I put it before the void loop(), and it compiled correctly. I’m trying it now.
Thanks in advance.
@ScruffR
The same issue with the flush function. I’ll try tomorrow to see the data on the serial USB to make sure there is nothing wrong with the sensor’s data, and I’ll let you know about that .
I appreciated your kindly help.
Thanks a lot for your time.