Requesting a sensor value from a different node?



  • Hi,

    I'm trying to put together a "status" type LCD screen on a separate node which can display values from other sensor nodes in the network but am running into some problems reading the data from the other nodes.

    the setup is like this:
    Node A - temp, humidity, pressure
    Node B - Distance
    Node C- LCD screeen

    I'm using a Vera as my controller, and all devices are in there and reporting correctly. I've used the "TimeAndVariable" example as the base of the LCD node, and can get it to read custom variables without any problems. But looking at the API reference I should be able to get the last value from any sensor using:

    void requestStatus(uint8_t radioId, int8_t childId, uint8_t variableType);

    But I cant for get this to work! Just trying to play with the code here is a section with the problem:

    gw.getStatus(1,11,0); //altID of temp sensor 1;11, 0 is for V_TEMP
    Status(gw.getMessage()); //function is below
    lcd.print(value);

    void Status(message_s message) {
    value = atoi(message.data);
    }

    I'm obviously doing something wrong - any advice would be appreciated!


  • Admin

    I would recommend pushing data from your sensors to the LCD node instead of trying to poll it with requestStatus.

    The requestStatus function was mainly implemented for fetching data from controller and I'm not sure how well it has been tested for the tasks you are planning on 1.3.

    Your sensors must do a lot of "manual" work to pick up the request-message and reply to the LCD-node. This means they must be awake all the time. And are basically pushing data in the end anyway.



  • Awesome - pushing from the sensor at the same time it sends to the gateway has got it working. Will have to create what will almost be a stripped down version of a gateway to process all incoming messages and assign the contents to the correct variables for the screen : )

    Thanks for the advice!



  • @sansespere said:

    Awesome - pushing from the sensor at the same time it sends to the gateway has got it working. Will have to create what will almost be a stripped down version of a gateway to process all incoming messages and assign the contents to the correct variables for the screen : )

    Thanks for the advice!

    Hey Great idea been trying something similar myself sometime but getting nowhere any chance of you sharing some of your code, that might help me get started. What size LCD are you thinking of of using, or are you just going to use a small LCD menu driven with a couple buttons.



  • @andyuno

    Hey, no problem - the LCD I'm using is this one in a 16x2 format.

    Haven't had much of a chance to work on it yet since first getting it working with Hek's advice above but this is what I have so far. Standard disclaimer though, I'm new to this whole coding and electronics stuff so there may be a better way of doing it.

    To start with, in the sketch of the sensor that has the information you want to display, find where it's sending the data to the gateway, and get it to send to the node that has the LCD at the same time. EG:

    gw.sendVariable(CHILD_ID_TEMP, V_TEMP, temperatureB, 1); //standard line sending data to the gateway
    gw.sendVariable(MONITOR_STATION,CHILD_ID_TEMP, V_TEMP, temperatureB, 1); //new line that needs to be created, where MONITOR_STATION is defined as the radioID of the node with the LCD
    

    and below is the testing sketch I wrote to receive and display the messages:

     #include <SPI.h>
     #include <EEPROM.h>  
     #include <RF24.h>
     #include <Sensor.h>  
     #include <Time.h>  
     #include <Wire.h>  
     #include <LiquidCrystal_I2C.h>
    
     Sensor gw;
     #define CHILD_ID 10
     
     LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
     float temp = 0; //for storing temperature values
     float hum = 0; //for storing humidity values
     
     void setup()  
     {  
       gw.begin();
       // Send the sketch version information to the gateway and Controller
       gw.sendSketchInfo("LCD", "1.0");
     
       // Register any sensortype. This example we just create a motion sensor.
       gw.sendSensorPresentation(CHILD_ID, S_MOTION);
     
       lcd.begin(16,2);   //Specify LCD size
       lcd.backlight();   
     }
    
     void loop()     
     {     
       int LoopCount = 0; // LoopCount is there to make sure that we dont get stuck in a never ending loop of processing messages - not sure if this could ever even happen, but just to be safe
     
       while(gw.messageAvailable()==true && LoopCount < 10){ //while there are messages in the queue and we havent processed more than 10 since entering the loop
           message_s  message = gw.getMessage(); //get the message
           if (message.header.type == 0){  //check the type of message it is - temperature, humidity, etc. as per Variable Types defined in http://www.mysensors.org/build/sensor_api
           temp = atof(message.data); //if it's a temp type, get the data and convert it to float
           }
           if (message.header.type == 1){
           hum =  atof(message.data); //if it's a humidity type, get the data and convert it to float
           }  
           LoopCount++;  //increment the loop counter
       }
      
       if (LoopCount >= 1){ //Check if we need to update the LCD
        UpdateLCD(); 
       }
       
       //serial prints for troubleshooting
       Serial.print("Temp: ");
       Serial.println(temp);
       Serial.print("Hum: ");
       Serial.println(hum);
       Serial.println("Waiting");
    
       delay(10000);   //take a short break  
     }
    
     void UpdateLCD() { //LCD output
       lcd.clear();
       lcd.print("Temp:");
       lcd.print(temp,1);
       lcd.print("C"); 
       lcd.setCursor(0,1);
       lcd.print("Humi:");
       lcd.print(hum,1);
       lcd.print("%"); 
    
     }
    

    and you end up with something like this.....
    upload-782a7eaa-f12e-4e50-aeb8-d2c106de80aa
    showing data for a sensor I have sitting outside.

    Still a lot of work to do to get it right - there are other things I want to display, using scrolling messages to cycling messages, etc, but this is just a basic proof of concept.


  • Contest Winner

    @sansespere said:

    @andyuno

    Hey, no problem - the LCD I'm using is this one in a 16x2 format.

    Haven't had much of a chance to work on it yet since first getting it working with Hek's advice above but this is what I have so far. Standard disclaimer though, I'm new to this whole coding and electronics stuff so there may be a better way of doing it.

    To start with, in the sketch of the sensor that has the information you want to display, find where it's sending the data to the gateway, and get it to send to the node that has the LCD at the same time. EG:

    gw.sendVariable(CHILD_ID_TEMP, V_TEMP, temperatureB, 1); //standard line sending data to the gateway
    gw.sendVariable(MONITOR_STATION,CHILD_ID_TEMP, V_TEMP, temperatureB, 1); //new line that needs to be created, where MONITOR_STATION is defined as the radioID of the node with the LCD
    

    and below is the testing sketch I wrote to receive and display the messages:

     #include <SPI.h>
     #include <EEPROM.h>  
     #include <RF24.h>
     #include <Sensor.h>  
     #include <Time.h>  
     #include <Wire.h>  
     #include <LiquidCrystal_I2C.h>
    
     Sensor gw;
     #define CHILD_ID 10
     
     LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
     float temp = 0; //for storing temperature values
     float hum = 0; //for storing humidity values
     
     void setup()  
     {  
       gw.begin();
       // Send the sketch version information to the gateway and Controller
       gw.sendSketchInfo("LCD", "1.0");
     
       // Register any sensortype. This example we just create a motion sensor.
       gw.sendSensorPresentation(CHILD_ID, S_MOTION);
     
       lcd.begin(16,2);   //Specify LCD size
       lcd.backlight();   
     }
    
     void loop()     
     {     
       int LoopCount = 0; // LoopCount is there to make sure that we dont get stuck in a never ending loop of processing messages - not sure if this could ever even happen, but just to be safe
     
       while(gw.messageAvailable()==true && LoopCount < 10){ //while there are messages in the queue and we havent processed more than 10 since entering the loop
           message_s  message = gw.getMessage(); //get the message
           if (message.header.type == 0){  //check the type of message it is - temperature, humidity, etc. as per Variable Types defined in http://www.mysensors.org/build/sensor_api
           temp = atof(message.data); //if it's a temp type, get the data and convert it to float
           }
           if (message.header.type == 1){
           hum =  atof(message.data); //if it's a humidity type, get the data and convert it to float
           }  
           LoopCount++;  //increment the loop counter
       }
      
       if (LoopCount >= 1){ //Check if we need to update the LCD
        UpdateLCD(); 
       }
       
       //serial prints for troubleshooting
       Serial.print("Temp: ");
       Serial.println(temp);
       Serial.print("Hum: ");
       Serial.println(hum);
       Serial.println("Waiting");
    
       delay(10000);   //take a short break  
     }
    
     void UpdateLCD() { //LCD output
       lcd.clear();
       lcd.print("Temp:");
       lcd.print(temp,1);
       lcd.print("C"); 
       lcd.setCursor(0,1);
       lcd.print("Humi:");
       lcd.print(hum,1);
       lcd.print("%"); 
    
     }
    

    and you end up with something like this.....
    upload-782a7eaa-f12e-4e50-aeb8-d2c106de80aa
    showing data for a sensor I have sitting outside.

    Still a lot of work to do to get it right - there are other things I want to display, using scrolling messages to cycling messages, etc, but this is just a basic proof of concept.

    nice work.

    for your next revision we can show you how to do this without holding in the while loop or using delays.

    terrific!!!!! 🙂 I like LCD's 🙂



  • Ahhh ok - so something more like this:

    #include <SPI.h>
    #include <EEPROM.h>  
    #include <RF24.h>
    #include <Sensor.h>  
    #include <Time.h>  
    #include <Wire.h>  
    #include <LiquidCrystal_I2C.h>
    
    Sensor gw;
    #define CHILD_ID 1
    
    LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
    float temp = 0; //for storing temperature values
    float hum = 0; //for storing humidity values
    
    void setup()  
    {  
      gw.begin();
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("LCD", "1.0");
    
      // Register any sensortype. This example we just create a motion sensor.
     gw.sendSensorPresentation(CHILD_ID, S_MOTION);
    
      lcd.begin(16,2);   //Specify LCD size
      lcd.backlight();   
    }
    
    void loop()     
    {     
        message_s  message = gw.waitForMessage(); //wait for a message to process
    
        //check the type of message it is - temperature, humidity, etc. as per Variable Types defined in http://www.mysensors.org/build/sensor_api
        if (message.header.type == 0){  
          temp = atof(message.data); //if it's a temp type, get the data and convert it to float
        }
        else if (message.header.type == 1){
          hum =  atof(message.data); //if it's a humidity type, get the data and convert it to float
        }  
        else {
          Serial.print("Unknow Message Type");
        } 
    
      //serial prints for troubleshooting
      Serial.print("Temp: ");
      Serial.println(temp);
      Serial.print("Hum: ");
      Serial.println(hum);
      UpdateLCD(); 
      Serial.println("Waiting");
    }
    
    void UpdateLCD() { //LCD output
      lcd.clear();
      lcd.print("Temp:");
      lcd.print(temp,1);
      lcd.print("C"); 
      lcd.setCursor(0,1);
      lcd.print("Humi:");
      lcd.print(hum,1);
      lcd.print("%"); 
    
    }


  • @sansespere.. Nice work, I don't think I would've got most of that, now that should give me something to work from thanks.



  • If someone have this converted to 1.4 version of library please post it.



  • If someone have this converted to 1.4 version of library please post it.

    Have node №2 child 1 - temp sensor.
    For example: how to ask the node 2 child 1 value from node №10?



  • This post is deleted!


  • Anyone?

    @sansespere



  • I've just found this thread, which describes the Convertion from 1.3 to 1.4:

    http://forum.mysensors.org/topic/172/convert-sketch-from-1-3-to-1-4

    I think, the following would do the trick, i will try it, when i am home this evenening:

    // process incoming messages (like config from server) <-- insert line
    gw.process(); <-- insert line
    gw.sendVariable(MONITOR_STATION, CHILD_ID, V_TEMP, temperature, 1); change to --> gw.send(msg.setSensor(CHILD).set(temperature,1).setDestination(MONITOR_STATION)); // send float with one decimal point


  • Hero Member

    I would imagine the "royal" way of getting sensor values is requesting them from the controller. In this case the sensor to be read does not need to bother about sending the values to all of the nodes and waking up is not an issue.



  • did anyone convert this succesfully? I'm having some problems, this would make a great example build 🙂 I looked at other ones like "node to node " but something simple like this would be great to start building from..


Log in to reply
 

Suggested Topics

  • 2
  • 12
  • 11
  • 11
  • 1
  • 3
  • 3

204
Online

10.3k
Users

10.7k
Topics

109.8k
Posts