Node to Node Communication



  • Hello, I am building a LCD information panel to interface with my several Arduino sensors and am looking for some help in setting up the Node to Node communication. I have searched these forums extensively and either the information I find is not relevant to 1.4 or is beyond my comprehension.

    Also I believe it would be a good idea to have an example on the build page for Node to Node communication.



  • Second that! I'm looking also for an example.


  • Admin

    Use the setDestination(desitnationNodeId) on message before sending it off:

    https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MyMessage.h#L159

    In the receiving node you can pick it up just like the RelayActuator example does.



  • @hek said:

    In the receiving node you can pick it up just like the RelayActuator example does.

    then would it automatically be cleared ? or we need to change the destination again to the gateway for normal operation ??


  • Admin

    @sharath-krishna said:

    then would it automatically be cleared ? or we need to change the destination again to the gateway for normal operation ??

    :question:



  • @hek I tried your suggestion above and got the following error message; "no matching function call" I used the following code in my sketch: Mymessage setDestination(11);

    Does anyone have a working example of node - node communication that we could all reference?

    So been playing arround a bit more and got this, does it look right?

    gw.send(msgHTTemp.setDestination(11).setSensor(i).set(temperature,1));
    

    and if this looks correct will it send to both node 11 and the gateway?



  • So it looks like the code below did work:
    gw.send(msgHTTemp.setDestination(11).setSensor(i).set(temperature,1));

    How ever in the serial monitor I am getting a bunch of ST=fail trying to send to node 11:
    T2: 71.90
    send: 1-1-0-11 s=0,c=1,t=0,pt=7,l=5,st=ok:71.4
    send: 1-1-0-11 s=0,c=1,t=0,pt=7,l=5,st=fail:71.4

    Here is the code I have in my Node 11 sketch to receive the messages:
    gw.begin(NULL, AUTO, true);
    gw.process();

    I also don't fully understand how I capture the data coming into node 11 and present it to the LCD screen so any help with that as well would be great.



  • @cleight said:

    So it looks like the code below did work:
    gw.send(msgHTTemp.setDestination(11).setSensor(i).set(temperature,1));

    How ever in the serial monitor I am getting a bunch of ST=fail trying to send to node 11:
    T2: 71.90
    send: 1-1-0-11 s=0,c=1,t=0,pt=7,l=5,st=ok:71.4
    send: 1-1-0-11 s=0,c=1,t=0,pt=7,l=5,st=fail:71.4

    Here is the code I have in my Node 11 sketch to receive the messages:
    gw.begin(NULL, AUTO, true);
    gw.process();

    I also don't fully understand how I capture the data coming into node 11 and present it to the LCD screen so any help with that as well would be great.

    Figured out the issue was in the repeater code on node 11. So now I am getting variable from Node1 being presented to Node11 but I am not sure how to capture this information and display it on the LCD Screen attached.

    read: 1-0-11 s=0,c=1,t=0,pt=7,l=5:84.2



  • @cleight I believe you would need to change your gw.begin
    http://www.mysensors.org/download/sensor_api_14

    To initialize radio and start the library, you must call begin(). Begin initializes the sensor node but you >can also configure the sensor node operating parameters manually. Call this before anything else in >the library

    void begin(void (*_msgCallback)(const MyMessage &), uint8_t nodeId, boolean repeaterMode,
    uint8_t parentNodeId, rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e dataRate);
    incomingMessageCallback - Callback function for incoming messages from other nodes or >controller and request responses. Default is NULL.
    nodeId - The unique id (1-254) for this sensor. Default is AUTO(255) which means sensor tries to >fetch an id from controller.
    repeaterMode - Activate repeater mode. This node will forward messages to other nodes in the >radio network. Make sure to call process() regularly. Default in false
    parentNodeId - Use this to force node to always communicate with a certain parent node. Default is >AUTO which means node automatically tries to find a parent.
    paLevel - Radio PA Level for this sensor. Default RF24_PA_MAX
    channel - Radio channel. Default is channel 76
    dataRate - Radio transmission speed. Default RF24_250KBPS

    So instead of gw.begin(NULL,Auto,true) try gw.begin(ProcessMessage,Auto,true)

    And then just define ProcessMessage as a function.

    I'd look at the relay sketch which sets up incomingmessage as the function to handle incoming messages.



  • @Chaotic I'm not following at all with what you said. I don't believe I need to change my gw.begin as I am receiving messages from the other node, I am now struggling with capturing that data to a variable that I can use to output the data to an attached LCD Screen.



  • I tried the following code but doesn't appear to be working

    void getVariables(const MyMessage &message)
    {
    if (message.sensor == 1)
      {
          if (message.type == V_TEMP)
          {
            testTemp = atoi(message.data);
          DEBUG_PRINTLN(F("Test Temp recieved:"));
          DEBUG_PRINTLN(testTemp);
          }
      }
    }
    


  • @cleight said:

    I tried the following code but doesn't appear to be working

    void getVariables(const MyMessage &message)
    {
    if (message.sensor == 1)
      {
          if (message.type == V_TEMP)
          {
            testTemp = atoi(message.data);
          DEBUG_PRINTLN(F("Test Temp recieved:"));
          DEBUG_PRINTLN(testTemp);
          }
      }
    }
    

    Can anyone assist with this issue? I cannot figure out what I am missing to capture this data into an integer so I can parse it to my LCD Screen.

    Message.sensor -- 1 is what I am defining right now as I was the data from Node ID1, Sensor ID0, I believe this is where my issue is but I cannot figure out the syntax needed to define Node 1 Child Sensor 0 and Variable type V_TEMP.


  • Hero Member

    Can you please show us the full code.? From what I read @cleight has a good suggestion. Try the relay sketch_ to learn how to use the incoming message in your code. . You need to define it in gwbegin else it is only noticed as incoming in the serial monitgor



  • @Chaotic I understand what your saying as well as what @AWI is saying but I don't think everyone understands what I am trying to do. I would like to capture several node's child sensors data and use it on my LCD Screen to show me instant status of sensors. If I use code like the relay example how do I tell it which node and child sensor I want to capture the data from?

    void incomingMessage(const MyMessage &message) {
          if (message.type == V_TEMP)
          {
            testTemp = atoi(message.data);
          DEBUG_PRINTLN(F("Test Temp recieved:"));
          DEBUG_PRINTLN(testTemp);
          }
      }
    

    ^That code, per the relay sketch example doesn't allow me to specify I want data from Node 1, Child Sensor 0.

    Here is my full sketch I am currently working on:

    #define STATES 9
    #define HUMIDITY_SENSOR_DIGITAL_PIN 4
    #define DEBUG
    
    #ifdef DEBUG
    #define DEBUG_SERIAL(x) Serial.begin(x)
    #define DEBUG_PRINT(x) Serial.print(x)
    #define DEBUG_PRINTLN(x) Serial.println(x)
    #else
    #define DEBUG_SERIAL(x)
    #define DEBUG_PRINT(x) 
    #define DEBUG_PRINTLN(x) 
    #endif
    
    #include <avr/pgmspace.h>
    #include <Wire.h>
    #include <Time.h>
    #include <SPI.h>
    #include <MySensor.h>
    #include <LiquidCrystal_I2C.h>
    #include <DS3232RTC.h> 
    //
    #define RADIO_ID 11
    #define CHILD_ID_SCENE 3
    #define CHILD_ID_LED 4
    #define BACKLIGHT 6 //available PWM capable pin
    
    //
    LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // set the LCD address to 0x27 for a 16 chars and 2 line display
    //
    void (*lcdDisplay[STATES])();
    //
    byte state = 0;
    byte lastState;
    byte timeCounter = 0;
    int ledStatus = 1;// to toggle LCD backlight led
    int ledLevel = 254;
    unsigned long lastTime;
    unsigned long refreshInterval = 3000UL;
    unsigned long lastClockSet;
    boolean isMessage = false;
    float insideTemperature;
    float humidity;
    int OutdoorTemp = -99;
    int OutdoorHumidity = -99;
    int todayHigh = -99; 
    int todayLow = -99;
    int HotTubTemp = -99;
    int KWH = -99;
    int testTemp = -99;
    String conditions = "Not yet Reported";
    String tomorrowWeather = "Not yet Reported";
    String messageOfTheDay = "**Hello There!**";
    String AlarmStatus = "No Data";
    unsigned long motdTimer;
    boolean buttonPushed = false;
    //
    MySensor gw;
    //
    MyMessage msgOn(CHILD_ID_SCENE, V_SCENE_ON);
    MyMessage msgOff(CHILD_ID_SCENE, V_SCENE_OFF);
    MyMessage msgVAR1(CHILD_ID_SCENE, V_VAR1);// outdoor temperature
    MyMessage msgVAR2(CHILD_ID_SCENE, V_VAR2);// outdoor humidity
    MyMessage msgVAR3(CHILD_ID_SCENE, V_VAR3);//today's low
    MyMessage msgVAR4(CHILD_ID_SCENE, V_VAR4);// today's high
    MyMessage msgVAR5(CHILD_ID_SCENE, V_VAR5);//conditions
    //
    MyMessage lightMsg(CHILD_ID_LED, V_DIMMER);
    MyMessage msgMOTD(CHILD_ID_LED, V_VAR1); // Hot Tub KWH
    MyMessage msgAlarm(CHILD_ID_LED, V_VAR2); // Tomorrow Forecast
    MyMessage msgBrite(CHILD_ID_LED, V_VAR3); 
    MyMessage msgHTTemp(CHILD_ID_LED, V_VAR4); // Hot Tub Temp
    MyMessage msgALARMSTATUS (CHILD_ID_LED, V_VAR5);// Alarm System Status
    void setup()  
    { 
      DEBUG_SERIAL(115200);
      DEBUG_PRINTLN(F("Serial started"));
      //
      lcdDisplay[0] = lcdDisplay0;
      lcdDisplay[1] = lcdDisplay1;
      lcdDisplay[2] = lcdDisplay2;
      lcdDisplay[3] = lcdDisplay3;
      lcdDisplay[4] = lcdDisplay4;
      lcdDisplay[5] = lcdDisplay5;
      lcdDisplay[6] = lcdDisplay6;
      lcdDisplay[7] = lcdDisplay7;
      lcdDisplay[8] = lcdDisplay8;
      //
      pinMode(BACKLIGHT, OUTPUT);
      gw.begin(getVariables, RADIO_ID);
      //gw.begin(NULL, AUTO, true);
      gw.sendSketchInfo("Home Status Panel", "2.1");
      setSyncProvider (RTC.get);
      gw.present(CHILD_ID_SCENE, S_SCENE_CONTROLLER);
      gw.present( CHILD_ID_LED, S_DIMMER);
      //
      analogWrite(BACKLIGHT, 200); //LCD Backlight
      //
      lcd.begin(20,4);
      lcd.clear();
      lcd.backlight();
      lcd.setCursor(0, 0);
      lcd.print("Syncing Time");
      lcd.setCursor(0, 1);
      int clockCounter = 0;
      while(timeStatus() == timeNotSet && clockCounter < 60)
      {
        gw.process();
        gw.requestTime(receiveTime);
        Serial.println("getting Time");
        delay(1000);
        lcd.print(".");
        clockCounter++;
        if (clockCounter > 16)
        {
          lcd.clear();
          lcd.print(F("**Failed Clock**"));
          lcd.setCursor(0,1);
          lcd.print(F("*Syncronization*"));
          delay(2000);
          break;
        }
      }
      lcd.clear();
      lastTime = millis();
    }
    void loop()      
    {
      gw.process();
      if (millis() - lastClockSet >= 60000UL)
      {
        gw.requestTime(receiveTime);
        lastClockSet = millis();
      }
      if (millis() - lastTime >= refreshInterval)
      {
        state++;
        if (state > STATES - 1) state = 0;
        DEBUG_PRINTLN(F("State:")); 
        DEBUG_PRINTLN(state);
        lastTime += refreshInterval;
        getTempHumidity();
      }
      if (state != lastState) 
      {
        fastClear();
        lcdDisplay[state]();
      }
      lastState = state;
      if (isMessage)
      {
        if (millis() - motdTimer > 86400 * 1000UL)
        {
          isMessage = false;
        }
      }
    }
    void fastClear() //Clear LCD Screen
    {
      lcd.setCursor(0,0);
      lcd.clear();
      lcd.setCursor(0,1);
      lcd.clear();
      lcd.setCursor(0,2);
      lcd.clear();
      lcd.setCursor(0,3);
      lcd.clear();
    }
    //
    void lcdDisplay0()
    {
      lcd.setCursor(0,0);
      lcd.print(F("Time: "));
      if (hourFormat12() < 10) lcd.print("0");
      lcd.print(hourFormat12());
      lcd.print(":");
      if (minute() < 10) lcd.print("0");
      lcd.print(minute());
      if (isAM()) lcd.print(F("am"));
      else lcd.print(F("pm"));
      DEBUG_PRINT(F("Time:"));
      DEBUG_PRINTLN(hourFormat12());
      lcd.setCursor(0,1);
      lcd.print(F("Date: "));
      if (month() < 10) lcd.print("0");
      lcd.print(month());
      lcd.print("/");
      if (day() < 10) lcd.print("0");
      lcd.print(day());
      lcd.print("/");
      lcd.print(year());
      DEBUG_PRINTLN(F("Date: ")); 
      DEBUG_PRINT(month()); 
      DEBUG_PRINT("/"); 
      DEBUG_PRINT(day()); 
      DEBUG_PRINT("/"); 
      DEBUG_PRINTLN(year());
    }
    void lcdDisplay1()
    {
      lcd.setCursor(0,0);
      lcd.print(F(" Indoor Temp:"));
      lcd.print(int(round(insideTemperature)));
      lcd.print(char(223));
      DEBUG_PRINT(F("Indoor Temp:")); 
      DEBUG_PRINT(int(round(insideTemperature))); 
      DEBUG_PRINTLN(F("F"));
     }
    void lcdDisplay2()
    {
      lcd.setCursor(0,0);
      lcd.print("Outdoor Temp:"); 
      lcd.print(OutdoorTemp); 
      lcd.print(char(223));
      DEBUG_PRINT(F("Outdoor Temp:"));
      DEBUG_PRINTLN(OutdoorTemp);
      lcd.setCursor(0,1);
      lcd.print(F("    Humidity:")); 
      lcd.print(OutdoorHumidity); 
      lcd.print(F("%"));
      DEBUG_PRINT(F("    Humidity:"));
      DEBUG_PRINTLN(OutdoorHumidity);
    }
    void lcdDisplay3()
    {
      lcd.setCursor(0,0);
      lcd.print(F("Today's High:"));
      lcd.print(todayHigh); 
      lcd.print(char(223));
      DEBUG_PRINT(F("Today's High: "));
      DEBUG_PRINTLN(todayHigh);
      lcd.setCursor(0,1);
      lcd.print(F("         Low:"));
      lcd.print(todayLow); 
      lcd.print(char(223));
      DEBUG_PRINT(F("Today's Low: "));
      DEBUG_PRINTLN(todayLow);
    }
    void lcdDisplay4()
    {
      lcd.setCursor(0,0);
      lcd.print(F("Today's Weather"));
      DEBUG_PRINTLN(F("Today's Weather: "));
      lcd.setCursor(0,1);
      lcd.print(conditions);
      DEBUG_PRINTLN(conditions);
    }
    void lcdDisplay5()
    {
      lcd.setCursor(0,0);
      lcd.print(F("Forcast Tomorrow"));
      DEBUG_PRINTLN(F("Tomorrow's Forecast: "));
      lcd.setCursor(0,1);
      lcd.print(tomorrowWeather);
      DEBUG_PRINTLN(tomorrowWeather);
    }
    void lcdDisplay6()
    {
      if (isMessage)
      {
        lcd.setCursor(0,0);
        lcd.print(F("**NEW  MESSAGE**"));
        DEBUG_PRINTLN(F("****Message****"));
        lcd.setCursor(0,1);
        lcd.print(messageOfTheDay);
        DEBUG_PRINTLN(messageOfTheDay);
        motdTimer = millis();
      }
      else
      {
        lcd.setCursor(0,0);
        lcd.print(F("****Welcome!****"));
        DEBUG_PRINTLN(F("****Message****"));
        lcd.setCursor(0,1);
        lcd.print(F("Have a Nice Day!"));
        DEBUG_PRINTLN(F("Have a Nice Day"));
      }
    }
    void lcdDisplay7()
    {
      lcd.setCursor(0,1);
      lcd.print("Alarm Status:");  
      DEBUG_PRINT("Alarm Status:");
      DEBUG_PRINTLN(AlarmStatus);
      lcd.setCursor(0,2);
      lcd.print(AlarmStatus);
    }
    void lcdDisplay8()
    {
      lcd.setCursor(0,0);
      lcd.print("Hot Tub KWH:");
      lcd.print(KWH);
      DEBUG_PRINT("Hot Tub KWH:");
      DEBUG_PRINTLN(KWH);
      lcd.setCursor(0,1);
      lcd.print(F(" Hot Tub:"));
      lcd.print(HotTubTemp);
      lcd.print(char(223));
      DEBUG_PRINT(F("Hot Tub:"));
      DEBUG_PRINT(HotTubTemp);
      DEBUG_PRINT(F("F"));
      lcd.setCursor(3,0);
      lcd.print("Test Temp:");
      lcd.print(testTemp);
      lcd.print(char(223));
      DEBUG_PRINT(F("Test Temp:"));
      DEBUG_PRINTLN(testTemp);
    }
    //
    void getTempHumidity()
    {
      insideTemperature = ((RTC.temperature()/4*9/5 + 32));
      if (isnan(insideTemperature)) 
      {
        DEBUG_PRINTLN(F("Failed reading temperature from RTC"));
      } 
    }
    //
    void receiveTime(unsigned long controllerTime)
    {
      // Ok, set imcoming time
      DEBUG_PRINTLN(F("Time value received: "));
      DEBUG_PRINTLN(controllerTime);
      RTC.set(controllerTime);
      controllerTime = true;
    }
    //
    void incomingMessage(const MyMessage &message) {
          if (message.type == V_TEMP)
          {
            testTemp = atoi(message.data);
          DEBUG_PRINTLN(F("Test Temp recieved:"));
          DEBUG_PRINTLN(testTemp);
          }
      }
    
    void getVariables(const MyMessage &message)
    {
      if (message.sensor == CHILD_ID_SCENE)
      { 
        if (message.type == V_VAR1) //Outdoor temp pulled from Weather Underground Vera Plugin
        {
          OutdoorTemp = atoi(message.data);
          DEBUG_PRINTLN(F("OutdoorTemp recieved:"));
          DEBUG_PRINTLN(OutdoorTemp);
        }
        if (message.type == V_VAR2) //Outdoor Humidity pulled from Weather Underground Vera Plugin
        {
          OutdoorHumidity = atoi(message.data);
          DEBUG_PRINT(F("OutdoorHumidity recieved:"));
          DEBUG_PRINTLN(OutdoorHumidity);
        }
        if (message.type == V_VAR3) //pulled from Weather Underground Vera Plugin
        {
          todayLow = atoi(message.data);
          DEBUG_PRINT(F("Received Today's LOW:"));
          DEBUG_PRINTLN(todayLow);
        }
    
        if (message.type == V_VAR4) //pulled from Weather Underground Vera Plugin
        {
          todayHigh = atoi(message.data);
          DEBUG_PRINT(F("Received Today's HIGH:"));
          DEBUG_PRINTLN(todayHigh);
        }
        if (message.type == V_VAR5) //pulled from Weather Underground Vera Plugin
        {
          String newMessage = String(message.data);
          int locator = newMessage.indexOf("@");
          newMessage = newMessage.substring(0, locator);
          conditions = newMessage;
          DEBUG_PRINT(F("Received today's Conditions:"));
          DEBUG_PRINTLN(conditions);
        }
      }
        if (message.sensor == CHILD_ID_LED)
      {
        if (message.type == V_DIMMER) //Set LCD Brightness from Dimmer Device in Vera
        {
          ledLevel = message.getByte();
          		lcd.setBacklight(ledLevel);
    		Serial.print("Brightness Level recieved:");
    		Serial.println(ledLevel);
                    analogWrite(BACKLIGHT, (int)(ledLevel / 100. * 255) );                
        }
        if (message.type == V_VAR1) //Hot Tub KWN Hours
        {
          KWH = atoi(message.data);
          DEBUG_PRINT("Hot Tub KWH recieved:");
          DEBUG_PRINTLN(KWH);
        }
        if (message.type == V_VAR2) //pulled from Weather Underground Vera Plugin
        {
          // Extended Forecast
          String newMessage = String(message.data);
          int locator = newMessage.indexOf("@");
          newMessage = newMessage.substring(0, locator);
          tomorrowWeather = newMessage;
          DEBUG_PRINT(F("Received Two Day Forecast:"));
          DEBUG_PRINTLN(tomorrowWeather);
        }
        if (message.type == V_VAR3) //Not sure what this will be used for just yet
        {
          // message of the day
          String newMessage = String(message.data);
          int locator = newMessage.indexOf("@");
          newMessage = newMessage.substring(0, locator);
          messageOfTheDay = newMessage;
          DEBUG_PRINT(F("Received Message of the Day:"));
          DEBUG_PRINTLN(messageOfTheDay);
          isMessage = true;
        }
        if (message.type == V_VAR4) //Hot Tub Temp from Vera which comes from an Arduino
        {
          HotTubTemp = atoi(message.data);
          DEBUG_PRINT(F("Received HotTubTemp:"));
          DEBUG_PRINTLN(HotTubTemp);
        }
        if (message.type == V_VAR5) //Check on Alarm status
        {
        String newMessage = String(message.data);
          int locator = newMessage.indexOf("@");
          newMessage = newMessage.substring(0, locator);
          AlarmStatus = newMessage;
          DEBUG_PRINT(F("Received Alarm Status:"));
          DEBUG_PRINTLN(AlarmStatus); 
        } 
      }
    }
    

  • Admin

    @cleight, the incoming message contains where it came from. So you could do something like:

    #define TEMP_NODE_ID 42
    #define HUMIDITY_NODE_ID 44
    float temp = 0, hum =0;
    void incomingMessage(const MyMessage &message) {
       switch (message.sender) {
             case TEMP_NODE_ID:
                  temp = message.getFloat();
                  break; 
             case HUMIDITY_NODE_ID:
                  hum = message.getFloat();
                  break; 
       }
       updateDisplay();  
    }


  • @cleight You sensor nodes should handle sending the data.

    The message coming to your LCD Node should have the node id that it started from which you can check against to do what you want for each message. The code @hek provided should allow you to tell what node the message is coming from.

    I'm going to suggest since you seem to be doing non-standard things that you go and read the API which explains the different parts of the message.
    http://www.mysensors.org/download/serial_api_14



  • @hek Thank you for the example, one thing I am still confused on though is if all my nodes have child ID's of 0 and 1 that the code you presented above doesn't care about the Child sensor only the Node ID correct?

    @Chaotic: I have read the API documentation about 100 times and I don't correlate it to what I want, I unfortunately do not have a programming background and what I have learned so far is by other users examples or trial and error.



  • @cleight Your nodes should each have a unique ID. And then the child ID might be 0/1 for each one.

    Since you claimed you don't have a programming background I'll try to explain the API (as I understand it anyways) And how to get to each piece

    The message that gets passed by the radio is going to look like this

    12;6;1;0;0;36.5\n
    

    Looking at each part

    12: node-id The unique id of the node that sends or should receive the message (address) message.sender

    6: child-sensor-id Each node can have several sensors attached. This is the child-sensor-id that uniquely identifies one attached sensor message.sensor

    1: message-type Type of message sent - See table below message.command_ack_payload (I think)

    0: ack The ack parameter has the following meaning:
    Outgoing: 0 = unacknowledged message, 1 = request ack from destination node
    Incoming: 0 = normal message, 1 = this is an ack message message.isAck()

    0: sub-type Depending on messageType this field has different meaning. See tables below message.type

    36.5: payload The payload holds the message coming in from sensors or instruction going out to actuators.
    Various functions exist to get the payload

    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;

    So you might have a childID of 0/1 if you are only sending 1-2 items from the sensor but each sensor will have its own nodeID

    So using the example Hek provided and assuming temp is sensor 0 humidity is 1

    #define BEDROOM_NODE_ID 42
    #define KITCHEN_NODE_ID 44
    #define TEMP 0
    #define HUM 1
    float bdtemp = 0, bdhum =0, kntemp = 0, knhum =0;
    void incomingMessage(const MyMessage &message) {
       switch (message.sender) {
             case BEDROOM_NODE_ID:
                  switch (message.sensor){
                       case TEMP
                              bdtemp = message.getFloat();
                       break; 
                       case HUM
                              bdhum = message.getFloat();
                       break;
               } 
               break; 
         case KITCHEN_NODE_ID:
                  switch (message.sensor){
                       case TEMP
                              kntemp = message.getFloat();
                       break; 
                       case HUM
                              knhum = message.getFloat();
                       break; 
              } 
              break; 
       }
      updateDisplay();  
     }
    

    That will give you 4 variables bdtemp, bdhum, kntemp, knhum so you know the temp/humidity coming from 2 different sensors



  • @Chaotic I understand what you are saying and have the concept down of the message being sent to the gateway. What I don't understand is the code that Hek provided and how I seperate Node ID 1 Child Sensor 0 (temp Sensor) from Node ID 1 Child Sensor 1 (Humidity Sensor)

    Also I tried the code Hek provided but I cannot use Float to store the variable as I am out of room in my sketch, I tried changing to message.getInt(); without luck.



  • @cleight said:

    @Chaotic I understand what you are saying and have the concept down of the message being sent to the gateway. What I don't understand is the code that Hek provided and how I seperate Node ID 1 Child Sensor 0 (temp Sensor) from Node ID 1 Child Sensor 1 (Humidity Sensor)

    Also I tried the code Hek provided but I cannot use Float to store the variable as I am out of room in my sketch, I tried changing to message.getInt(); without luck.

    I was putting in an example to do just that when you responded.

    as for getInt / getFloat it should let you switch but you might lose anything after the period.


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.