I’ve been using a Webhook forever…
which takes the event value and sends a Pushover notification:
but adding to a new Serial Bridge that I created:
const size_t MAX_MESSAGE_LENGTH = 32;
void setup()
{
Serial1.begin(57600);
Serial.begin(115200);
pinMode(D7, OUTPUT);
digitalWrite(D7, HIGH);
}
void loop()
{
if(const char* newMessage = checkForNewMessage(Serial1, '\n'))
{
Serial1.println(newMessage);
Serial.println(newMessage);
Particle.publish("pushover", newMessage, 60, PRIVATE);
digitalWrite(D7, !digitalRead(D7));
}
}
char* checkForNewMessage(Stream& stream, const char endMarker)
{
static char incomingMessage[MAX_MESSAGE_LENGTH] = "";
static byte idx = 0;
if(stream.available())
{
incomingMessage[idx] = stream.read();
if(incomingMessage[idx] == endMarker)
{
incomingMessage[idx] = '\0';
idx = 0;
return incomingMessage;
}
else
{
idx++;
if(idx > MAX_MESSAGE_LENGTH - 1)
{
stream.print(F("{\"error\":\"message too long\"}\n")); //you can send an error to sender here
while(stream.available())
(void)stream.read();
idx = 0;
incomingMessage[idx] = '\0';
}
}
}
return nullptr;
}
I am getting:
but the event looks OK:
any suggestions?