Getting V_FORECAST on a node from controller?
-
HI all!
I have been trying to get the V_FORECAST to another node (not the originating node). I have set up the payload forward in MyController, but I am having a problem getting it to work on the receiving node.
I have tried various variations on....
void receive(const MyMessage &message) { if (message.sensor == CHILD_ID_GETFORECAST && message.type == V_FORECAST){ FORECAST = (message.getInt()); }
including getByte and getString. But still I can't seem to get it to work.
So what is the correct way to get relayed V_FORECAST on a node?
-
@skywatch can you paste the screenshot of forward payload configuration?
-
@jkandasa Sure I can!
I think I have the wrong variable type to get V_FORECAST - Although I only need a byte or int with the index pointer of the current forecast (0-5).
When testing it with byte received I could send a raw message and it worked, so I guess it is not a byte or int that is sent to the controller and then on to the node?
-
@skywatch MyController sends payload as is.
Can you double check that, you have configured right sensor?
You may debug by adding a serial print line right aftervoid receive(const MyMessage &message) {
beforeif
loop? -
@skywatch MyController sends payload as is.
I do not know what that is - is it an int? byte?string?
Can you double check that, you have configured right sensor?
Yes I have, I can send the receiving node a byte and the screen displays the correct value. I did this to test with action>send raw message and it was good.
You may debug by adding a serial print line right after
void receive(const MyMessage &message) {
beforeif
loop?That's a thought for tomorrow.....thanks!
-
I do not know what that is - is it an int? byte?string?
MyController receives all the payload in String format and sends all the payload in String format.
From the gateway, MyController receives payload as String, https://www.mysensors.org/download/serial_api_20
However, We have multiple functions in MySensors, based on your payload you can call a particular function,
https://www.mysensors.org/download/sensor_api_20#message-constructor// Getters for picking up payload on incoming messages char* getStream(char *buffer) const; char* getString(char *buffer) const; const char* getString() const; void* getCustom() const; uint8_t getByte() const; bool getBool() const; float getFloat() const; long getLong() const; unsigned long getULong() const; int getInt() const; unsigned int getUInt() const;
Can you check it in the resources page, do you receive data from the source node? You can enable
Notice
and check activities in resources log page. -
Thanks I got it to work!
The below is what I used as I cannot display the full message on a small oled and so I use abbreviations held in an array. Therefore I needed to get a value to act as a pointer to the message to display and the below did the trick! - Node finished!
void receive(const MyMessage &message) { if (message.sensor == CHILD_ID_GETFORECAST && message.type == V_FORECAST) { forecast = (message.getString()); if (forecast == "stable"){ Index = 0;} else if (forecast == "sunny"){ Index = 1;} else if (forecast == "cloudy"){ Index = 2;} else if (forecast == "unstable"){ Index = 3;} else if (forecast == "thunderstorm"){ Index = 4;} else if (forecast == "unknown"){ Index = 5;} }
-
@skywatch Just a quick update - ......
Keep the receive section clean - I took all the 'if' and 'elseif' out of receive and into the main loop - This is good practice. So now it looks like this......
// process incoming message void receive(const MyMessage &message) { if (message.sensor == CHILD_ID_GETFORECAST && message.type == V_FORECAST) { forecast = (message.getString()); NewForecast = 1; } }
The NewForecast is there to alert the main loop to a new incomming value to be tested and updated.