how to read other device status with arduino?



  • Hey,
    I'm using veraEdge with arduino gateway and I have a few temperature sensors on my network.
    Ive search the forums and examples but could find a way to do what I want.

    Let say I have arduino1 has a DHT sensor and is a S_TEMP device #11 on my network
    and arduino2 has LCD and is set to be S_HVAC device #12 on my network

    I would like to show on arduino2 LCD the temperature read by arduino1.
    Can u please help?


  • Contest Winner

    @leeoz there are two ways to achieve this

    1. The easy way:
      Each time the temperature is changed in arduino1 and the controller is updated with a
      message like this:
    gw.send(msgTemp.set(((float)temperature / 10.0), 1)); 
    

    Also send a message to arduino2 something like this:
    arduino1 code:

    // This can be the sensor ID on arduino2 device #12 (but if you do not check each integer between 1-254 will do)
    #define MYSENSOR_TEMP_LCD  1
    MyMessage msgTempNode2 (MYSENSOR_TEMP_LCD,  V_TEMP);  
    
    void loop ()
    {
        gw.process();
        ... do stuff
       if (oldtemperature  != temperature)
       {     // inform the gateway we have a new temp.
            gw.send(msgTemp.set(((float)temperature / 10.0), 1)); 
        
            gw.wait(100); // give the gateway some time to process the 1ste message
    
           // inform our LCD slave node also about the temp. change
           msgTempNode2.setDestination(12); // This is the node ID on arduino2 
           gw.send(msgTempNode2.set(((float)temperature / 10.0), 1),; 
           oldtemperature  = temperature;
      }
    
        ... do some more stuff
    }
    

    The LCD arduino should handle the incoming TEMP message, arduino2 code:

    void incomingMessage(const MyMessage &message) {
       if (message.isAck()) {
            Serial.println(F("GW ack"));
       }
       switch (message.type) {
          case V_TEMP:
              Serial.print("New temperature received : ");
              Serial.println(message.getFloat());
              ... do some stuff to update your LCD screen
              break; 
      }
    }
    

    2)The second more complex way is to request the temperature from arduino2 to arduino1
    arduino1 code:

    // This can be the sensor ID on arduino2 device #12 (but if you do not check each integer between 1-254 will do)
    #define MYSENSOR_TEMP_LCD  1
    MyMessage msgTempNode2 (MYSENSOR_TEMP_LCD,  V_TEMP);  
    
    void loop ()
    {
        gw.process();
        ... do stuff
       if (oldtemperature  != temperature)
       {     // inform the gateway we have a new temp.
            gw.send(msgTemp.set(((float)temperature / 10.0), 1)); 
            // Store the temp.
            oldtemperature  = temperature;
      }
       ... do more stuff
    }
    
    void incomingMessage(const MyMessage &message) {
        if (mGetCommand(message) == C_REQ) {
             MyMessage answerMsg;
             Serial.print("Incoming request for sensor: ");
             Serial.println(message.sensor);
             mSetCommand(answerMsg, C_SET);
             answerMsg.setSensor(message.sensor);
             answerMsg.setDestination(message.sender);
             switch (message.sensor) {
               case MYSENSOR_TEMP:
                   answerMsg.setType(V_TEMP);
                   gw.send(answerMsg.set((float)(oldtemperature/ 10.0), 1));
                   break;
            }
        } else {
            if (message.isAck()) {
                Serial.println(F("GW ack"));
            }
            switch (message.type) {
                ... handle other messages
            }
       }
    }
    

    arduino2 code:

    void loop ()
    {
      gw.process();
        ... do stuff
       if (time_to_poll_for_temp())
       {     // Request for temperature
             gw.request(MYSENSOR_TEMP, V_TEMP, 12);   // This is the node ID on arduino2 
      }
    }
    
    void incomingMessage(const MyMessage &message) {
       if (message.isAck()) {
            Serial.println(F("GW ack"));
       }
       switch (message.type) {
          case V_TEMP:
              Serial.print("New temperature received : ");
              Serial.println(message.getFloat());
              ... do some stuff to update your LCD screen
              break; 
      }
    }
    ``


  • @BartE
    Tnx for the respose, great.
    Also, if i would like to request value from vera?
    So i use the gw.request(VeraDeviceID, V_TEMP,??)

    Also for solution 2, on the request from arduino2 code,
    gw.request(MYSENSOR_TEMP, V_TEMP, 12);
    MYSENSOR_TEMP is what?
    And why did u type 12? The sensor id is 11...

    I think that in general i dont understad the use of gw.request()


  • Contest Winner

    @leeoz said:

    @BartE
    Tnx for the respose, great.
    Also, if i would like to request value from vera?
    So i use the gw.request(VeraDeviceID, V_TEMP,??)

    Requesting Vera is not possible, there is no request interface between the GW and Vera

    Also for solution 2, on the request from arduino2 code,
    gw.request(MYSENSOR_TEMP, V_TEMP, 12);
    MYSENSOR_TEMP is what?
    Just a sensor ID on your arduino1
    And why did u type 12? The sensor id is 11...

    True, this should have been 11

    I think that in general i dont understad the use of gw.request()

    gw,request() sends a message to a different node requesting for data, the requested node has to process this message and respond with a second message. Look at this link at the "Requesting data" paragraph



  • @BartE
    Ok, I think I got it all. Great tnx a lot


Log in to reply
 

Suggested Topics

68
Online

11.4k
Users

11.1k
Topics

112.7k
Posts