Sending Data To Dashboard Using Particle.publish

I am trying to use Particle.publish to see serial data coming from my machine. I am able to see the data in the serial monitor if I use Serial.write() but I am unsure of how to get the to show up correctly in the dashboard.

void loop() {
	// Ask machine a question
	Serial1.println("model number");

	// Look for incoming data for the next 1.5 seconds
	unsigned long start = millis();
	    while(millis() - start < 1500) {
                int c = Serial1.read();
		    if (c >= 0) {
                        // Send data to the dashboard
		        Particle.publish("Machine Data", c);
		    }
	     }
}

Any help would be great!

There’s a limit to how many times you can publish data, and you probably want to accumulate all of the characters into a single publish anyway. Something like this should work:

void loop() {
	// Ask machine a question
	Serial1.println("model number");

	// Look for incoming data for the next 1.5 seconds
	char buffer[128];
	int bufIndex = 0;
	unsigned long start = millis();
	while(millis() - start < 1500) {
        int c = Serial1.read();
		if (c >= 0 && bufIndex < (sizeof(buffer) - 1)) {
		    buffer[bufIndex++] = (char) c;
		}
	}
	buffer[bufIndex] =  0;
	if (bufIndex > 0) {
        // Send data to the dashboard
        Particle.publish("Machine Data", buffer);
	}
}

This accumulates all of the characters that arrive in the 1.5 seconds into buffer, then uses Particle.publish to send the data up, as long as it’s not empty.

That worked perfectly! Accumulating the data was my next hurdle, you’re a mind reader. Thank you for helping out again!