MySensor Request Function



  • All,
    I used to had a sketch to grab the V_TEXT values from Domoticz controller and show on LCD.
    All was good except, recently I wanted to change some of the text on LCD.
    I only changed the text and when I tried to compile the sketch I get some error.

    It does not like this line anymore:

    void request(uint8_t childSensorId, uint8_t variableType, uint8_t destination);
    

    And I receive this set of errors in compiler (Arduino IDE):

    LCD_Sketch:113: error: new declaration 'void request(uint8_t, uint8_t, uint8_t)'
    
     void request(uint8_t childSensorId, uint8_t variableType, uint8_t destination);
    
                                                                                  ^
    
    In file included from C:\Users\Saeid\Documents\Arduino\libraries\MySensors/MySensors.h:412:0,
    
                     from D:\WemosD1MiniPro-NodeMCU-LCD_Sketch\WemosD1MiniPro-NodeMCU-LCD_Sketch.ino:35:
    
    C:\Users\Saeid\Documents\Arduino\libraries\MySensors/core/MySensorsCore.cpp:392:6: error: ambiguates old declaration 'bool request(uint8_t, uint8_t, uint8_t)'
    
     bool request(const uint8_t childSensorId, const uint8_t variableType, const uint8_t destination)
    
          ^
    
    exit status 1
    new declaration 'void request(uint8_t, uint8_t, uint8_t)'
    

    I commented the "void request" line and sketch compile just fine but I feel something is not right.

    • Would you please explain why my code does not compile the code?

    • Is alright to not having the Request line at all?

    • What is your suggestion to get this code improved/fixed as I see the device get restarted after a while on and off!!!

    Here is the full code for my sketch:

     // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    //Fixed NodeID in Domoticz
    #define MY_NODE_ID 2
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable repeater functionality for this node
    #define MY_REPEATER_FEATURE
    
    
    #include <Wire.h> 
    #include <LiquidCrystal_I2C.h>
    #include <SPI.h>
    #include <MySensors.h>
    
    
    // Set the LCD address to 0x27 for a 16 chars and 2 line display
    LiquidCrystal_I2C lcd(0x3F, 20, 4);
    
    //const byte nodeId = 66 ;                   // MySensors fixed node id
    const byte LCD1_CHILD = 8 ;                  // LCD line 1
    const byte LCD2_CHILD = 9 ;                  // LCD line 2
    const byte LCD3_CHILD = 10 ;                 // LCD line 3
    const byte LCD4_CHILD = 11 ;                 // LCD line 4
    
    char lastLCD1[21] = "Line1 - first   ";     // define & init before first receive
    char lastLCD2[21] = "Line2 - second  ";
    char lastLCD3[21] = "Line3 - third   ";     
    char lastLCD4[21] = "Line4 - forth   ";
    
    // Initialize messages for sensor network
    MyMessage textMsg( 0, V_TEXT );
    
    void setup(){
      //WiFi.persistent(false);
      //ESP.flashEraseSector(0x3fe);
      
      Wire.begin(D3, D4);
      lcd.begin();
      lcd.backlight(); // finish with backlight on  
      
    //-------- Write characters on the display ----------------
    // NOTE: Cursor Position: CHAR, LINE) start at 0  
      lcd.setCursor(0,0); //Start at character 4 on line 0
      lcd.print("Welcome to :");
      delay(1000);
      lcd.setCursor(4,1);
      lcd.print("LCD Panel");
      delay(2000); 
      lcd.setCursor(0,3);
      lcd.print("Weather Station");
      delay(2000); 
      lcd.clear();
      
      // Initialize the serial port at a speed of 9600 baud
      Serial.begin(115200);
    }
    
    void presentation()  
    {   
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("LCD", "2.0");
      
      present(LCD1_CHILD, S_INFO, "LCD_line1");        // new S_type 20150905 (not know by domoticz)
      present(LCD2_CHILD, S_INFO, "LCD_line2");
      present(LCD3_CHILD, S_INFO, "LCD_line3");
      present(LCD4_CHILD, S_INFO, "LCD_line4");
      
      send(textMsg.setSensor(LCD1_CHILD).set("-"));    // initialize the V_TEXT at controller for sensor to none (trick for Domoticz)
      send(textMsg.setSensor(LCD2_CHILD).set("-"));   
      send(textMsg.setSensor(LCD3_CHILD).set("-")); 
      send(textMsg.setSensor(LCD4_CHILD).set("-")); 
    
      //requestTime(); 
    
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Inside  (T):");
    
        lcd.setCursor(0, 1);
        lcd.print("Outside (T):");
    
        lcd.setCursor(0, 2);
        lcd.print("Bedroom (T):");
    
        lcd.setCursor(0, 3);
        lcd.print("Bedroom (H):");
    }
    
    void requestTime();
    
    void request(uint8_t childSensorId, uint8_t variableType, uint8_t destination);
    
    
    void loop(){
      
      Serial.println(".");
      //requestTime();
      request(8,V_TEXT,0);
      wait(50);
      request(9,V_TEXT,0);
      wait(50); 
      request(10,V_TEXT,0);
      wait(50); 
      request(11,V_TEXT,0);
      wait(50); 
      sleep(60000);
      
      // If characters arrived over the serial port...
      if (Serial.available()) {
        // Wait a bit for the entire message to arrive
        delay(100);
        // Clear the screen
        lcd.clear();
        
    
        // Write all characters received with the serial port to the LCD.
        while (Serial.available() > 0) {
          lcd.write(Serial.read());
        }
      }
      
    }
    
    // This is called only if new time value was received by calling requestTime();
    void receiveTime(unsigned long controllerTime) {
        Serial.print("Time value received: ");
        Serial.println(controllerTime);
    
        //Hours = controllerTime / (1000*60*60)
        //Minutes = (controllerTime % (1000*60*60)) / (1000*60)
        //Seconds = ((controllerTime % (1000*60*60)) % (1000*60)) / 1000
        
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Current Time");
        lcd.setCursor(0,1);
        lcd.print(controllerTime);  //seconds format ex. 45681238785
     }
    
    // This is called when a message is received 
    void receive(const MyMessage &message) {
    
       // Write some debug info
       Serial.print("Message: "); 
       Serial.print(message.sensor); 
       Serial.print(", Message: "); 
       Serial.println(message.getString());
    
        lcd.setCursor(0, 0);
        lcd.print("Inside  (T):");
    
        lcd.setCursor(0, 1);
        lcd.print("Outside (T):");
    
        lcd.setCursor(0, 2);
        lcd.print("Bedroom (T):");
    
        lcd.setCursor(0, 3);
        lcd.print("Bedroom (H):");
         
      if (message.type==V_TEXT) {
        if (message.sensor == LCD1_CHILD ) {
          //snprintf(lastLCD1, sizeof(lastLCD1), "%20s", message.getString());  // load text into LCD string
          //lcd.setCursor(17, 1);
          //lcd.print(lastLCD1);
          lcd.setCursor(13, 0);
          lcd.print(message.getString());
          lcd.print((char)223);
          lcd.print("C"); 
        } 
       if (message.sensor == LCD2_CHILD ) {
           lcd.setCursor(0, 1);
          //lcd.print(lastLCD2);
            lcd.setCursor(13, 1);
            lcd.print(message.getString());
            lcd.print((char)223);
            lcd.print("C"); 
       }
       if (message.sensor == LCD3_CHILD ) {
           lcd.setCursor(0, 2);
          //lcd.print(lastLCD3);
            lcd.setCursor(13, 2);
            lcd.print(message.getString());
            lcd.print((char)223);
            lcd.print("C"); 
       }
      if (message.sensor == LCD4_CHILD ) {
           lcd.setCursor(0, 3);
          //lcd.print(lastLCD4);
            lcd.setCursor(13, 3);
            lcd.print(message.getString());
            lcd.print("%"); 
       }
       } 
    }
    

    P.S: I am using MySensor Library 2.3.0 hwever, by reverting it back to 2.2.0, problem still persist.
    I am also using NodeMCU v1.0 for my microprocessor connected to LCD and NRF24 Radio.


  • Mod

    @sghazagh remove void

    By adding void, you've changed the statement from calling the function to declaring it.



  • @mfalkvidd So what should I do then?

    It was with void before and compiler didn't get any error.
    Isn't it the way to declare it? like other functions?
    ex. void setup(), void presentation(),.... ?????????


  • Mod

    @sghazagh I don't think the c programming language has changed how functions are declared in the last 50 years, so I doubt having void there was working before. MySensors can't influence how the programming language works.

    What are you trying to do with the request function?



  • You can remove these lines, the declaration is already done in the MySensors framework. For presentation() it is needed because you write code there, that is in the function. Now you only call the function, and the code is already in the framework.



  • @electrik Thanks electrik.
    It is absolutely right, I removed the line for declaring the function and all is working as expected.
    Actually the other problem which made me nut was that I was seeing the device restarts continuously so I thought not declaring the request function is causing that.
    That has fixed as well. The issue was that I had enabled the REPEATER option, however, I didn't add any WIFI library or correct setting for that so the system was crashing and was resetting .
    Now that I disabled that REPEATER option and also did not declaring the request function, all is working fine again.

    @mfalkvidd: I am not sure but believe me it was there and it was compiling just fine before.
    Perhaps used to we had to declare it, and now as "electrik" explained, it already declares in MySensor call.

    Thank you both anyway.
    I think I get it working now.

    Cheers,



  • All,
    I leave the code here as it's a working code for getting the Domoticz Virtual Sensor V_TEXT and showing on LCD.
    Just don't forget to:
    disable REPEATER option:

    // #define MY_REPEATER_FEATURE
    

    and remove this line:

    void request(uint8_t childSensorId, uint8_t variableType, uint8_t destination);
    

    Thanks.



  • You should do the same for requestTime();


Log in to reply
 

Suggested Topics

  • 4
  • 9
  • 20
  • 2
  • 17
  • 4

46
Online

11.4k
Users

11.1k
Topics

112.6k
Posts