Requesting a sensor value from a different node?
-
@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.
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 LCDand 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.....
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.
-
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 LCDand 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.....
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.
@sansespere said:
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 LCDand 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.....
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 :)
-
@sansespere said:
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 LCDand 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.....
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("%"); } -
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("%"); } -
Anyone?
-
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 -
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..