@@ -349,12 +349,12 @@ boolean MySensor::process() {
349
349
// Check if sender requests an ack back.
350
350
if (mGetRequestAck (msg)) {
351
351
// Copy message
352
- ack = msg;
353
- mSetRequestAck (ack ,false ); // Reply without ack flag (otherwise we would end up in an eternal loop)
354
- mSetAck (ack ,true );
355
- ack .sender = nc.nodeId ;
356
- ack .destination = msg.sender ;
357
- sendRoute (ack );
352
+ tmpMsg = msg;
353
+ mSetRequestAck (tmpMsg ,false ); // Reply without ack flag (otherwise we would end up in an eternal loop)
354
+ mSetAck (tmpMsg ,true );
355
+ tmpMsg .sender = nc.nodeId ;
356
+ tmpMsg .destination = msg.sender ;
357
+ sendRoute (tmpMsg );
358
358
}
359
359
360
360
if (command == C_INTERNAL) {
@@ -591,18 +591,21 @@ int8_t MySensor::sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, ui
591
591
}
592
592
593
593
bool MySensor::sign (MyMessage &message) {
594
- MyMessage msgNonce;
595
- if (!sendRoute (build (msgNonce, nc.nodeId , message.destination , message.sensor , C_INTERNAL, I_GET_NONCE, false ).set (" " ))) {
594
+ if (!sendRoute (build (tmpMsg, nc.nodeId , message.destination , message.sensor , C_INTERNAL, I_GET_NONCE, false ).set (" " ))) {
596
595
return false ;
597
596
} else {
598
597
// We have to wait for the nonce to arrive before we can sign our original message
599
598
// Other messages could come in-between. We trust process() takes care of them
600
599
unsigned long enter = millis ();
600
+ msgSign = message; // Copy the message to sign since message buffer might be touched in process()
601
601
while (millis () - enter < 5000 ) {
602
602
if (process ()) {
603
- if (getLastMessage ().type == I_GET_NONCE_RESPONSE) {
603
+ if (mGetCommand ( getLastMessage ()) == C_INTERNAL && getLastMessage ().type == I_GET_NONCE_RESPONSE) {
604
604
// Proceed with signing if nonce has been received
605
- if (signer.putNonce (getLastMessage ()) && signer.signMsg (message)) return true ;
605
+ if (signer.putNonce (getLastMessage ()) && signer.signMsg (msgSign)) {
606
+ message = msgSign; // Write the signed message back
607
+ return true ;
608
+ }
606
609
break ;
607
610
}
608
611
}
0 commit comments