Skip to content

Instantly share code, notes, and snippets.

@bathoryr
Last active January 20, 2019 09:01
Show Gist options
  • Save bathoryr/c381a95bc625bdc230eb63193d781f72 to your computer and use it in GitHub Desktop.
Save bathoryr/c381a95bc625bdc230eb63193d781f72 to your computer and use it in GitHub Desktop.
MySensors send message with ACK and wait for confirmation message
bool magAck;
MyMessage msgBtn(PIN_BUTTON_1, V_TRIPPED);
void loop()
{
int8_t btn = sleep(0, CHANGE, 1, CHANGE, 3600000);
if (btn >= 0)
{
delay(20);
msgBtn.sensor = PIN_BUTTON_1 + btn;
msgAck = false;
for (int i = 0; msgAck == false && i < 3; i++)
{
send(msgBtn.set(digitalRead(PIN_BUTTON_1 + btn) == LOW), true);
wait(500, C_SET, V_TRIPPED);
}
}
}
void receive(const MyMessage& msg)
{
if (msg.isAck() && msg.sensor == PIN_BUTTON && msg.type == V_TRIPPED)
{
msgAck = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment