Moisture Sensor - Payload problem



  • Hi everyone,

    i want to use a Moisture-Sensor (YL69+YL39) to report the humidity-level (0-1023) to my serial-Gateway.
    All set-up well.
    My Serial-Gateway works fine, the Sensor-Node works also and is connected to the Gateway.
    Now, my problem is that the Sensor-Node doesn´t send the level data correctly, i think.

    The Sensor-Node should send the following Level:
    Humidity Level (0-1023): 19

    In the Serial Monitor from my Sensor-Node i always get this output, when a msg will be send:

    req id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    

    And this is the Gateway Serial Monitor:

    0;0;3;0;9;read: 255-255-0 s=255,c=3,t=3,pt=0,l=0,sg=0:
    255;255;3;0;3;
    

    So to me, it looks like the msg has no content!?
    pl=0 and l=0 -> no data in the msg, doesn´t it?

    Here is my Sensor-Node Sketch:

    // MySensor Library hinzufügen
    #include <SPI.h>
    #include <MySensor.h> 
    
    #define CHILD_ID 0   // Id of the sensor child
    
    MySensor gw;
    
    //Definieren welche Sensor-ID die nachricht schickt 
    //und welcher Variablen-Typ übermittelt wird. (V_LEVEL ist in S_MOISTURE möglich)
    // Entsprechend der Sensor-Liste und Variablen-Liste
    MyMessage msg(CHILD_ID, V_LEVEL);
    int lastSoilValue = 0;
    
    // YL-39 + YL-69 humidity sensor
    byte humidity_sensor_pin = A1;
    byte humidity_sensor_vcc = 6;
    
    void setup() {
    
      // Start Gateway Kommunikation
      gw.begin();
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Soil Moisture Sensor", "1.0");     
      // Register all sensors to gw (they will be created as child devices)  
      gw.present(CHILD_ID, S_MOISTURE);
      
      // Init the humidity sensor board
      pinMode(humidity_sensor_vcc, OUTPUT);
      digitalWrite(humidity_sensor_vcc, LOW);
    
      // Setup Serial
    //while (!Serial);
    //delay(1000);
    //Serial.begin(9600);
    }
    
    int read_humidity_sensor() {
      digitalWrite(humidity_sensor_vcc, HIGH);
      delay(500);
      int value = analogRead(humidity_sensor_pin);
      digitalWrite(humidity_sensor_vcc, LOW);
      return 1023 - value;
    }
    
    void loop() {
      int soilValue = read_humidity_sensor();
      Serial.print("Humidity Level (0-1023): ");
      Serial.println(soilValue);
      delay(2000);
      if (soilValue != lastSoilValue) {
        Serial.println(soilValue);
        gw.send(msg.set(soilValue));  
        lastSoilValue = soilValue;
      }
    }
    

    So, can someone help my, finding the problem, why my Level-Value will not be transmitted?
    Thanks for help!


  • Hero Member

    @vga It looks like your sensor is requesting an ID from the controller. As long as the ID is not received no message with content will be sent. Which controller are using? You can use a fixed node to test.



  • i´m a totally beginner with MySensors, so sorry for my questions:

    I have a FHEM-Controller working.
    But haven´t connected the Controller to the Gateway yet.
    I thought i can test the Communication between the Gateway and the Sensor-Node, without connect the Gateway to my Controller. Isn´t that possible?

    What do you mean with "fixed node"?


  • Hero Member

    @vga To indentify the node in the network a "Node Id" is needed. When you don't assign one yourself the sensor will ask the controller to issue one. As you have no controller connected it will never be issued and the node will keep asking. By assigning the node id yourself you will be able to use it without a controller attached. I modified your sketch to use a fixed node id (don't use 0 or 255)

    // MySensor Library hinzufügen
    #include <SPI.h>
    #include <MySensor.h> 
    
    #define CHILD_ID 0   // Id of the sensor child
    
    MySensor gw ;
    
    //Definieren welche Sensor-ID die nachricht schickt 
    //und welcher Variablen-Typ übermittelt wird. (V_LEVEL ist in S_MOISTURE möglich)
    // Entsprechend der Sensor-Liste und Variablen-Liste
    MyMessage msg(CHILD_ID, V_LEVEL);
    int lastSoilValue = 0;
    
    // YL-39 + YL-69 humidity sensor
    byte humidity_sensor_pin = A1;
    byte humidity_sensor_vcc = 6;
    
    void setup() {
    
      // Start Gateway Kommunikation
      gw.begin((NULL, 2);     // AWI: assign fixed node id 2  (use anything from 1..254);
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Soil Moisture Sensor", "1.0");     
      // Register all sensors to gw (they will be created as child devices)  
      gw.present(CHILD_ID, S_MOISTURE);
      
      // Init the humidity sensor board
      pinMode(humidity_sensor_vcc, OUTPUT);
      digitalWrite(humidity_sensor_vcc, LOW);
    
      // Setup Serial
    //while (!Serial);
    //delay(1000);
    //Serial.begin(9600);
    }
    
    int read_humidity_sensor() {
      digitalWrite(humidity_sensor_vcc, HIGH);
      delay(500);
      int value = analogRead(humidity_sensor_pin);
      digitalWrite(humidity_sensor_vcc, LOW);
      return 1023 - value;
    }
    
    void loop() {
      int soilValue = read_humidity_sensor();
      Serial.print("Humidity Level (0-1023): ");
      Serial.println(soilValue);
      delay(2000);
      if (soilValue != lastSoilValue) {
        Serial.println(soilValue);
        gw.send(msg.set(soilValue));  
        lastSoilValue = soilValue;
      }
    }


  • Thank you AWI,
    While compiling the modified sketch in Arduino App, i´m getting the following error:

    no matching function for call to 'MySensor::MySensor(NULL, int)'
    

  • Hero Member

    @vga oops, my mistake. I corrected the example 😊 (my excuse: I usually work in development branch). Let us know the results..



  • It is working! ;D ...thank you very much!
    Now i understand a little bit more with MySensors 😉


Log in to reply
 

Suggested Topics

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

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts