Last active
January 20, 2019 09:01
-
-
Save bathoryr/c381a95bc625bdc230eb63193d781f72 to your computer and use it in GitHub Desktop.
MySensors send message with ACK and wait for confirmation message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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