(SOLVED) Programming problem: error: 'incomingMessage' was not declared in this scope



  • I am trying to mix and match two sketches..
    One is the RealTimeClockDisplaySensor example and one is a sketch I found on HomeSeer forum.

    Both compiles without any problems.

    But when I use this sketch:

    * The MySensors Arduino library handles the wireless radio link and protocol
    * between your home built sensors/actuators and HA controller of choice.
    * The sensors forms a self healing radio network with optional repeaters. Each
    * repeater and gateway builds a routing tables in EEPROM which keeps track of the
    * network topology allowing messages to be routed to nodes.
    *
    * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
    * Copyright (C) 2013-2015 Sensnology AB
    * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
    *
    * Documentation: http://www.mysensors.org
    * Support Forum: http://forum.mysensors.org
    *
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License
    * version 2 as published by the Free Software Foundation.
    *
    *******************************
    *
    * REVISION HISTORY
    * Version 1.0 - Henrik Ekblad
    * 
    * DESCRIPTION
    * Example sketch showing how to request time from controller which is stored in RTC module
    * The time and temperature (DS3231/DS3232) is shown on an attached Crystal LCD display
    * 
    *
    * Wiring (radio wiring on www.mysensors.org)
    * ------------------------------------
    * Arduino   RTC-Module     I2C Display 
    * ------------------------------------
    * GND       GND            GND
    * +5V       VCC            VCC
    * A4        SDA            SDA
    * A5        SCL            SCL
    *
    * http://www.mysensors.org/build/display
    *
    */
    
    
    #include <SPI.h>
    #include <MySensor.h>  
    #include <Time.h>  
    #include <DS3232RTC.h>  // A  DS3231/DS3232 library
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    
    //Standard
           #define RELAY_1                            4  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
           #define NUMBER_OF_RELAYS                2 // Total number of attached relays
           #define RELAY_ON                        0  // GPIO value to write to turn on attached relay
           #define RELAY_OFF                        1 // GPIO value to write to turn off attached relay
    // Other Stuff
    //        Bounce debouncer = Bounce();
           int numSensors=                            0;
    
    
    MySensor gw;
    boolean timeReceived = false;
    unsigned long lastUpdate=0, lastRequest=0;
    
    // Initialize display. Google the correct settings for your display. 
    // The follwoing setting should work for the recommended display in the MySensors "shop".
    LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
    
    void setup()  
    {  
               gw.begin(incomingMessage, AUTO, false);
    
     
     // Send the sketch version information to the gateway and Controller
     gw.sendSketchInfo("Oles relay", "1.0");
     
    
     // Request latest time from controller at startup
    //  gw.requestTime(receiveTime);  
     //Present relays to gateway
     for (int sensor=1; sensor <=NUMBER_OF_RELAYS;sensor++) {
         gw.present(sensor, S_LIGHT);
     }
     
     // initialize the lcd for 16 chars 2 lines and turn on backlight
     lcd.begin(16,2); 
    }
    
    // This is called when a new time value was received
    //void receiveTime(unsigned long controllerTime) {
    // // Ok, set incoming time 
    //  Serial.print("Time value received: ");
    //  Serial.println(controllerTime);
    //  RTC.set(controllerTime); // this sets the RTC to the time from controller - which we do want periodically
    //  timeReceived = true;
    }
    
    void loop()     
    {     
             // Alway process incoming messages whenever possible
             gw.process();
    }
           void incomingMessage(const MyMessage &message) {
           if (message.isAck()) {
                Serial.println("This is an ack from gateway");
            } else if (message.type==V_LIGHT) {
                 state = message.getBool();
                // Change relay state
               lcd.home();
               lcd.print(message.sensor);
               lcd.print(" , ");
               lcd.print(state);
               //Send the msg
               gw.send(msg.setSensor(message.sensor).set(state), true);
                 // Write some debug info
                Serial.print("Incoming change for sensor:");
                Serial.print(message.sensor);
                Serial.print(", New status: ");
                Serial.println(state);
                //Handle LED's on change
                ledControl(message.sensor);
              } 
           }
    
    
    
    
    void updateDisplay(){
    
     // Print date and time 
     lcd.home();
    //  lcd.print(" ");
    //  lcd.print(tmYearToCalendar(tm.Year)-2000);
    
     lcd.print("gammel ");
    
     // Go to next line and print temperature
     lcd.setCursor ( 0, 1 );  
     lcd.print("tekst");
    //  lcd.print(RTC.temperature()/4);
    //  lcd.print("C");
    }
    
    
    void printDigits(int digits){
     if(digits < 10)
       lcd.print('0');
     lcd.print(digits);
    }
    
    

    I get the following error message:

    
    
    
    
    C:\Users\Owner\(...)\Oles_nye_display2.ino: In function 'void setup()':
    
    Oles_nye_display2:70: error: 'incomingMessage' was not declared in this scope
    
                gw.begin(incomingMessage, AUTO, false);
    
                         ^
    
    C:\Users\Owner\(...)\Oles_nye_display2.ino: At global scope:
    
    Oles_nye_display2:95: error: expected declaration before '}' token
    
    }
    
    ^
    
    exit status 1
    'incomingMessage' was not declared in this scope
    

    I am new to c++ and sketches, is there a simple fix to this problem?

    Using Win7, Arduino 1.6.7

    Right now it is a proof of concpt.. My end goal is to have my display change based on change of "fake" relays... So if the gateway tells me to turn on child1, my display writes "Window open"

    Thanks.


  • Contest Winner

    @Ole-Theill-Sørensen on commenting out function void receiveTime(
    you missed one } character at the end i think you have to add // in front of that line as well



  • Thank you, that was it...

    There are other issues with the code I see now.. But I will persue them tonight..

    Thanks


Log in to reply
 

Suggested Topics

  • 3
  • 1
  • 24
  • 2
  • 2
  • 3

21
Online

11.2k
Users

11.1k
Topics

112.5k
Posts