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 ??

    ❓



  • @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.
    https://codebender.cc/sketch:47528



  • @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.


  • Admin

    Make sure to send the same type as you're trying to getXXX on the receiving side. No automatic conversion is done except for the getString().

    https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MyMessage.cpp#L62



  • @hek This is the code I am using on the sensor side to send to LCD Node (Node 11)

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

    And in serial monitor on node 11 I see the data being captured correctly, so I believe my issue still lies in my code on the LCD Screen side.

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

    Here is my latest Sketch after I made changes again per Hek's suggestion, only thing is I couldn't use float as I am out of room in my sketch to hard to use INT instead for testTemp

    #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
    //Define Additional Nodes that I would like to pull data from
    #define HOTTUB_NODE_ID 1
    //
    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 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); 
        } 
      }
       switch (message.sender) {
            case HOTTUB_NODE_ID:
                 testTemp = atoi(message.data);
                 break;
          }
    }
    

    Node ID 1 - Temperature Sensor that is sending to Node 11 (LCD Screen)

    #include <SPI.h>
    #include <MySensor.h>  
    #include <DHT.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #define CHILD_ID_HUM 1
    #define CHILD_ID_TEMP 2
    #define CHILD_ID_HTTEMP 3
    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
    //Waterproof Sensor addition
    #define ONE_WIRE_BUS 4 //Pin where waterproof temp sensor is connected
    #define MAX_ATTACHED_DS18B20 16
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    
    MySensor gw;
    DHT dht;
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors=0;
    boolean receivedConfig = false;
    float lastTemp;
    float lastHum;
    boolean metric = false; 
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgHTTemp(CHILD_ID_HTTEMP, V_TEMP);
    
    void setup()  
    { 
      // Startup OneWire
      sensors.begin();
    
      gw.begin();
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Hot Tub Monitor", "2.0");
    
      // Fetch the number of attached temperature sensors
      numSensors = sensors.getDeviceCount();
    
      // Present all sensors to controller
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
        gw.present(i, S_TEMP);
      }
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
    
      metric = gw.getConfig().isMetric;
    }
    
    void loop()      
    {  
      // Process incoming messages (like config from server)
      gw.process();
    
      //Fetch temperatures from Dallas sensors
      sensors.requestTemperatures();
    
      // Red temperatures and send them to the controller
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
    
        // Fetch and round temperature to one decimal
        float temperature = static_cast<float>(static_cast<int>((sensors.getTempFByIndex(i)) * 10.)) / 10.;
    
        //Only send data if temperature has changed and no error
        if (lastTemperature[i] != temperature && temperature != -127.00) {
    
          // Send in the new temperature
          delay(100);
          gw.send(msgHTTemp.setSensor(i).set(temperature,1));
          gw.send(msgHTTemp.setDestination(11).setSensor(i).set(temperature,1));
          Serial.print("T2: ");
          Serial.println(temperature);
          lastTemperature[i]=temperature;
        }
      }
    
      delay(dht.getMinimumSamplingPeriod());
    
      //float temperature = dht.getTemperature();
      float temperature = dht.getTemperature()*9/5 + 32;
      if (isnan(temperature)) {
        Serial.println("Failed reading temperature from DHT");
      } 
      else if (temperature != lastTemp) {
        lastTemp = temperature;
        if (!metric) {
          //temperature = dht.toFahrenheit(temperature);
          temperature = dht.getTemperature()*9/5 + 32;
        }
        delay(100);
        gw.send(msgTemp.set(temperature, 1));
        Serial.print("T: ");
        Serial.println(temperature);
      }
    
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
        Serial.println("Failed reading humidity from DHT");
      } 
      else if (humidity != lastHum) {
        lastHum = humidity;
        delay(100);
        gw.send(msgHum.set(humidity, 1));
        Serial.print("H: ");
        Serial.println(humidity);
      }
    
      gw.sleep(SLEEP_TIME); //sleep a bit
    }
    

  • Admin

    Forget.. looked at the wrong sketch.



  • @hek said:

    @cleight said:

    gw.begin();

    You forgot to initialize begin like you were told above.

    I have this in my gateway.begin

    gw.begin(getVariables, RADIO_ID);
    

    I seem to need to have it this way or Vera doesn't get Node ID 11 anymore and it gets a random generated ID. So then I put the Case statement at the bottom of my getVariables Function.


  • Admin

    If you send it as a float value you must use getFloat (it is transmitted as binary data). Doing atoi will get you garbled data because it is not transmitted as ascii.

    If your memory is low, I suggest you either convert and send is as a string (char *) and do message.getString()

    or

    send it as a int and just do message.getInt() on the receiving side.

    BTW the "String" class you're using is VERY memory hungry and is probably the reason for low memory an after a while probably result in crashes (it fragments memory).



  • @hek How do I send it as an integer?


  • Admin

    declare the variable you're sending as int or convert it by casting

    gw.send (msgHum.set(static_cast<int>(humidity)));

    http://www.learncpp.com/cpp-tutorial/44-type-conversion-and-casting/



  • @hek said:

    declare the variable you're sending as int or convert it by casting

    gw.send (msgHum.set(static_cast<int>(humidity)));

    http://www.learncpp.com/cpp-tutorial/44-type-conversion-and-casting/

    @hek Converting my sensor to send the data as an Integer worked and it is now parsing correctly, however I also have a humidity child sensor on that node I would like to send to node 11 as well, how would I capture that in the case statement?


  • Admin

    @cleight
    just switch on message.sensor (should be one of CHILD_ID_HUM, CHILD_ID_TEMP)



  • @cleight I posted code to do just that

    #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();  
    }


  • @Chaotic I missed your code earlier, thank you for this, although while compiling is it saying I am missing a colon before knhum for some reason, need to dig deeper.



  • @cleight that is what I get for coding on the fly

    change

    case TEMP
    

    and

    case HUM
    

    with

    case TEMP:
    

    and

    case HUM:


  • @Chaotic Thank you, I knew it had to be something simple.



  • Ok last issue to be worked out and I think I am good to go, thanks again to @Chaotic and @hek for there assistance with my project.

    Last issue is with the sensor node, it sends the data to the LCD Node (node 11) but only sends the data to the gateway on boot, it will not send it to the gateway after it starts sending to Node 11. I would like it to send to both the Node and the Gateway all the time, that way Vera see the information as well as my LCD.

    Here is the output of the Serial Monitor, also for some reason on each temp update it sends to node 11 twice for some reason:
    sensor started, id 1
    send: 1-1-0-0 s=255,c=0,t=17,pt=0,l=5,st=ok:1.4.1
    send: 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
    read: 0-0-1 s=255,c=3,t=6,pt=0,l=1:I
    send: 1-1-0-0 s=255,c=3,t=11,pt=0,l=15,st=ok:Hot Tub Monitor
    send: 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:2.0
    send: 1-1-0-0 s=0,c=0,t=6,pt=0,l=5,st=ok:1.4.1
    send: 1-1-0-0 s=1,c=0,t=7,pt=0,l=5,st=ok:1.4.1
    send: 1-1-0-0 s=2,c=0,t=6,pt=0,l=5,st=ok:1.4.1
    send: 1-1-0-0 s=0,c=1,t=0,pt=7,l=5,st=ok:67.2
    send: 1-1-0-11 s=0,c=1,t=0,pt=2,l=2,st=ok:67
    T2: 67.20
    send: 1-1-0-0 s=2,c=1,t=0,pt=7,l=5,st=ok:66.2
    T: 66.20
    send: 1-1-0-0 s=1,c=1,t=1,pt=7,l=5,st=ok:36.0
    send: 1-1-0-11 s=1,c=1,t=1,pt=2,l=2,st=ok:36
    H: 36.00
    send: 1-1-0-11 s=0,c=1,t=0,pt=7,l=5,st=ok:75.7
    send: 1-1-0-11 s=0,c=1,t=0,pt=2,l=2,st=ok:75
    T2: 75.70
    send: 1-1-0-11 s=0,c=1,t=0,pt=7,l=5,st=ok:80.1
    send: 1-1-0-11 s=0,c=1,t=0,pt=2,l=2,st=ok:80
    T2: 80.10
    send: 1-1-0-11 s=0,c=1,t=0,pt=7,l=5,st=ok:81.6
    send: 1-1-0-11 s=0,c=1,t=0,pt=2,l=2,st=ok:81
    T2: 81.60
    send: 1-1-0-11 s=0,c=1,t=0,pt=7,l=5,st=ok:81.7
    send: 1-1-0-11 s=0,c=1,t=0,pt=2,l=2,st=ok:81
    T2: 81.70
    send: 1-1-0-11 s=0,c=1,t=0,pt=7,l=5,st=ok:79.8
    send: 1-1-0-11 s=0,c=1,t=0,pt=2,l=2,st=ok:79
    T2: 79.80
    send: 1-1-0-11 s=0,c=1,t=0,pt=7,l=5,st=ok:78.1
    send: 1-1-0-11 s=0,c=1,t=0,pt=2,l=2,st=ok:78
    T2: 78.10
    send: 1-1-0-11 s=0,c=1,t=0,pt=7,l=5,st=ok:76.7
    send: 1-1-0-11 s=0,c=1,t=0,pt=2,l=2,st=ok:76
    T2: 76.70
    send: 1-1-0-11 s=0,c=1,t=0,pt=7,l=5,st=ok:75.5
    send: 1-1-0-11 s=0,c=1,t=0,pt=2,l=2,st=ok:75
    T2: 75.50

    Here is the sketch:

    #include <SPI.h>
    #include <MySensor.h>  
    #include <DHT.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #define CHILD_ID_HUM 1
    #define CHILD_ID_TEMP 2
    #define CHILD_ID_HTTEMP 3
    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
    //Waterproof Sensor addition
    #define ONE_WIRE_BUS 4 //Pin where waterproof temp sensor is connected
    #define MAX_ATTACHED_DS18B20 16
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    
    MySensor gw;
    DHT dht;
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors=0;
    boolean receivedConfig = false;
    float lastTemp;
    float lastHum;
    boolean metric = false; 
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgHTTemp(CHILD_ID_HTTEMP, V_TEMP);
    
    void setup()  
    { 
      // Startup OneWire
      sensors.begin();
    
      gw.begin();
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Hot Tub Monitor", "2.0");
    
      // Fetch the number of attached temperature sensors
      numSensors = sensors.getDeviceCount();
    
      // Present all sensors to controller
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
        gw.present(i, S_TEMP);
      }
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
    
      metric = gw.getConfig().isMetric;
    }
    
    void loop()      
    {  
      // Process incoming messages (like config from server)
      gw.process();
    
      //Fetch temperatures from Dallas sensors
      sensors.requestTemperatures();
    
      // Red temperatures and send them to the controller
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
    
        // Fetch and round temperature to one decimal
        float temperature = static_cast<float>(static_cast<int>((sensors.getTempFByIndex(i)) * 10.)) / 10.;
    
        //Only send data if temperature has changed and no error
        if (lastTemperature[i] != temperature && temperature != -127.00) {
    
          // Send in the new temperature
          delay(100);
          gw.send(msgHTTemp.setSensor(i).set(temperature,1));
          gw.send(msgHTTemp.setDestination(11).set(static_cast<int>(temperature)));
          Serial.print("T2: ");
          Serial.println(temperature);
          lastTemperature[i]=temperature;
        }
      }
    
      delay(dht.getMinimumSamplingPeriod());
    
      //float temperature = dht.getTemperature();
      float temperature = dht.getTemperature()*9/5 + 32;
      if (isnan(temperature)) {
        Serial.println("Failed reading temperature from DHT");
      } 
      else if (temperature != lastTemp) {
        lastTemp = temperature;
        if (!metric) {
          //temperature = dht.toFahrenheit(temperature);
          temperature = dht.getTemperature()*9/5 + 32;
        }
        delay(100);
        gw.send(msgTemp.set(temperature, 1));
        Serial.print("T: ");
        Serial.println(temperature);
      }
    
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
        Serial.println("Failed reading humidity from DHT");
      } 
      else if (humidity != lastHum) {
        lastHum = humidity;
        delay(100);
        gw.send(msgHum.set(humidity, 1));
        gw.send(msgHum.setDestination(11).set(static_cast<int>(humidity)));
        Serial.print("H: ");
        Serial.println(humidity);
      }
    
      gw.sleep(SLEEP_TIME); //sleep a bit
    }
    


  • @cleight I think the easiest solution (all theory btw) would be to duplicate the message for each sensor

    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgHumLCD(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgTempLCD(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgHTTemp(CHILD_ID_HTTEMP, V_TEMP);
    MyMessage msgHTTempLCD(CHILD_ID_HTTEMP, V_TEMP);
    

    then in the setup()

    msgHumLCD.setDestination(11);
    msgTempLCD.setDestination(11);
    msgHTTPempLCD.setDestination(11);
    

    Then in the loop when you are doing the gw.send just do a second one for the LCD message (you shouldn't need the setDestination)



  • @Chaotic Sorry for not getting back sooner on this, but I did confirm that your solution does indeed work and works very well. I can't wait to finish this project up and be able to post the Pictures/Sketch to share with the community.


Log in to reply
 

Suggested Topics

13
Online

11.4k
Users

11.1k
Topics

112.7k
Posts