Mysensors ESP8266 GW with relay - Presentation relay not working why?

  • Dear all,

    I am trying to use the ESP8266 with a local attached relay , but it is not recognized by domoticz.
    Can someone help on that ?

    Here the information log and the ino code:


    2016-01-17 13:49:54.731 MySensors: connected to: 
    2016-01-17 13:49:54.731 MySensors: Gateway Ready... 
    2016-01-17 13:49:55.781 MySensors: Gateway Version: 1.6.0-beta 
    2016-01-17 13:49:55.781 MySensors: Gateway Version: 1.6.0-beta 


    connected with FCSSID, channel 1
    start call Setup
    Start wait
    End wait
    End call Setup
    start call presentation
    Start wait
    End wait
    End call presentation
    0;0;3;0;9;Init complete, id=0, parent=0, distance=0
    0;0;3;0;9;Client 0 connected
    0;0;3;0;9;Client 0: 0;0;3;0;2;
    0;0;3;0;9;Client 0: 0;0;3;0;2;Get Version
    0;0;3;0;9;Client 0: 0;0;3;0;18;PING
    0;0;3;0;9;Client 0: 0;0;3;0;18;PING
    0;0;3;0;9;Client 0: 0;0;3;0;18;PING
    0;0;3;0;9;Client 0: 0;0;3;0;18;PING
    0;0;3;0;9;Client 0: 0;0;3;0;18;PING

    INO code:

    #include <EEPROM.h>
    #include <SPI.h>
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    #define MY_DEBUG_VERBOSE
    // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
    #define MY_BAUD_RATE 9600
    // Enables and select radio type (if attached)
    // #define MY_RADIO_NRF24
    // #define MY_RADIO_RFM69
    // Gateway mode always enabled for ESP8266. But we add this anyway ;)
    #define MY_GATEWAY_ESP8266
    #define MY_ESP8266_SSID "FCSSID"
    #define MY_ESP8266_PASSWORD "jfsc20100930*"
    // Enable UDP communication
    //#define MY_USE_UDP
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    #define MY_IP_ADDRESS 192,168,1,111
    // If using static ip you need to define Gateway and Subnet address as well
    #define MY_IP_GATEWAY_ADDRESS 192,168,1,1
    #define MY_IP_SUBNET_ADDRESS 255,255,255,0
    // The port to keep open on node server mode 
    #define MY_PORT 5003      
    // How many clients should be able to connect to this gateway (default 1)
    // Controller ip address. Enables client mode (default is "server" mode). 
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. 
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
    // Flash leds on rx/tx/err
    // Set blinking period
    // Enable inclusion mode
    // Enable Inclusion mode button on gateway
    // Set inclusion mode duration (in seconds)
    // Digital pin used for inclusion mode button
    #define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
    #define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
    #define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
    #if defined(MY_USE_UDP)
      #include <WiFiUDP.h>
      #include <ESP8266WiFi.h>
    // Enable repeater functionality for this node
    #include <SPI.h>
    #include <MySensor.h>
    #define RELAY_1  4  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1 // Total number of attached relays
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    void setup()  
      Serial.println("start call Setup");
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);   
        // Set relay to last known state (using eeprom storage) 
        digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
        Serial.println("Start wait");  
        Serial.println("End wait");  
        Serial.println("End call Setup");
    void presentation()  
        Serial.println("start call presentation");
        Serial.println("Start wait");  
        Serial.println("End wait");  
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Relay2", "2.0");
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_LIGHT);
          Serial.println("End call presentation");
    void loop() 
          //Serial.println("start call loop");
    void receive(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_LIGHT) {
         // Change relay state
         digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
         // Store state in eeprom
         saveState(message.sensor, message.getBool());
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(", New status: ");

  • please indent your code with 4 spaces to keep it readable.
    And in the arduino gui press CTRL-T to tabify your code correctly 😉

  • yes ,i find this bug too.

  • Admin

    Hmm.. Looks like it could it be that the connection to controller hasn't been initialised when node/gw sends the presentations.

    Please create an issue on github and create a link to it here.

Log in to reply

Suggested Topics

  • 5
  • 1
  • 178
  • 44
  • 1
  • 11
  • 6