Can't get to call incomingMessageCallback function



  • I'm new to MySensors and I can't get it work right.
    I try to send some information (temperature, humidity) from one node (Arduino Nano) to another (Arduino Uno).
    First of all, no data is received by second node, if SerialGateway is on.
    But that's only a half of a problem.
    Even if I turn SerialGateway node off, data is sent and read between nodes, but I still can't get to call incomingMessageCallback function.

    1. Node which is supposed to receive data:
    #include <MySensor.h>
    #include <SPI.h>
    
    #define CAQ             10
    #define BARO_CHILD      3
    #define TEMP_CHILD      4
    #define CHILD_ID_HUM    1
    #define CHILD_ID_TEMP   2
    #define   CHILD_ID_MQ   0 
    
    float mq=0, pressure=0, baro_temp=0, hum=0, dht_temp=0;
    
    
    MySensor gw;
    
    void setup(){  
      gw.begin(incomingMessage, AUTO, false);
      gw.sendSketchInfo("Incoming Message Processor", "1.0");
      
      Serial.begin(115200);
    //  Serial.println("TempDHT \t Hum \t TempBaro \t Pressure \t AirQ");
    }
    
    void loop()  { 
         
      gw.process();
    //  Serial.print(dht_temp);
    //  Serial.print("\t");
    //  Serial.print(hum);
    //  Serial.print("\t");
    //  Serial.print(baro_temp);
    //  Serial.print("\t");
    //  Serial.print(pressure);
    //  Serial.print("\t");
    //  Serial.println(mq);
    
    }
    
    void incomingMessage(const MyMessage &message){
      Serial.println("Incoming Message function called");
      if (message.isAck()) {
        Serial.println("This is an ack from gateway");
      } else {
        switch (message.sender){
          case CAQ:{
            Serial.println("CAQ sender detected");
            switch(message.sensor){
              case CHILD_ID_MQ:
                mq=message.getFloat();
                break;
              case CHILD_ID_HUM:
                hum=message.getFloat();
                break;
              case CHILD_ID_TEMP:
                dht_temp=message.getFloat();
                break;
              case BARO_CHILD:
                pressure=message.getFloat();
                break;
              case TEMP_CHILD:
                baro_temp=message.getFloat();
                break;          
            }
          }
      
        }
      }
    }
    
    1. Node, which sends data:
    #include <SPI.h>
    #include <MySensor.h>  
    #include <DHT.h> 
    
    
    #define CHILD_ID_HUM 1
    #define CHILD_ID_TEMP 2
    
    
    //Pins
    #define HUMIDITY_SENSOR_DIGITAL_PIN 4
    
    //DHT-sensor variables:
    float lastTempDHT;
    float lastHum;
    boolean metric = true; 
    
    DHT dht;
    
    //My Sensors objects:
    MySensor gw;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    
    
    void setup()  
    { 
    
     gw.begin(NULL,10, true,AUTO);
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Simple Message Sender", "1.0");
    
      
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP, "Temperure DHT");
      
      metric = gw.getConfig().isMetric;
    
      
    }
    
    void loop()      
    { 
        delay(dht.getMinimumSamplingPeriod());
          
      float temperatureDHT = dht.getTemperature();
      if (isnan(temperatureDHT)) {
          Serial.println("Failed reading temperature from DHT");
      } else if (temperatureDHT != lastTempDHT) {
        lastTempDHT = temperatureDHT;
        if (!metric) {
          temperatureDHT = dht.toFahrenheit(temperatureDHT);
        }
        gw.send(msgTemp.set(temperatureDHT, 1));
        Serial.print("T: ");
        Serial.println(temperatureDHT);
      }
    
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          gw.send(msgHum.set(humidity, 1));
          Serial.print("H: ");
          Serial.println(humidity);
      }
      
    
    }```
    
    

    Serial monitor of 2) node:
    *send: 10-10-15-0 s=255,c=0,t=18,pt=0,l=5,sg=0,st=ok:1.5.1
    send: 10-10-15-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:15
    repeater started, id=10, parent=15, distance=2
    send: 10-10-15-0 s=255,c=3,t=11,pt=0,l=21,sg=0,st=ok:Simple Message Sender
    send: 10-10-15-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
    send: 10-10-15-0 s=1,c=0,t=7,pt=0,l=0,sg=0,st=ok:
    send: 10-10-15-0 s=2,c=0,t=6,pt=0,l=13,sg=0,st=fail:Temperure DHT
    send: 10-10-15-0 s=2,c=1,t=0,pt=7,l=5,sg=0,st=fail:27.0
    T: 27.00
    send: 10-10-15-0 s=1,c=1,t=1,pt=7,l=5,sg=0,st=ok:28.0
    H: 28.00

    Serial monitor of 1) node:
    send: 15-15-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=fail:1.5.1
    send: 15-15-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:0
    sensor started, id=15, parent=0, distance=1
    send: 15-15-0-0 s=255,c=3,t=11,pt=0,l=25,sg=0,st=fail:Incoming Message Processo
    send: 15-15-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:1.0
    read: 10-10-0 s=1,c=1,t=1,pt=7,l=5,sg=0:28.0
    read: 10-10-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    read: 10-10-0 s=1,c=1,t=1,pt=7,l=5,sg=0:27.0
    read: 10-10-0 s=2,c=1,t=0,pt=7,l=5,sg=0:28.0
    read: 10-10-0 s=1,c=1,t=1,pt=7,l=5,sg=0:28.0
    read: 10-10-0 s=2,c=1,t=0,pt=7,l=5,sg=0:27.0
    read: 10-10-0 s=1,c=1,t=1,pt=7,l=5,sg=0:17.0


  • Admin

    You haven't set destination of message to the nodeId of your repeater.

    msgTemp.setDestination(xxx);



  • Thank you!


Log in to reply
 

Suggested Topics

29
Online

11.2k
Users

11.1k
Topics

112.5k
Posts