How to determine from which Node a message is comming from
-
First of all, not sure whether this is the right topic for my question, so if not I apologize.
I've been experimenting with node to node communication inspired by @GertSanders his presentation during the Dutch MySensors meetup. I haven't discovered this feature of MySensors before, but it's brilliant.
I can communicate from one sensor to another without the interference of any controller. Love it! It opens new possibilities, and probably keep me awake for a couple of nights ;-)
So I'd like to know, if there's a way to determine the sender of a message in the incomming message handler. I do see a setDestination() method but - at least in 1.5 - there's no getter and it seems like MySensors ignores that. For my use case it would be great if I can determine what the id is of the node of which the message is originating from.
I also tried to create a message with the default constructor like this:
MyMessage myMsg(); myMsg.setDestination( aNodeId );but that results into the following compile error:
error: request for member 'setDestination' in 'myMsg', which is of non-class type 'MyMessage()' myMsg.setDestination( aNodeId ); ^I can get around that easily, so I think I misunderstood the API documentation for that.
void sendMessage( uint8_t aNodeId, char *aMsg ) { MyMessage myMsg( 255, V_VAR1 ); myMsg.setDestination( aNodeId ); myMsg.set( aMsg ); gw.send( myMsg, true ); } -
First of all, not sure whether this is the right topic for my question, so if not I apologize.
I've been experimenting with node to node communication inspired by @GertSanders his presentation during the Dutch MySensors meetup. I haven't discovered this feature of MySensors before, but it's brilliant.
I can communicate from one sensor to another without the interference of any controller. Love it! It opens new possibilities, and probably keep me awake for a couple of nights ;-)
So I'd like to know, if there's a way to determine the sender of a message in the incomming message handler. I do see a setDestination() method but - at least in 1.5 - there's no getter and it seems like MySensors ignores that. For my use case it would be great if I can determine what the id is of the node of which the message is originating from.
I also tried to create a message with the default constructor like this:
MyMessage myMsg(); myMsg.setDestination( aNodeId );but that results into the following compile error:
error: request for member 'setDestination' in 'myMsg', which is of non-class type 'MyMessage()' myMsg.setDestination( aNodeId ); ^I can get around that easily, so I think I misunderstood the API documentation for that.
void sendMessage( uint8_t aNodeId, char *aMsg ) { MyMessage myMsg( 255, V_VAR1 ); myMsg.setDestination( aNodeId ); myMsg.set( aMsg ); gw.send( myMsg, true ); }@TheoL this code:
void receive(const MyMessage &message) { LOG(F("Received %s from %s\n"), msgTypeAsCharRepresentation((mysensor_data)message.type), nodeTypeAsCharRepresentation(message.sender)); delay(250); sendPingOrPongResponse( message ); }from the PingPong example suggests that the sender is available.
Is that a solution to your problem or did I not quite understand your question?
-
@TheoL this code:
void receive(const MyMessage &message) { LOG(F("Received %s from %s\n"), msgTypeAsCharRepresentation((mysensor_data)message.type), nodeTypeAsCharRepresentation(message.sender)); delay(250); sendPingOrPongResponse( message ); }from the PingPong example suggests that the sender is available.
Is that a solution to your problem or did I not quite understand your question?
@mfalkvidd Thanx for the quick reply and the example. It's exactly what I was I was looking for. I just overlooked the union definition in Message.h.
I'm currently sending the message to the Node itself as a test. But event that that works.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login