Push V_VAR from Vera controller to sensor?
-
Hi,
I've just started with MySensors, and am trying to get my first sketch working.
I have an LCD display that I want to update from my Vera by setting V_VAR1 to V_VAR4.This is my sketch:
#define SN "LCD Display" #define SV "1.0" #define NODE_ID 10 #include <MySensor.h> #include <SPI.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> MySensor gw; static int backlight = 0; MyMessage backlightMsg(0, V_LIGHT); MyMessage var1text(0, V_VAR1); MyMessage var2text(0, V_VAR2); MyMessage var3text(0, V_VAR3); MyMessage var4text(0, V_VAR4); LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //LiquidCrystal_I2C lcd(0x27); //set the LCD address to 0x27 for a 16 chars and 2 line display void setup() { Serial.begin(9600); // Used to type in characters lcd.begin(20,4); // ------- Quick 3 blinks of backlight ------------- for(int i = 0; i< 3; i++) { lcd.backlight(); delay(250); lcd.noBacklight(); delay(250); } lcd.backlight(); // finish with backlight on lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print(" MySensors LCD "); delay(1000); lcd.setCursor(0,2); lcd.print("Waiting for gateway"); Serial.println( SN ); gw.begin( incomingMessage, NODE_ID ); gw.present( 0, S_LIGHT ); gw.sendSketchInfo(SN, SV); // Pull the gateway's light status gw.request( 0, V_STATUS ); gw.request( 0, V_VAR1 ); gw.request( 0, V_VAR2 ); gw.request( 0, V_VAR3 ); gw.request( 0, V_VAR4 ); }/*--(end setup )---*/ void loop() { gw.process(); } void incomingMessage(const MyMessage &message) { if (message.type == V_STATUS) { // Retrieve on/off from the incoming request message int backlight = atoi( message.data ); if (backlight){ lcd.backlight(); } else { lcd.noBacklight(); } } if (message.type == V_VAR1) { String lcdtext = String(message.data); updateLCDRow(0, lcdtext); } if (message.type == V_VAR2) { String lcdtext = String(message.data); updateLCDRow(1, lcdtext); } if (message.type == V_VAR3) { String lcdtext = String(message.data); updateLCDRow(2, lcdtext); } if (message.type == V_VAR4) { String lcdtext = String(message.data); updateLCDRow(3, lcdtext); } } void updateLCDRow(int row, String text) { lcd.setCursor(0,row); lcd.print(" "); lcd.setCursor(0,row); lcd.print(text); }The problem is that changing the variables in Vera doesn't update the LCD (only once during setup). Do I have to do a gw.request() in the loop in order to get the data? That seems a bit inefficient...
Is it possible to push the data?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login