I'm trying to read serial data from a unit and print it, over the RX/TX pins into a non PC controller. This is my code I've written, but it doesn't seem to be working. Does anyone have any suggestions?
void keypad(const char *event, const char *data);//forward declaration
String outgoingString;
void setup() {
Serial1.begin(9600, SERIAL_8N2);//begin serial at: 9600baud, 8 data bits, no
parity, 2 stop bits
Particle.subscribe("Janus485b", keypad, MY_DEVICES);// subscribe to
secondary publish of data from keypad
}
void loop() {
//read incoming data on serial, and publish back to secondary for keypad
while(Serial1.available() > 0){
String incomingString = Serial1.readStringUntil('\n');
Particle.publish("Janus485a", incomingString, PRIVATE);
Serial1.flush();//wait for serial buffer to empty
}
}
void keypad(const char *event, const char *data) {
//read incoming data from secondary at keypad, write to controller
String outgoingString = ("received value=0x%x", outgoingString);
Serial1.write((uint8_t*)&data, sizeof(data));
Serial1.flush();//wait for serial buffer to empty
}